-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
66 lines (66 loc) · 1.25 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
PROGRAM -> STMTS
STMTS -> STMT STMTS
STMTS -> ''
STMT -> FUNC
STMT -> IF
STMT -> FOR
STMT -> WHILE
STMT -> RETURN ;
STMT -> ASSIGN ;
STMT -> DEFN ;
STMT -> FUNC_CALL ;
DEFN -> TYPE DEFN_LIST
DEFN_LIST -> ID_MAYBE_INIT , DEFN_LIST
DEFN_LIST -> ID_MAYBE_INIT
ID_MAYBE_INIT -> ID
ID_MAYBE_INIT -> ID = EXPR
FUNC -> TYPE ID ( ARGS ) { STMTS }
ARGS -> ARG , ARGS
ARGS -> ARG
ARG -> TYPE ID
ARG -> ''
IF -> if ( EXPR ) { STMTS } else { STMTS }
IF -> if ( EXPR ) { STMTS } else IF
IF -> if ( EXPR ) { STMTS }
FOR -> for ( DEFN ; EXPR ; ASSIGN ) { STMTS }
WHILE -> while ( EXPR ) { STMTS }
RETURN -> return EXPR
ASSIGN -> ID = EXPR
EXPR -> EXPR == TERM
EXPR -> EXPR != TERM
EXPR -> EXPR > TERM
EXPR -> EXPR < TERM
EXPR -> EXPR >= TERM
EXPR -> EXPR <= TERM
EXPR -> TERM
TERM -> TERM + TERM2
TERM -> TERM - TERM2
TERM -> TERM2
TERM2 -> TERM2 * TERM3
TERM2 -> TERM2 / TERM3
TERM2 -> TERM3
TERM3 -> ( EXPR )
TERM3 -> ID
TERM3 -> NUM
TERM3 -> STR
TERM3 -> FLT
TERM3 -> FUNC_CALL
FUNC_CALL -> ID ( FUNC_ARGS )
FUNC_ARGS -> FUNC_ARG , FUNC_ARGS
FUNC_ARGS -> FUNC_ARG
FUNC_ARG -> EXPR
FUNC_ARG -> ''
TYPE -> int
TYPE -> float
TYPE -> char
TYPE -> double
TYPE -> string
TYPE -> void
ID -> <id>
NUM -> <num>
NUM -> + <num>
NUM -> - <num>
STR -> <str>
FLT -> <flt>
FLT -> + <flt>
FLT -> - <flt>