-
Notifications
You must be signed in to change notification settings - Fork 0
/
EBNF.ebnf
165 lines (103 loc) · 5.5 KB
/
EBNF.ebnf
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
/* Program */
program ::= platform? library_list action_list agent_list behavior_list task_list main
platform ::= "platform" variable
library_list ::= library*
library ::= "import" variable
library_call ::= variable ( "." variable )* ( '(' actual_parameters ')' )?
/* Action */
action_list ::= action+
action ::= "Action" variable "(" formal_parameters? ")" action_compound
action_compound ::= "{" action_statement* "}"
action_statement ::= action_if_else
| action_return_statement
| library_call_statement
| assignment_statement
| put_statement
| get_statement
| empty_statement
action_if_else ::= "if" "(" expression ")" action_compound ( "else" action_compound )?
action_return_statement ::= "return" expression ";"
library_call_statement ::= library_call ";"
/* Agent */
agent_list ::= agent+
agent ::= "Agent" variable "{" ( variable ( "," variable )* )? ";" "}"
agent_call_statement ::= "Agent" variable integer ";"
/* Behavior */
behavior_list ::= behavior+
behavior ::= "Behavior" variable "(" formal_parameters? ")" "{" behavior_init_block behavior_goal_block behavior_routine_block "}"
behavior_init_block ::= "@init" behavior_compound
behavior_goal_block ::= "@goal" "{" ( behavior_statement* "$" expression )? "}"
behavior_routine_block ::= "@routine" behavior_compound ( "||" behavior_compound )*
behavior_compound ::= "{" behavior_statement* "}"
behavior_statement ::= behavior_if_else
| function_call_statement
| assignment_statement
| empty_statement
behavior_if_else ::= "if" "(" expression ")" behavior_compound ( "else" behavior_compound )?
function_call_statement ::= variable "(" actual_parameters? ")" ";"
/* Task */
task_list ::= task+
task ::= "Task" variable "(" formal_parameters_agent_range_list ( "," formal_parameters )? ")" "{" task_init_block task_goal_block task_routine_block "}"
task_init_block ::= "@init" task_compound
task_goal_block ::= "@goal" "{" ( task_statement* "$" expression )? "}"
task_routine_block ::= "@routine" task_compound ( "||" task_compound )*
task_compound ::= "{" task_statement* "}"
task_statement ::= task_order
| task_each
| task_if_else
| task_call_statement
| assignment_statement
| put_statement
| get_statement
| empty_statement
task_order ::= "order" actual_parameters_agent_range "{" function_call_statement* "}"
task_each ::= "each" actual_parameters_agent_range "{" function_call_statement* "}"
task_if_else ::= "if" "(" expression ")" task_compound ( "else" task_compound )?
task_call_statement ::= variable "(" actual_parameters_agent_range_list ( "," actual_parameters )? ")" ";"
main ::= "Main" "{" agent_call_statement+ task_call_statement "}"
/* Basic statement */
assignment_statement ::= variable "=" ( ( string ";" )
| function_call_statement
| ( expression ";" ) )
put_statement ::= "put" ( string | expression ) "to" ( knowledge | knowledge_queue ) ";"
get_statement ::= "get" variable "from" ( knowledge | knowledge_queue ) ";"
empty_statement ::= ";"
/* Parameter */
formal_parameters_agent_range_list ::= "{" formal_parameters_agent_range ( "," formal_parameters_agent_range )* "}"
actual_parameters_agent_range_list ::= "{" actual_parameters_agent_range ( "," actual_parameters_agent_range )* "}"
formal_parameters_agent_range ::= variable "[" variable "~" variable "]"
actual_parameters_agent_range ::= variable "[" additive_expression "~" additive_expression "]"
formal_parameters ::= variable ( "," variable )*
actual_parameters ::= additive_expression ( "," additive_expression )*
/* Expressions */
expression ::= logical_not_expression
logical_not_expression ::= "not"? logical_or_expression
logical_or_expression ::= logical_and_expression
| logical_and_expression "or" logical_or_expression
logical_and_expression ::= equality_expression
| equality_expression "and" logical_and_expression
equality_expression ::= relational_expression
| relational_expression "==" equality_expression
| relational_expression "!=" equality_expression
relational_expression ::= additive_expression
| additive_expression "<" relational_expression
| additive_expression "<=" relational_expression
| additive_expression ">" relational_expression
| additive_expression ">=" relational_expression
additive_expression ::= multiplicative_expression ( ( "+" | "-" ) multiplicative_expression )*
multiplicative_expression ::= primary_expression ( ( "*" | "/" | "%" ) primary_expression )*
primary_expression ::= ( ( "+" | "-" ) primary_expression )
| "(" additive_expression ")"
| library_call
| variable
| boolean
| integer
| float
variable ::= [a-zA-Z] ( [a-zA-Z0-9] | "_" )*
knowledge ::= variable
knowledge_queue ::= variable "[" "]"
boolean ::= "False" | "True"
integer ::= "0" | ( [1-9] [0-9]* )
float ::= integer "." integer
string ::= ( "'" | '"' ) ( #x0009 | #x000A | #x000D | [#x0020-#xFFFF] )* ( "'" | '"' )
comments ::= "/*" ( #x0009 | #x000A | #x000D | [#x0020-#xFFFF] )* "*\/"