forked from lascar-pacagi/MiniJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.txt
More file actions
39 lines (30 loc) · 1.33 KB
/
grammar.txt
File metadata and controls
39 lines (30 loc) · 1.33 KB
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
Program ::= MainClass ClassDeclaration* 'eof'
MainClass ::= 'class' Identifier '{' 'public' 'static' 'void' 'main' "(" 'String' '[' ']' Identifier ')' '{' Statement '}' '}'
ClassDeclaration ::= 'class' Identifier ( 'extends' Identifier )? '{' VarDeclaration* MethodDeclaration* '}'
VarDeclaration ::= Type Identifier ';'
MethodDeclaration ::= 'public' Type Identifier '(' ( Type Identifier ( ',' Type Identifier )* )? ')' '{' VarDeclaration* Statement* 'return' Expression ';' '}'
Type ::= 'int' '[' ']'
| 'boolean'
| 'int'
| Identifier
Statement ::= '{' Statement* '}'
| 'if' '(' Expression ')' Statement 'else' Statement
| 'while' '(' Expression ')' Statement
| 'System.out.println' '(' Expression ')' ';'
| Identifier '=' Expression ';'
| Identifier '[' Expression ']' '=' Expression ';'
Expression ::= Expression ( '&&' | '<' | '+' | '-' | '*' ) Expression
| Expression '[' Expression ']'
| Expression '.' 'length'
| Expression '.' Identifier '(' ( Expression ( ',' Expression )* )? ')'
| Integer
| 'true'
| 'false'
| Identifier
| 'this'
| 'new' 'int' '[' Expression ']'
| 'new' Identifier '(' ')'
| '!' Expression
| '(' Expression ')'
Integer ::= [0-9]+
Identifier ::= [a-zA-Z_][a-zA-Z0-9_]*