-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascalCsExp.par
More file actions
317 lines (315 loc) · 14.1 KB
/
PascalCsExp.par
File metadata and controls
317 lines (315 loc) · 14.1 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
%start PascalCs0
%title "ISO Pascal LALR(1) grammar"
%comment "Readable EBNF-style ISO 7185 grammar in parol format"
%grammar_type 'lalr(1)'
%block_comment "\(\*" "\*\)"
%block_comment "\{" "\}"
%%
/* 0 */ PascalCs0: PascalCs;
/* 1 */ PascalCs: Program;
/* 2 */ PascalCs: Module;
/* 3 */ Program: ProgramHeading SEMICOLON Block DOT;
/* 4 */ ProgramHeading: PROGRAM IDENTIFIER;
/* 5 */ ProgramHeading: PROGRAM IDENTIFIER LPAREN IdentifierList RPAREN;
/* 6 */ IdentifierList: IdentifierList COMMA IDENTIFIER;
/* 7 */ IdentifierList: IDENTIFIER;
/* 8 */ Block: LabelDeclarationPart ConstantDefinitionPart TypeDefinitionPart VariableDeclarationPart ProcedureAndFunctionDeclarationPart StatementPart;
/* 9 */ Module: ConstantDefinitionPart TypeDefinitionPart VariableDeclarationPart ProcedureAndFunctionDeclarationPart;
/* 10 */ LabelDeclarationPart: LABEL LabelList SEMICOLON;
/* 11 */ LabelDeclarationPart: ;
/* 12 */ LabelList: LabelList COMMA Label;
/* 13 */ LabelList: Label;
/* 14 */ Label: DIGSEQ;
/* 15 */ ConstantDefinitionPart: CONST ConstantList;
/* 16 */ ConstantDefinitionPart: ;
/* 17 */ ConstantList: ConstantList ConstantDefinition;
/* 18 */ ConstantList: ConstantDefinition;
/* 19 */ ConstantDefinition: IDENTIFIER EQUAL CExpression SEMICOLON;
/* 20 */ CExpression: CSimpleExpression;
/* 21 */ CExpression: CSimpleExpression RelOp CSimpleExpression;
/* 22 */ CSimpleExpression: CTerm;
/* 23 */ CSimpleExpression: CSimpleExpression AddOp CTerm;
/* 24 */ CTerm: CFactor;
/* 25 */ CTerm: CTerm MulOp CFactor;
/* 26 */ CFactor: Sign CFactor;
/* 27 */ CFactor: CExponentiation;
/* 28 */ CExponentiation: CPrimary;
/* 29 */ CExponentiation: CPrimary STARSTAR CExponentiation;
/* 30 */ CPrimary: IDENTIFIER;
/* 31 */ CPrimary: LPAREN CExpression RPAREN;
/* 32 */ CPrimary: UnsignedConstant;
/* 33 */ CPrimary: NOT CPrimary;
/* 34 */ Constant: NonString;
/* 35 */ Constant: Sign NonString;
/* 36 */ Constant: CHARACTER_STRING;
/* 37 */ Sign: PLUS;
/* 38 */ Sign: MINUS;
/* 39 */ NonString: DIGSEQ;
/* 40 */ NonString: IDENTIFIER;
/* 41 */ NonString: REALNUMBER;
/* 42 */ TypeDefinitionPart: TYPE TypeDefinitionList;
/* 43 */ TypeDefinitionPart: ;
/* 44 */ TypeDefinitionList: TypeDefinitionList TypeDefinition;
/* 45 */ TypeDefinitionList: TypeDefinition;
/* 46 */ TypeDefinition: IDENTIFIER EQUAL TypeDenoter SEMICOLON;
/* 47 */ TypeDenoter: IDENTIFIER;
/* 48 */ TypeDenoter: NewType;
/* 49 */ NewType: NewOrdinalType;
/* 50 */ NewType: NewStructuredType;
/* 51 */ NewType: NewPointerType;
/* 52 */ NewOrdinalType: EnumeratedType;
/* 53 */ NewOrdinalType: SubrangeType;
/* 54 */ EnumeratedType: LPAREN IdentifierList RPAREN;
/* 55 */ SubrangeType: Constant DOTDOT Constant;
/* 56 */ NewStructuredType: StructuredType;
/* 57 */ NewStructuredType: PACKED StructuredType;
/* 58 */ StructuredType: ArrayType;
/* 59 */ StructuredType: RecordType;
/* 60 */ StructuredType: SetType;
/* 61 */ StructuredType: FileType;
/* 62 */ ArrayType: ARRAY LBRAC IndexList RBRAC OF ComponentType;
/* 63 */ IndexList: IndexList COMMA IndexType;
/* 64 */ IndexList: IndexType;
/* 65 */ IndexType: OrdinalType;
/* 66 */ OrdinalType: NewOrdinalType;
/* 67 */ OrdinalType: IDENTIFIER;
/* 68 */ ComponentType: TypeDenoter;
/* 69 */ RecordType: RECORD RecordSectionList END;
/* 70 */ RecordType: RECORD RecordSectionList SEMICOLON VariantPart END;
/* 71 */ RecordType: RECORD VariantPart END;
/* 72 */ RecordSectionList: RecordSectionList SEMICOLON RecordSection;
/* 73 */ RecordSectionList: RecordSection;
/* 74 */ RecordSection: IdentifierList COLON TypeDenoter;
/* 75 */ VariantPart: CASE VariantSelector OF VariantList SEMICOLON;
/* 76 */ VariantPart: CASE VariantSelector OF VariantList;
/* 77 */ VariantPart: ;
/* 78 */ VariantSelector: TagField COLON TagType;
/* 79 */ VariantSelector: TagType;
/* 80 */ VariantList: VariantList SEMICOLON Variant;
/* 81 */ VariantList: Variant;
/* 82 */ Variant: CaseConstantList COLON LPAREN RecordSectionList RPAREN;
/* 83 */ Variant: CaseConstantList COLON LPAREN RecordSectionList SEMICOLON VariantPart RPAREN;
/* 84 */ Variant: CaseConstantList COLON LPAREN VariantPart RPAREN;
/* 85 */ CaseConstantList: CaseConstantList COMMA CaseConstant;
/* 86 */ CaseConstantList: CaseConstant;
/* 87 */ CaseConstant: Constant;
/* 88 */ CaseConstant: Constant DOTDOT Constant;
/* 89 */ TagField: IDENTIFIER;
/* 90 */ TagType: IDENTIFIER;
/* 91 */ SetType: SET OF OrdinalType;
/* 92 */ FileType: PFILE OF ComponentType;
/* 93 */ NewPointerType: UPARROW DomainType;
/* 94 */ DomainType: IDENTIFIER;
/* 95 */ VariableDeclarationPart: VAR VariableDeclarationList SEMICOLON;
/* 96 */ VariableDeclarationPart: ;
/* 97 */ VariableDeclarationList: VariableDeclarationList SEMICOLON VariableDeclaration;
/* 98 */ VariableDeclarationList: VariableDeclaration;
/* 99 */ VariableDeclaration: IdentifierList COLON TypeDenoter;
/* 100 */ ProcedureAndFunctionDeclarationPart: ProcOrFuncDeclarationList SEMICOLON;
/* 101 */ ProcedureAndFunctionDeclarationPart: ;
/* 102 */ ProcOrFuncDeclarationList: ProcOrFuncDeclarationList SEMICOLON ProcOrFuncDeclaration;
/* 103 */ ProcOrFuncDeclarationList: ProcOrFuncDeclaration;
/* 104 */ ProcOrFuncDeclaration: ProcedureDeclaration;
/* 105 */ ProcOrFuncDeclaration: FunctionDeclaration;
/* 106 */ ProcedureDeclaration: ProcedureHeading SEMICOLON Directive;
/* 107 */ ProcedureDeclaration: ProcedureHeading SEMICOLON ProcedureBlock;
/* 108 */ ProcedureHeading: ProcedureIdentification;
/* 109 */ ProcedureHeading: ProcedureIdentification FormalParameterList;
/* 110 */ Directive: FORWARD;
/* 111 */ Directive: EXTERNAL;
/* 112 */ FormalParameterList: LPAREN FormalParameterSectionList RPAREN;
/* 113 */ FormalParameterSectionList: FormalParameterSectionList SEMICOLON FormalParameterSection;
/* 114 */ FormalParameterSectionList: FormalParameterSection;
/* 115 */ FormalParameterSection: ValueParameterSpecification;
/* 116 */ FormalParameterSection: VariableParameterSpecification;
/* 117 */ FormalParameterSection: ProceduralParameterSpecification;
/* 118 */ FormalParameterSection: FunctionalParameterSpecification;
/* 119 */ ValueParameterSpecification: IdentifierList COLON IDENTIFIER;
/* 120 */ VariableParameterSpecification: VAR IdentifierList COLON IDENTIFIER;
/* 121 */ ProceduralParameterSpecification: ProcedureHeading;
/* 122 */ FunctionalParameterSpecification: FunctionHeading;
/* 123 */ ProcedureIdentification: PROCEDURE IDENTIFIER;
/* 124 */ ProcedureBlock: Block;
/* 125 */ FunctionDeclaration: FunctionHeading SEMICOLON Directive;
/* 126 */ FunctionDeclaration: FunctionIdentification SEMICOLON FunctionBlock;
/* 127 */ FunctionDeclaration: FunctionHeading SEMICOLON FunctionBlock;
/* 128 */ FunctionHeading: FUNCTION IDENTIFIER COLON ResultType;
/* 129 */ FunctionHeading: FUNCTION IDENTIFIER FormalParameterList COLON ResultType;
/* 130 */ ResultType: IDENTIFIER;
/* 131 */ FunctionIdentification: FUNCTION IDENTIFIER;
/* 132 */ FunctionBlock: Block;
/* 133 */ StatementPart: CompoundStatement;
/* 134 */ CompoundStatement: PBEGIN StatementSequence END;
/* 135 */ StatementSequence: StatementSequence SEMICOLON Statement;
/* 136 */ StatementSequence: Statement;
/* 137 */ Statement: OpenStatement;
/* 138 */ Statement: ClosedStatement;
/* 139 */ OpenStatement: Label COLON NonLabeledOpenStatement;
/* 140 */ OpenStatement: NonLabeledOpenStatement;
/* 141 */ ClosedStatement: Label COLON NonLabeledClosedStatement;
/* 142 */ ClosedStatement: NonLabeledClosedStatement;
/* 143 */ NonLabeledClosedStatement: AssignmentStatement;
/* 144 */ NonLabeledClosedStatement: ProcedureStatement;
/* 145 */ NonLabeledClosedStatement: GotoStatement;
/* 146 */ NonLabeledClosedStatement: CompoundStatement;
/* 147 */ NonLabeledClosedStatement: CaseStatement;
/* 148 */ NonLabeledClosedStatement: RepeatStatement;
/* 149 */ NonLabeledClosedStatement: ClosedWithStatement;
/* 150 */ NonLabeledClosedStatement: ClosedIfStatement;
/* 151 */ NonLabeledClosedStatement: ClosedWhileStatement;
/* 152 */ NonLabeledClosedStatement: ClosedForStatement;
/* 153 */ NonLabeledClosedStatement: ;
/* 154 */ NonLabeledOpenStatement: OpenWithStatement;
/* 155 */ NonLabeledOpenStatement: OpenIfStatement;
/* 156 */ NonLabeledOpenStatement: OpenWhileStatement;
/* 157 */ NonLabeledOpenStatement: OpenForStatement;
/* 158 */ RepeatStatement: REPEAT StatementSequence UNTIL Expression;
/* 159 */ OpenWhileStatement: WHILE Expression DO OpenStatement;
/* 160 */ ClosedWhileStatement: WHILE Expression DO ClosedStatement;
/* 161 */ OpenForStatement: FOR IDENTIFIER ASSIGNMENT Expression Direction FinalValue DO OpenStatement;
/* 162 */ ClosedForStatement: FOR IDENTIFIER ASSIGNMENT Expression Direction FinalValue DO ClosedStatement;
/* 163 */ OpenWithStatement: WITH RecordVariableList DO OpenStatement;
/* 164 */ ClosedWithStatement: WITH RecordVariableList DO ClosedStatement;
/* 165 */ OpenIfStatement: IF Expression THEN Statement;
/* 166 */ OpenIfStatement: IF Expression THEN ClosedStatement ELSE OpenStatement;
/* 167 */ ClosedIfStatement: IF Expression THEN ClosedStatement ELSE ClosedStatement;
/* 168 */ AssignmentStatement: VariableAccess ASSIGNMENT Expression;
/* 169 */ VariableAccess: IDENTIFIER;
/* 170 */ VariableAccess: IndexedVariable;
/* 171 */ VariableAccess: FieldDesignator;
/* 172 */ VariableAccess: VariableAccess UPARROW;
/* 173 */ IndexedVariable: VariableAccess LBRAC IndexExpressionList RBRAC;
/* 174 */ IndexExpressionList: IndexExpressionList COMMA IndexExpression;
/* 175 */ IndexExpressionList: IndexExpression;
/* 176 */ IndexExpression: Expression;
/* 177 */ FieldDesignator: VariableAccess DOT IDENTIFIER;
/* 178 */ ProcedureStatement: IDENTIFIER Params;
/* 179 */ ProcedureStatement: IDENTIFIER;
/* 180 */ Params: LPAREN ActualParameterList RPAREN;
/* 181 */ ActualParameterList: ActualParameterList COMMA ActualParameter;
/* 182 */ ActualParameterList: ActualParameter;
/* 183 */ ActualParameter: Expression;
/* 184 */ ActualParameter: Expression COLON Expression;
/* 185 */ ActualParameter: Expression COLON Expression COLON Expression;
/* 186 */ GotoStatement: GOTO Label;
/* 187 */ CaseStatement: CASE Expression OF CaseListElementList END;
/* 188 */ CaseStatement: CASE Expression OF CaseListElementList SEMICOLON END;
/* 189 */ CaseStatement: CASE Expression OF CaseListElementList SEMICOLON OtherwisePart Statement END;
/* 190 */ CaseStatement: CASE Expression OF CaseListElementList SEMICOLON OtherwisePart Statement SEMICOLON END;
/* 191 */ CaseListElementList: CaseListElementList SEMICOLON CaseListElement;
/* 192 */ CaseListElementList: CaseListElement;
/* 193 */ CaseListElement: CaseConstantList COLON Statement;
/* 194 */ OtherwisePart: OTHERWISE;
/* 195 */ OtherwisePart: OTHERWISE COLON;
/* 196 */ Direction: TO;
/* 197 */ Direction: DOWNTO;
/* 198 */ FinalValue: Expression;
/* 199 */ RecordVariableList: RecordVariableList COMMA VariableAccess;
/* 200 */ RecordVariableList: VariableAccess;
/* 201 */ Expression: SimpleExpression;
/* 202 */ Expression: SimpleExpression RelOp SimpleExpression;
/* 203 */ SimpleExpression: Term;
/* 204 */ SimpleExpression: SimpleExpression AddOp Term;
/* 205 */ Term: Factor;
/* 206 */ Term: Term MulOp Factor;
/* 207 */ Factor: Sign Factor;
/* 208 */ Factor: Exponentiation;
/* 209 */ Exponentiation: Primary;
/* 210 */ Exponentiation: Primary STARSTAR Exponentiation;
/* 211 */ Primary: VariableAccess;
/* 212 */ Primary: UnsignedConstant;
/* 213 */ Primary: FunctionDesignator;
/* 214 */ Primary: SetConstructor;
/* 215 */ Primary: LPAREN Expression RPAREN;
/* 216 */ Primary: NOT Primary;
/* 217 */ UnsignedConstant: UnsignedNumber;
/* 218 */ UnsignedConstant: CHARACTER_STRING;
/* 219 */ UnsignedConstant: NIL;
/* 220 */ UnsignedNumber: DIGSEQ;
/* 221 */ UnsignedNumber: REALNUMBER;
/* 222 */ FunctionDesignator: IDENTIFIER Params;
/* 223 */ SetConstructor: LBRAC MemberDesignatorList RBRAC;
/* 224 */ SetConstructor: LBRAC RBRAC;
/* 225 */ MemberDesignatorList: MemberDesignatorList COMMA MemberDesignator;
/* 226 */ MemberDesignatorList: MemberDesignator;
/* 227 */ MemberDesignator: MemberDesignator DOTDOT Expression;
/* 228 */ MemberDesignator: Expression;
/* 229 */ AddOp: PLUS;
/* 230 */ AddOp: MINUS;
/* 231 */ AddOp: OR;
/* 232 */ MulOp: STAR;
/* 233 */ MulOp: SLASH;
/* 234 */ MulOp: DIV;
/* 235 */ MulOp: MOD;
/* 236 */ MulOp: AND;
/* 237 */ RelOp: EQUAL;
/* 238 */ RelOp: NOTEQUAL;
/* 239 */ RelOp: LT;
/* 240 */ RelOp: GT;
/* 241 */ RelOp: LE;
/* 242 */ RelOp: GE;
/* 243 */ RelOp: IN;
/* 244 */ AND: /(?i)AND(?-i)/;
/* 245 */ ARRAY: /(?i)ARRAY(?-i)/;
/* 246 */ PBEGIN: /(?i)BEGIN(?-i)/;
/* 247 */ CASE: /(?i)CASE(?-i)/;
/* 248 */ CONST: /(?i)CONST(?-i)/;
/* 249 */ DIV: /(?i)DIV(?-i)/;
/* 250 */ DO: /(?i)DO(?-i)/;
/* 251 */ DOWNTO: /(?i)DOWNTO(?-i)/;
/* 252 */ ELSE: /(?i)ELSE(?-i)/;
/* 253 */ END: /(?i)END(?-i)/;
/* 254 */ EXTERNAL: /(?i)EXTERN(AL)?(?-i)/;
/* 255 */ PFILE: /(?i)FILE(?-i)/;
/* 256 */ FOR: /(?i)FOR(?-i)/;
/* 257 */ FORWARD: /(?i)FORWARD(?-i)/;
/* 258 */ FUNCTION: /(?i)FUNCTION(?-i)/;
/* 259 */ GOTO: /(?i)GOTO(?-i)/;
/* 260 */ IF: /(?i)IF(?-i)/;
/* 261 */ IN: /(?i)IN(?-i)/;
/* 262 */ LABEL: /(?i)LABEL(?-i)/;
/* 263 */ MOD: /(?i)MOD(?-i)/;
/* 264 */ NIL: /(?i)NIL(?-i)/;
/* 265 */ NOT: /(?i)NOT(?-i)/;
/* 266 */ OF: /(?i)OF(?-i)/;
/* 267 */ OR: /(?i)OR(?-i)/;
/* 268 */ OTHERWISE: /(?i)OTHERWISE(?-i)/;
/* 269 */ PACKED: /(?i)PACKED(?-i)/;
/* 270 */ PROCEDURE: /(?i)PROCEDURE(?-i)/;
/* 271 */ PROGRAM: /(?i)PROGRAM(?-i)/;
/* 272 */ RECORD: /(?i)RECORD(?-i)/;
/* 273 */ REPEAT: /(?i)REPEAT(?-i)/;
/* 274 */ SET: /(?i)SET(?-i)/;
/* 275 */ THEN: /(?i)THEN(?-i)/;
/* 276 */ TO: /(?i)TO(?-i)/;
/* 277 */ TYPE: /(?i)TYPE(?-i)/;
/* 278 */ UNTIL: /(?i)UNTIL(?-i)/;
/* 279 */ VAR: /(?i)VAR(?-i)/;
/* 280 */ WHILE: /(?i)WHILE(?-i)/;
/* 281 */ WITH: /(?i)WITH(?-i)/;
/* 282 */ IDENTIFIER: /[a-zA-Z_][a-zA-Z0-9_]*/;
/* 283 */ ASSIGNMENT: ':=';
/* 284 */ COLON: ':';
/* 285 */ COMMA: ',';
/* 286 */ DOTDOT: '..';
/* 287 */ DOT: '.';
/* 288 */ EQUAL: '=';
/* 289 */ LPAREN: '(';
/* 290 */ RPAREN: ')';
/* 291 */ LBRAC: '[';
/* 292 */ RBRAC: ']';
/* 293 */ PLUS: '+';
/* 294 */ MINUS: '-';
/* 295 */ SLASH: '/';
/* 296 */ STARSTAR: '**';
/* 297 */ STAR: '*';
/* 298 */ NOTEQUAL: '<>';
/* 299 */ LE: '<=';
/* 300 */ LT: '<';
/* 301 */ GE: '>=';
/* 302 */ GT: '>';
/* 303 */ SEMICOLON: ';';
/* 304 */ UPARROW: '^';
/* 305 */ REALNUMBER: /[0-9]+\.[0-9]+/;
/* 306 */ DIGSEQ: /[0-9]+/;
/* 307 */ CHARACTER_STRING: /'([^']|'')*'/;