-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
56 lines (56 loc) · 3.37 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
prog -> classDeclWrapper funcDefWrapper main funcBody ;
classDeclWrapper -> EPSILON | classDecl classDeclWrapper
classDecl -> class id optionalIDExt { genericDeclWrapper } ;
funcDefWrapper -> EPSILON | funcDef funcDefWrapper
funcDef -> funcHead funcBody ;
funcBody -> { statementWrapper }
optionalIDExt -> EPSILON | : id idWrapper
idWrapper -> EPSILON | idEntity idWrapper
idEntity -> , id
genericDeclWrapper -> EPSILON | genericDecl genericDeclWrapper
genericDecl -> type id genericExtension ;
genericExtension -> arraySizeWrapper | ( fParams )
funcHead -> type optionalIDSR ( fParams )
optionalIDSR -> id optionalIDSRExt
optionalIDSRExt -> EPSILON | sr id
type -> integer | float | id
fParams -> EPSILON | type id arraySizeWrapper fParamsTailWrapper
fParamsTailWrapper -> EPSILON | fParamsTail fParamsTailWrapper
fParamsTail -> , type id arraySizeWrapper
aParams -> EPSILON | expr aParamsTailWrapper
aParamsTailWrapper -> EPSILON | aParamsTail aParamsTailWrapper
aParamsTail -> , expr
statementWrapper -> EPSILON | statement statementWrapper
assignStatAndVar -> integer id genericExtension optionalAssignOp | float id genericExtension optionalAssignOp | id statOrVarExt optionalAssignOp
optionalAssignOp -> assignOp expr ; | ;
statOrVarExt -> id genericExtension | indiceWrapper indiceExtInt | ( aParams ) optionalDotAndIdnest | EPSILON
optionalDotAndIdnest -> . variableIdnestWrapper | EPSILON
indiceExtInt -> EPSILON | . variableIdnestWrapper
statement -> assignStatAndVar | if ( expr ) then statBlock else statBlock ; | for ( type id assignOp expr ; relExpr ; assignStat ) statBlock ; | read ( variableIdnestWrapper ) ; | write ( expr ) ; | return ( expr ) ;
arraySizeWrapper -> EPSILON | arraySize arraySizeWrapper
arraySize -> [ intNum ]
assignStat -> variableIdnestWrapper assignOp expr
expr -> arithExpr exprExt
exprExt -> relOp arithExpr | EPSILON
statBlock -> EPSILON | { statementWrapper } | statement
relExpr -> arithExpr relOp arithExpr
arithExpr -> term arithExprPrime
arithExprPrime -> EPSILON | addOp term arithExprPrime
variableIdnestWrapper -> EPSILON | variableIdnest variableIdnestWrapper
variableIdnest -> id indiceWrapper
relOp -> eq | neq | lt | gt | leq | geq
addOp -> + | - | or
multOp -> * | / | and
assignOp -> =
term -> factor termPrime
termPrime -> EPSILON | multOp factor termPrime
variableAndfunctionCall -> id T3 T2
T2 -> indice indiceWrapper T3 | ( aParams ) T3 | variableAndfunctionCall | EPSILON
T3 -> EPSILON | .
sign -> + | -
factor -> variableAndfunctionCall | intNum | floatNum | ( arithExpr ) | not factor | sign factor
idnestWrapper -> EPSILON | idnest idnestWrapper
idnest -> id idnestExt
idnestExt -> indiceWrapper . | ( aParams ) .
indiceWrapper -> EPSILON | indice indiceWrapper
indice -> [ arithExpr ]