-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grammar.txt
31 lines (31 loc) · 1.49 KB
/
Grammar.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
<program> ::= <block>
<assignment> ::= <lvalue> := <expr> | local <id> := <expr>
<lvalue> ::= <id> | <arrayelem> | <field>
<arrayelem> ::= <id> [ <expr> ]
<field> ::= <id> . <string>
<expr> ::= <arithmexp> | <funccall> | <read> | <array> | <methodcall> | <object> | <funcvalue>
<methodcall> ::= <field> (<farglist>)
<value> ::= <number> | <id> | <arrayelem> | <field>
<number> ::= 1<number> | 2<number> | 3<number> ... | 9<number> | e
<block> ::= begin <operatorlist> end
<operatorlist> ::= <operator><operatorlist> | <operator>;
<operator> ::= <block> | <assignment>; | <whilecycle> | <ifstatement> | <funccall>; | <print>; | <funcdef> | <return>
| <include> | <load>
<whilecycle> ::= while <condition> do <operator>
<ifstatement> ::= if <condition> then <operator> else <operator> | if <condition> then <operator>
<condition> ::= <logicalexp> | <logicalexp> and <condition> | <logicalexp> or <condition> | not <logicalexp>
<logicalexp> ::= <value><cmp><value> | <value>
<cmp> ::= < | = | > | <= | >=
<arithmexp> ::= <term> | <term> + <arithmexp> | <term> - <arithmexp>
<term> ::= <value> | <value> * <term> | <value> / <term>
<funccall> ::= <id> (<farglist>)
<farglist> ::= <value> , <farglist> | <value> | e
<print> ::= print <expr>
<read> ::= read | intread
<funcdef> ::= function <id> (<farglist>) <block>
<return> ::= return <expr>
<array> ::= array [ <number> ]
<object> ::= object | new <funcall>
<funcvalue> ::= function (<farglist>) <block>
<include> ::= include <constant>
<load> ::= load <costant>