-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrammar_reference.txt
129 lines (94 loc) · 2.54 KB
/
grammar_reference.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
Pascal Grammar Reference
program ->
program id ( identifier_list );
declarations
subprogram_declarations
compound_statement
.
identifier_list ->
id
| identifier_list , id
declarations ->
declarations var identifier_list : type;
| e
type ->
standard_type
| array [num .. num] of standard_type
standard_type ->
integer
| real
subprogram_declarations ->
subprogram_declarations subprogram_declaration;
| e
subprogram_declaration ->
subprogram_head declarations compound_statement
subprogram_head ->
function id arugments : standard_type;
| procedure id arugments;
arugments ->
( parameter_list )
| e
compound_statement ->
begin
optional_statements
end
optional_statements ->
statement_list
| e
statement_list ->
statement
| statement_list; statement
statement ->
variable assignop expression
| procedure_statement
| compound_statement
| if expression then statement else statement
| while expression do statement
variable ->
id
| id [ expression ]
procedure_statement ->
id
| id ( expression_list )
expression_list ->
expression
| expression_list, 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
| id ( expression_list)
| num
| ( expression )
| not factor
sign ->
+ | -
1. Comments are surrounded by { and }. They may not contain a {.
Comments may appear after any token.
2. Blanks between tokens are optional, with the exception that keywords
must be surrounded by blanks, newlines, the beginning of the program,
or the final dot.
3. Token id for identifiers matches a letter followed by letters or digits:
letter -» [a-zA-z]
digit - [0-9]
id -* letter ( letter | digit )*
The implementer may wish to put a limit on identifier length.
4. Token num matches unsigned integers (see Example 3.5):
digits -* digit digit*
optional-fraction -* . digits | e
optional-exponent -» ( E ( + | - | e ) digits ) | e
num -* digits optional-fraction optional-exponentSI'C. A.5 SUGGESTED EXERCISES 749
5. Keywords are reserved and appear in boldface in the grammar.
6. The relation operators (relop's) are: =, <>, <, <=, > = , and >. Note that
<> denotes +.
7. The addop's are +, -, and or.
8. The mulop's are *, /, div, mod, and and.
9. The lexeme for token assignop is : =.