-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpdf_example
62 lines (56 loc) · 1.86 KB
/
pdf_example
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
Lexical Rules
=============
letter = a-z | A-Z
digit = 0 - 9
id: letter (letter|digit)*
digits = digit+
{boolean int float}
num: digit+ | digit+ . digits ( \L | E digits)
relop: \=\= | !\= | > | >\= | < | <\=
assign: =
{ if else while }
[ , ; \( \) { }]
addop: \+ | -
mulop: \* | /
Grammar
=======
# METHOD_BODY = STATEMENT_LIST
# STATEMENT_LIST = STATEMENT | STATEMENT_LIST STATEMENT
# STATEMENT = DECLARATION | IF | WHILE | ASSIGNMENT
# DECLARATION = PRIMITIVE_TYPE 'id' ';'
# PRIMITIVE_TYPE = 'int' | 'float'
# IF = 'if' '(' EXPRESSION ')' '{' STATEMENT '}'
# WHILE = 'while' '(' EXPRESSION ')' '{' STATEMENT '}'
# ASSIGNMENT = 'id' '=' EXPRESSION ';'
# EXPRESSION = SIMPLE_EXPRESSION | SIMPLE_EXPRESSION 'relop' SIMPLE_EXPRESSION
# SIMPLE_EXPRESSION = TERM | SIGN TERM | SIMPLE_EXPRESSION 'addop' TERM
# TERM = FACTOR | TERM 'mulop' FACTOR
# FACTOR = 'id' | 'num' | '(' EXPRESSION ')'
# SIGN = '+' | '-'
Modified Grammar
================
# METHOD_BODY = STATEMENT_LIST
# STATEMENT_LIST = STATEMENT STATEMENT_LIST_LRdash
# STATEMENT_LIST_LRdash = STATEMENT STATEMENT_LIST_LRdash | '\L'
# STATEMENT = DECLARATION | IF | WHILE | ASSIGNMENT
# DECLARATION = PRIMITIVE_TYPE 'id' ';'
# PRIMITIVE_TYPE = 'int' | 'float'
# IF = 'if' '(' EXPRESSION ')' '{' STATEMENT '}'
# WHILE = 'while' '(' EXPRESSION ')' '{' STATEMENT '}'
# ASSIGNMENT = 'id' '=' EXPRESSION ';'
# EXPRESSION = SIMPLE_EXPRESSION EXPRESSION_LFdash
# EXPRESSION_LFdash = 'relop' SIMPLE_EXPRESSION | '\L'
# SIMPLE_EXPRESSION = TERM SIMPLE_EXPRESSION_LRdash | SIGN TERM SIMPLE_EXPRESSION_LRdash
# SIMPLE_EXPRESSION_LRdash = 'addop' TERM SIMPLE_EXPRESSION_LRdash | '\L'
# TERM = FACTOR TERM_LRdash
# TERM_LRdash = 'mulop' FACTOR TERM_LRdash | '\L'
# FACTOR = 'id' | 'num' | '(' EXPRESSION ')'
# SIGN = '+' | '-'
Program
=======
int x;
x = 5;
if (x > 2)
{
x = 0;
}