-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.txt
96 lines (71 loc) · 1.86 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
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
Program : DeclList
DeclList : DeclList Decl
| Decl
Decl : VariableDecl
| FunctionDecl
| ClassDecl
| InterfaceDecl
VariableDecl : Variable ';'
Variable : Type ident
Type : int
| 'double'
| 'bool'
| 'string'
| 'void'
| ident
| Type[]
InterfaceDecl : 'interface' ident '{' PrototypeList '}'
PrototypeList : Prototype PrototypeList
| EPSILON
Prototype : Type ident ( ParamsList ) ; | EPSILON
ParamsList : Param AParam
| EPSILON
AParam : ',' Param AParam
| EPSILON
FunctionDec l : Type ident ( ParamsList ) StmtBlock
StmtBlock : '{' VariableDeclList StmtList '}'
VariableDeclList : VariableDecl VariableDeclList
| EPSILON
StmtList : Stmt StmtList
| EPSLION
Stmt : <Expr>;
| IfStmt | WhileStmt | ForStmt | BreakStmt | ReturnStmt | PrintStmt | StmtBlock
ClassDecl ::= class ident <extends ident> <implements ident+ ,> { Field∗ }
Field ::= VariableDecl | FunctionDecl
IfStmt ::= if ( Expr ) Stmt <else Stmt>
WhileStmt while ( Expr ) Stmt
ForStmt ::= for ( <Expr>; Expr ; <Expr>) Stmt
ReturnStmt : 'return' Expr ';'
| 'return' ';'
BreakStmt ::= break ;
PrintStmt ::= Print ( Expr+ , ) ;
Expr ::= LValue = Expr
| Constant
| LValue
| this
| Call
| ( Expr )
| Expr + Expr
| Expr - Expr
| Expr * Expr
| Expr / Expr
| Expr % Expr
| - Expr
| Expr < Expr
| Expr <= Expr
| Expr > Expr
| Expr >= Expr
| Expr == Expr
| Expr != Expr
| Expr && Expr
| Expr || Expr
| ! Expr
| ReadInteger ( ) | ReadLine ( ) | New ( ident ) | NewArray ( Expr , Type )
LValue ::= ident | Expr . ident | Expr [ Expr ]
Call ::= ident ( Actuals ) | Expr . ident ( Actuals )
Actuals ::= Expr+ , |
Constant : intConstant
| doubleConstant
| boolConstant
| stringConstant
| null