-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
55 lines (35 loc) · 1.53 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
S -> Define S | Assign S | If S | Loop S | Define | Assign | If | Loop
Define -> "int" Variables ";" |
"int" Variables "=" Values ";"
Variables -> Id "," Variables | Id
AssignOp -> "+=" | "-=" | "*=" | "/=" | "%=" | "="
Values -> Expr "," Values | Expr
Expr -> Expr "+" Term |
Expr "-" Term | Term
Term -> Term "*" Power |
Term "%" Power |
Term "/" Power | Power
Power -> Power "^" Factor | Factor
Factor -> Id | Number | "(" Expr ")"
Assign -> Variables AssignOp Values ";"
If -> "if" Condition ":" "begin" Statement "end" Elif Else |
"if" Condition ":" "begin" Statement "end" Else |
"if" Condition ":" "begin" Statement "end" Elif |
"if" Condition ":" "begin" Statement "end" |
"if" Condition ":" "begin" "end" Elif Else |
"if" Condition ":" "begin" "end" Else |
"if" Condition ":" "begin" "end" Elif |
"if" Condition ":" "begin" "end"
Elif -> "elif" Condition ":" "begin" Statement "end" Elif |
"elif" Condition ":" "begin" Statement "end" |
"elif" Condition ":" "begin" "end" Elif |
"elif" Condition ":" "begin" "end"
Else -> "else" ":" "begin" Statement "end" |
"else" ":" "begin" "end"
Statement -> Assign Statement | If Statement | Loop Statement | Assign | If | Loop
Condition -> Condition "and" SubCondition |
Condition "or" SubCondition | SubCondition
SubCondition -> "True" | "False" | Expr | Expr Relational Expr |
"(" Condition ")"
Relational -> ">" | "<" | ">=" | "<=" | "==" | "!="
Loop -> "loopc " Condition ":" "begin" Statement "end"