-
Notifications
You must be signed in to change notification settings - Fork 1
/
grammar.txt
82 lines (59 loc) · 1.94 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
<Program> -> <FunctionList>
<FunctionList> -> <Function> | <Function> <FunctionList>
<Function> -> <Type> IDENTIFIER LPAREN <ArgList> RPAREN
LBRACE
<Body>
RBRACE
<ArgList> -> e | <Args>
<Args> -> <Type> IDENTIFIER | <Type> IDENTIFIER COMMA <ArgList>
<Type> -> INT | CHAR | STRING
IDENTIFIER -> [a-zA-Z]+
<Body> -> <StmtList>
<StmtList> -> e | <Stmt> <StmtList>
<Stmt> -> <AssignStmt> | <IfElse> | <ForLoop> | <ReturnStmt>
<ReturnStmt> -> RETURN (<Expr> | e) SEMICOLON
<AssignStmt> -> [<Type>] (IDENTIFIER | <ArrIdent>) ASSIGN <Expr> SEMICOLON
<Expr> -> <Term> [(PLUS | MINUS) <Expr>]
<Term> -> <Factor> [( STAR | SLASH ) <Term>]
<Factor> -> LPAREN <Expr> RPAREN | <FunctionCall> | IDENTIFIER | INTEGER | STRINGLIT | <ArrIdent>
<ArrIdent> -> IDENTIFIER LBRACKET <Expr> RBRACKET
<FunctionCall> -> IDENTIFIER LPAREN <ParameterList> RPAREN
<ParameterList> -> e | <Params>
<Params> -> IDENTIFIER | IDENTIFIER COMMA <ParameterList>
<CompExpr> -> <Expr> [COMP_OP <Expr>]
<IfElse> -> IF LPAREN <CompExpr> RPAREN
LBRACE
<Body>
RBRACE
ELSE
LBRACE
<Body>
RBRACE
<ForLoop> -> FOR LPAREN <AssignStmt> <CompExpr> SEMICOLON <AssignStmt>
LBRACE
<Body>
RBRACE
INTEGER -> [0-9]+
STRINGLIT -> [a-zA-Z]*
LPAREN -> (
RPAREN -> )
LBRACKET -> [
RBRACKET -> ]
LBRACE -> {
RBRACE -> }
INT -> int
CHAR -> char
STRING -> string
FOR -> for
IF -> if
ELSE -> else
SEMICOLON -> ;
COMMA -> ,
COMP_OP -> < | > | == | !=
ASSIGN -> =
PLUS -> +
MINUS -> -
STAR -> *
SLASH -> /
IDENTIFIER -> [a-zA-Z]+
RETURN -> return