-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.txt
175 lines (128 loc) · 3.73 KB
/
rules.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
Meaning W3C
0 or more occurrences of A (A)*
Optional A (A)?
script = (chunk)*
chunk = (procedure)*
Procedure = "procedure" ProcedureName "(" Variables ")" Block
ProcedureTrip = "cf_procedure" ProcedureName "(" Variables ")" Block
Variables = ValidName ("," ValidName)*
Literals = "0-9"("0-9")*
Identifier = ValidName ("." ValidName)* | Literals | ProcedureCall | Expression
Assignment = "ValidName" "=" Identifier
NewAssignment = "ValidName" ":" Type ("=" Identifier)?
ValidName = "a..z"("0-9")*("a-z")* ("[" Expression "]")? : Type
ProcedureName = "a..z"("0-9")*("a-z")*
Type = "String" | "Agents" | "Troop" | "Scene" | "GameMenu" | "Presentation" | "Party" | "Item" | "Integer" | "FixedPoint" | "Position" | "Faction"
Block = "{" (Statements)* "}"
ExpressionLoop = NewAssignment "to" Identifier | Expression
ExpressionForEach = NewAssignment "in" Type
Statements = ProcedureCall |
(Block)* |
NewAssignment |
Assignment |
"return" (Identifier)? |
"ExitProcedure" | <- procedure must be cf_
"for" ExpressionLoop Block |
"foreach" ExpressionForEach Block |
"if" Expression Block
("else if" Expression Block)*
("else" Block)?
ProcedureCall = ProcedureName "()" | ProcedureName "(" (Variables) ")"
===Example===
procedure diplomacy_start_war_between_kingdoms (kingdomA: Faction, kingdomB: Faction, initializing_war_peace_cond: Integer)
{
ProcedureCall(script_npc_decision_checklist_peace_or_war(kingdomA, kingdomB, -1))
explainer_string : String = reg1
if (initializing_war_peace_cond <= 2)
{
}
else
{
}
for(cur_relation : Faction = kingdomA to kingdomB)
{
if(cur_relation != kingdomA && cur_relation != kingdomB)
{
}
}
}
====UNIT test
#assignment
i : Integer = 0
#ifs
if(1 < 0)
{
}
else if (i != 0)
{
}
else
{
}
#loop
#for loop
for(i : Integer = 0 to 1 )
{
}
#while loop
for(i != 0)
{
}
#foreach
foreach(agent : Agent in game.Agents)
{
}
start: procedure+
procedure: "procedure" procedurename paramsdeclare codeblock -> procedure
codeblock : "{" "}"
| "{" instruction+ "}"
instruction: assignment | expression | variabledeclare | variable
variabledeclareassign : NAME ":" TYPE ("=" expression)
variabledeclare: NAME ":" TYPE
variable : array | NAME -> variable
?procedurename: NAME
paramsdeclare : "("")"
| "(" NAME ":" TYPE ")"
| "(" NAME ":" TYPE ("," NAME ":" TYPE)+ ")"
array: variable "[" mathexpression "]"
assignment: (variable "=" expression) -> assignment
| (variabledeclare "=" expression ) -> assignment
expression: mathexpression
| boolexpression
| procedureexprssion
?mathexpression: sum
?sum: product
| sum "+" product -> op_add
| sum "-" product -> op_sub
?product: atom
| product "*" atom -> op_mul
| product "/" atom -> op_div
?atom: NUMBER -> number
| "-" atom -> minus
| "(" sum ")"
?boolexpression: boolsum
?boolsum: boolproduct
| boolsum "<" boolproduct -> lt
| boolsum ">" boolproduct -> gt
| boolsum "==" boolproduct -> eq
| boolsum "=<" boolproduct -> le
| boolsum "=>" boolproduct -> ge
| boolsum "=!" boolproduct -> neq
| boolsum "||" boolproduct -> or
?boolproduct: boolatom
| boolproduct "&&" boolatom -> and
?boolatom: BOOL
| "!" boolatom
| "(" boolsum ")"
?procedureexprssion: variable params
?params: "("")"
| "(" variable ")"
| "(" variable ("," variable)+ ")"
| "(" expression ")"
| "(" expression ("," expression)+ ")"
NAME: /[A-Za-z][A-Za-z0-9_]*/
NUMBER: /\d+\.?\d*/
TYPE: "Number" | "String" | "QString" | "Procedure"
| "Faction" | "Presentation" | "Troop" | "Agent" | "Item"
BOOL: "true"
| "false"