-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_minus_grammar_EBNF.txt
84 lines (45 loc) · 2.41 KB
/
c_minus_grammar_EBNF.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
83
84
BNF Grammar for C-Minus
1. program → declaration-list
2. declaration-list → declaration declaration-list-recur | declaration
2. declaration-list-recur → declaration declaration-list-recur | declaration
3. declaration → var-declaration | fun-declaration
4. var-declaration → type-specifier ID ; | type-specifier ID [ NUM ] ;
5. type-specifier → int | void
6. fun-declaration → type-specifier ID ( params ) compound-stmt
7. params → param-list | void
8. param-list → param param-list-recur | param
8. param-list-recur → , param param-list-recur | , param
9. param → type-specifier ID | type-specifier ID [ ]
10. compound-stmt → { local-declarations statement-list } | { local-declarations } | { statement-list } | { }
11. local-declarations → var-declaration local-declarations-recur | var-declaration
11. local-declarations-recur → var-declaration local-declarations-recur | var-declaration
12. statement-list → statement statement-list-recur | statement
12. statement-list-recur → statement statement-list-recur | statement
13. statement → expression-stmt | compound-stmt | selection-stmt | iteration-stmt | return-stmt | read-stmt | write-stmt
14. expression-stmt → expression ; | ;
15. selection-stmt → if ( expression ) statement | if ( expression ) statement else statement
16. iteration-stmt → while ( expression ) statement
17. return-stmt → return ; | return expression ;
18. read-stmt → read ( var ) ;
18. write-stmt → write ( expression ) ;
18. expression → var = expression | simple-expression
19. var → ID | ID [ expression ]
20. simple-expression → additive-expression relop additive-expression | additive-expression
21. relop → <= | < | > | >= | == | !=
22. additive-expression → term additive-expression-recur | term
22. additive-expression-recur → addop term additive-expression-recur | addop term
23. addop → + | -
24. term → factor term-recur | factor
24. term-recur → mulop factor term-recur | mulop factor
25. mulop → * | /
26. factor → ( expression ) | var | call | NUM
27. call → ID ( args ) | ID ( )
28. args → arg-list
29. arg-list → expression arg-list-recur | expression
29. arg-list-recur → , expression arg-list-recur | , expression
Keywords: else if int return void while
Special symbols: + - * / < <= > >= == != = ; , ( ) [ ] { }
ID = letter letter*
NUM = digit digit*
letter = a | .. | z | A | .. | Z
digit = 0 | .. | 9