-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammars.txt
77 lines (77 loc) · 1.84 KB
/
grammars.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
program -> compUnit
compUnit -> decl compUnit
compUnit -> funcDef compUnit
compUnit -> $
decl -> constDecl
decl -> varDecl
constDecl -> const bType constDef argConst ;
argConst -> , constDef argConst
argConst -> $
constDef -> Ident = constInitVal
constInitVal -> constExp
varDecl -> bType varDef argVarDecl ;
argVarDecl -> , varDef argVarDecl
argVarDecl -> $
varDef -> Ident argVarDef
argVarDef -> = initVal
argVarDef -> $
initVal -> exp
bType -> int
funcDef -> funcType Ident ( funcFParams ) block
funcType -> void
funcFParams -> funcFParam argFunctionF
funcFParams -> $
argFunctionF -> , funcFParam argFunctionF
argFunctionF -> $
funcFParam -> bType Ident
block -> { blockItem }
blockItem -> decl blockItem
blockItem -> stmt blockItem
blockItem -> $
stmt -> exp ;
stmt -> ;
stmt -> block
stmt -> return argExp ;
argExp -> $
argExp -> exp
exp -> assignExp
lVal -> Ident
primaryExp -> ( exp )
primaryExp -> number
number -> INT
unaryOp -> +
unaryOp -> -
unaryOp -> !
unaryExp -> unaryOp unaryExp
unaryExp -> Ident callFunc
callFunc -> ( funcRParams )
callFunc -> $
unaryExp -> primaryExp
funcRParams -> funcRParam argFunctionR
funcRParams -> $
argFunctionR -> , funcRParam argFunctionR
argFunctionR -> $
funcRParam -> exp
mulExp -> unaryExp mulExpAtom
mulExpAtom -> * unaryExp mulExpAtom
mulExpAtom -> / unaryExp mulExpAtom
mulExpAtom -> % unaryExp mulExpAtom
mulExpAtom -> $
addExp -> mulExp addExpAtom
addExpAtom -> + mulExp addExpAtom
addExpAtom -> - mulExp addExpAtom
addExpAtom -> $
relExp -> addExp relExpAtom
relExpAtom -> < addExp relExpAtom
relExpAtom -> > addExp relExpAtom
relExpAtom -> <= addExp relExpAtom
relExpAtom -> >= addExp relExpAtom
relExpAtom -> $
eqExp -> relExp eqExpAtom
eqExpAtom -> == relExp eqExpAtom
eqExpAtom -> != relExp eqExpAtom
eqExpAtom -> $
assignExp -> eqExp assignExpAtom
assignExpAtom -> = eqExp assignExpAtom
assignExpAtom -> $
constExp -> assignExp