comparison tests/agcl/contrib/plm.syn @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 /* YACC parser for PL/M syntax.
2
3 $Id: plm.syn,v 1.1 2007/04/05 06:29:19 dholland Exp $
4 From: plm-parse.y,v 1.1 1994/02/28 20:54:56 hays Exp
5
6 Copyright 1994 by Kirk Hays (hays@ichips.intel.com) and Gary Funck
7 (gary@intrepid.com)
8
9 USE AT YOUR OWN RISK. NO WARRANTY EXPRESSED OR IMPLIED.
10 This code is distributed in the hope that it will be useful,
11 but without any warranty. Further, there is no implied warranty of
12 merchantability or fitness for a particular purpose.
13
14 */
15
16 /* This file defines the grammar of PL/M. */
17
18
19 {
20
21
22 /*
23 * YACC grammar of PL/M
24 */
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include "plm-manifest.h"
28 #include "scope.h"
29
30 void yyerror ();
31
32 /* Cause the `yydebug' variable to be defined. */
33 #define YYDEBUG (1)
34
35
36 }
37 ADDRESS = "address"
38 AND = "and"
39 ASSIGN_OP = ":="
40 AT = "at"
41 AT_SIGN = '@'
42 BASED = "based"
43 BY = "by"
44 BYTE = "byte"
45 CALL = "call"
46 CASE = "case"
47 CAUSE_INTERRUPT = "causeInterrupt"
48 CHARINT = "charint"
49 COLON = ':'
50 COMMA = ','
51 DATA = "data"
52 DECLARE = "declare"
53 DISABLE = "disable"
54 DO = "do"
55 DOT = '.'
56 DWORD = "dword"
57 ELSE = "else"
58 ENABLE = "enable"
59 END = "end"
60 EOF_KW = "eof"
61 EQ = '='
62 EXTERNAL = "external"
63 GE = ">="
64 GO = "go"
65 GOTO = "goto"
66 GT = '>'
67 HALT = "halt"
68 HWORD = "hword"
69 IF = "if"
70 INITIAL_KW = "initial"
71 INTEGER = "integer"
72 INTERRUPT = "interupt"
73 LABEL = "label"
74 LE = "<="
75 LITERALLY = "literally"
76 LONGINT = "longint"
77 LPAREN = '('
78 LT = '<'
79 MINUS = "minus"
80 MINUS_SIGN = '-'
81 MOD = "mod"
82 NE = "<>"
83 NOT = "not"
84 OFFSET = "offset"
85 OR = "or"
86 PLUS = "plus"
87 PLUS_SIGN = '+'
88 POINTER = "pointer"
89 PROCEDURE = "procedure"
90 PUBLIC = "public"
91 QWORD = "qword"
92 REAL = "real"
93 REENTRANT = "reentrant"
94 RETURN = "return"
95 RPAREN = ')'
96 SELECTOR = "selector"
97 SEMI = ';'
98 SHORTINT = "shortint"
99 SLASH = '/'
100 STAR = '*'
101 STRUCTURE = "structure"
102 THEN = "then"
103 TO = "to"
104 WHILE = "while"
105 WORD = "word"
106 XOR = "xor"
107
108 [
109 grammar token = compilation
110 case sensitive = OFF
111 disregard white space
112 distinguish lexemes
113 lexeme {numeric_constant, IDENTIFIER, STRING}
114 ]
115
116 eof = -1 + 0 + ^D + ^Z
117
118 white space
119 -> ' ' + '\t' + '\r' + '\f' + '\v' + '\n'
120 -> "/*", ~eof?..., "*/"
121
122 actual_parameters
123 -> LPAREN, expression_list, RPAREN
124
125 adding_operator
126 -> MINUS
127 -> MINUS_SIGN
128 -> PLUS
129 -> PLUS_SIGN
130
131 and_operator
132 -> AND
133
134 arithmetic_expression
135 -> term
136 -> arithmetic_expression, adding_operator, term
137
138 array_specifier
139 -> explicit_dimension
140 -> implicit_dimension
141
142 assignment_statement
143 -> left_part, EQ, expression, SEMI
144
145 base_specifier
146 -> IDENTIFIER
147 -> IDENTIFIER, DOT, IDENTIFIER
148
149 basic_statement
150 -> assignment_statement
151 -> call_statement
152 -> goto_statement
153 -> microprocessor_dependent_statement
154 -> null_statement
155 -> return_statement
156
157 basic_type
158 -> ADDRESS
159 -> BYTE
160 -> CHARINT
161 -> DWORD
162 -> HWORD
163 -> INTEGER
164 -> LONGINT
165 -> OFFSET
166 -> POINTER
167 -> QWORD
168 -> REAL
169 -> SELECTOR
170 -> SHORTINT
171 -> WORD
172
173 bound_expression
174 -> expression
175
176 by_part
177 -> BY, step_expression
178
179 call_statement
180 -> CALL, simple_variable, SEMI
181 -> CALL, simple_variable, actual_parameters, SEMI
182
183 cast_type
184 -> basic_type
185
186 cause_interrupt_statement
187 -> CAUSE_INTERRUPT, LPAREN, integer_constant, RPAREN, SEMI
188
189 compilation
190 -> module, eof
191 -> module, EOF_KW, eof
192
193 conditional_clause
194 -> if_condition, true_unit
195 -> if_condition, true_element, ELSE, false_element
196
197 constant
198 -> STRING
199 -> numeric_constant
200
201 constant_attribute
202 -> DATA
203
204 constant_list
205 -> constant
206 -> constant_list, COMMA, constant
207
208 declaration
209 -> declare_statement
210 -> procedure_definition
211
212 declaration_sequence
213 -> declaration
214 -> declaration_sequence, declaration
215
216 declare_element
217 -> factored_element
218 -> unfactored_element
219
220 declare_element_list
221 -> declare_element
222 -> declare_element_list, COMMA, declare_element
223
224 declare_statement
225 -> DECLARE, declare_element_list, SEMI
226
227 disable_statement
228 -> DISABLE, SEMI
229
230 do_block
231 -> do_case_block
232 -> do_while_block
233 -> iterative_do_block
234 -> simple_do_block
235
236 do_case_block
237 -> do_case_statement, ending
238 -> do_case_statement, unit_sequence, ending
239
240 do_case_statement
241 -> DO, CASE, expression, SEMI ={
242 push_scope();
243 }
244
245 do_while_block
246 -> do_while_statement, ending
247 -> do_while_statement, unit_sequence, ending
248
249 do_while_statement
250 -> DO, WHILE, expression, SEMI ={
251 push_scope();
252 }
253
254 embedded_assignment
255 -> variable_reference, ASSIGN_OP, logical_expression
256
257 enable_statement
258 -> ENABLE, SEMI
259
260 end_statement
261 -> END, opt_identifier, SEMI ={
262 pop_scope();
263 }
264 ending
265 -> end_statement
266 -> label_definition_sequence, end_statement
267
268 explicit_dimension
269 -> LPAREN, numeric_constant, RPAREN
270
271 expression
272 -> embedded_assignment
273 -> logical_expression
274
275 expression_list
276 -> expression
277 -> expression_list, COMMA, expression
278
279 factored_element
280 -> factored_label_element
281 -> factored_variable_element
282
283 /*
284 * factored_label_element doesn't permit based variables,
285 * yet factored_variable_element does. This can't be disambiguated
286 * syntactically. Thus, the factored_label element will have to
287 * make the proper semantic checks to make the sure that the
288 * variable_name_specifier_list is in fact an identifier_list.
289 */
290
291 factored_label_element
292 -> LPAREN, variable_name_specifier_list, RPAREN, LABEL, opt_public_or_external
293
294 factored_member
295 -> LPAREN, member_name_list, RPAREN, opt_explicit_dimension, variable_type
296
297 factored_variable_element
298 -> LPAREN, variable_name_specifier_list, RPAREN, opt_explicit_dimension, variable_type, opt_variable_attributes
299
300 false_element
301 -> unit
302
303 formal_parameter
304 -> IDENTIFIER
305
306 formal_parameter_list
307 -> formal_parameter
308 -> formal_parameter_list, COMMA, formal_parameter
309
310 formal_parameter_specifier
311 -> LPAREN, formal_parameter_list, RPAREN
312
313 go_to
314 -> GOTO
315 -> GO, TO
316
317 goto_statement
318 -> go_to, IDENTIFIER, SEMI
319
320 halt_statement
321 -> HALT, SEMI
322
323 id_colon
324 -> IDENTIFIER, COLON
325
326 if_condition
327 -> IF, expression, THEN
328
329 implicit_dimension
330 -> LPAREN, STAR, RPAREN
331
332 index_part
333 -> index_variable, EQ, start_expression
334
335 index_variable
336 -> simple_variable
337
338 initial_value
339 -> expression
340
341 initial_value_list
342 -> initial_value
343 -> initial_value_list, COMMA, initial_value
344
345 initialization
346 -> DATA, LPAREN, initial_value_list, RPAREN
347 -> INITIAL_KW, LPAREN, initial_value_list, RPAREN
348
349 integer_constant
350 -> binary number
351 -> decimal number
352 -> hex number
353 -> octal number
354
355 interrupt
356 -> INTERRUPT, opt_interrupt_number
357
358 interrupt_number
359 -> integer_constant
360
361 iterative_do_block
362 -> iterative_do_statement, ending
363 -> iterative_do_statement, unit_sequence, ending
364
365 iterative_do_statement
366 -> DO, index_part, to_part, opt_by_part, SEMI ={
367 push_scope();
368 }
369 label_definition
370 -> id_colon
371
372 label_definition_sequence
373 -> label_definition
374 -> label_definition_sequence, label_definition
375
376 label_element
377 -> IDENTIFIER, LABEL, opt_public_or_external
378
379 left_part
380 -> variable_reference_list
381
382 literal_element
383 -> IDENTIFIER, LITERALLY, STRING ={
384 enter_literal ($1, $3);
385 }
386
387 location_reference
388 -> AT_SIGN, variable_reference
389 -> AT_SIGN, LPAREN, constant_list, RPAREN
390 -> DOT, variable_reference
391 -> DOT, LPAREN, constant_list, RPAREN
392
393 locator
394 -> AT, LPAREN, expression, RPAREN
395
396 locator_initialization
397 -> locator
398 -> initialization
399 -> locator, initialization
400
401 logical_expression
402 -> logical_factor
403 -> logical_expression, or_operator, logical_factor
404
405 logical_factor
406 -> logical_secondary
407 -> logical_factor, and_operator, logical_secondary
408
409 logical_primary
410 -> arithmetic_expression
411 -> arithmetic_expression, relation_operator, arithmetic_expression
412
413 logical_secondary
414 -> logical_primary
415 -> NOT, logical_primary
416
417 member_element
418 -> structure_type
419 -> factored_member
420 -> unfactored_member
421
422 member_element_list
423 -> member_element
424 -> member_element_list, COMMA, member_element
425
426 member_name
427 -> IDENTIFIER
428
429 member_name_list
430 -> member_name
431 -> member_name_list, COMMA, member_name
432
433 member_specifier
434 -> DOT, member_name
435 -> DOT, member_name, subscript
436
437 member_specifier_sequence
438 -> member_specifier_sequence, member_specifier
439 -> member_specifier
440
441 microprocessor_dependent_statement
442 -> cause_interrupt_statement
443 -> disable_statement
444 -> enable_statement
445 -> halt_statement
446
447 module
448 -> module_name, COLON, simple_do_block
449
450 module_name
451 -> IDENTIFIER
452
453 multiplying_operator
454 -> MOD
455 -> SLASH
456 -> STAR
457
458 null_statement
459 -> SEMI
460
461 numeric_constant
462 -> floating point number
463 -> integer_constant
464
465 opt_array_specifier
466 -> /* empty */
467 -> array_specifier
468
469 opt_by_part
470 -> /* empty */
471 -> by_part
472
473 opt_explicit_dimension
474 -> /* empty */
475 -> explicit_dimension
476
477 opt_formal_parameter_specifier
478 -> /* empty */
479 -> formal_parameter_specifier
480
481 opt_identifier
482 -> /* empty */
483 -> IDENTIFIER
484
485 opt_interrupt_number
486 -> /* empty */
487 -> interrupt_number
488
489 opt_procedure_attribute_sequence
490 -> /* empty */
491 -> procedure_attribute_sequence
492
493 opt_procedure_type
494 -> /* empty */
495 -> procedure_type
496
497 opt_public_or_external
498 -> /* empty */
499 -> EXTERNAL
500 -> PUBLIC
501
502 opt_variable_attributes
503 -> /* empty */
504 -> variable_attributes
505
506 or_operator
507 -> OR
508 -> XOR
509
510 primary
511 -> constant
512 -> location_reference
513 -> subexpression
514 -> variable_reference
515
516 procedure_attribute
517 -> EXTERNAL
518 -> PUBLIC
519 -> REENTRANT
520 -> interrupt, PUBLIC
521 -> interrupt, EXTERNAL
522
523 procedure_attribute_sequence
524 -> procedure_attribute
525 -> procedure_attribute_sequence, procedure_attribute
526
527 procedure_definition
528 -> procedure_statement, ending
529 -> procedure_statement, declaration_sequence, ending
530 -> procedure_statement, unit_sequence, ending
531 -> procedure_statement, declaration_sequence, unit_sequence, ending
532
533 procedure_statement
534 -> id_colon, PROCEDURE, opt_formal_parameter_specifier, opt_procedure_type, opt_procedure_attribute_sequence, SEMI ={
535 push_scope();
536 }
537
538 procedure_type
539 -> basic_type
540
541 relation_operator
542 -> EQ
543 -> GE
544 -> GT
545 -> LE
546 -> LT
547 -> NE
548
549 return_statement
550 -> typed_return
551 -> untyped_return
552
553 secondary
554 -> primary
555 -> unary_sign, primary
556
557 simple_do_block
558 -> simple_do_statement, ending
559 -> simple_do_statement, unit_sequence, ending
560 -> simple_do_statement, declaration_sequence, ending
561 -> simple_do_statement, declaration_sequence, unit_sequence, ending
562
563 simple_do_statement
564 -> DO, SEMI ={
565 push_scope();
566 }
567
568 simple_variable
569 -> IDENTIFIER
570 -> IDENTIFIER, DOT, IDENTIFIER
571
572 start_expression
573 -> expression
574
575 step_expression
576 -> expression
577
578 structure_type
579 -> STRUCTURE, LPAREN, member_element_list, RPAREN
580
581 subexpression
582 -> LPAREN, expression, RPAREN
583
584 subscript
585 -> LPAREN, expression, RPAREN
586
587 subscript_or_actual_parameters
588 -> LPAREN, expression_list, RPAREN
589
590 term
591 -> secondary
592 -> term, multiplying_operator, secondary
593
594 to_part
595 -> TO, bound_expression
596
597 true_element
598 -> true_statement
599 -> label_definition_sequence, true_statement
600
601 true_statement
602 -> do_block
603 -> basic_statement
604
605 true_unit
606 -> unit
607
608 typed_return
609 -> RETURN, expression, SEMI
610
611 unary_minus
612 -> MINUS_SIGN
613
614 unary_plus
615 -> PLUS_SIGN
616
617 unary_sign
618 -> unary_minus
619 -> unary_plus
620
621 unfactored_element
622 -> label_element
623 -> literal_element
624 -> variable_element
625
626 unfactored_member
627 -> member_name, opt_explicit_dimension, variable_type
628
629 unit
630 -> unit_element
631 -> label_definition_sequence, unit_element
632
633 unit_element
634 -> basic_statement
635 -> conditional_clause
636 -> do_block
637
638 unit_sequence
639 -> unit
640 -> unit_sequence, unit
641
642 untyped_return
643 -> RETURN, SEMI
644
645 variable_attributes
646 -> EXTERNAL, constant_attribute
647 -> EXTERNAL
648 -> PUBLIC, locator_initialization
649 -> PUBLIC
650 -> locator_initialization
651
652 variable_element
653 -> variable_name_specifier, opt_array_specifier, variable_type, opt_variable_attributes
654
655 variable_name_specifier
656 -> IDENTIFIER
657 -> IDENTIFIER, BASED, base_specifier
658
659 variable_name_specifier_list
660 -> variable_name_specifier
661 -> variable_name_specifier_list, COMMA, variable_name_specifier
662 /*
663 * Variable references may be either data references or function
664 * references. Syntactically, they appear to be the same, each
665 * is followed by a parenthesized comma separated list of expressions.
666 *
667 * A function reference, of course, cannot have the trailing list of
668 * member specifiers - semantic checking will catch this.
669 */
670
671 variable_reference
672 -> IDENTIFIER
673 -> IDENTIFIER, member_specifier_sequence
674 -> cast_type, subscript
675 -> IDENTIFIER, subscript_or_actual_parameters
676 -> IDENTIFIER, subscript_or_actual_parameters, member_specifier_sequence
677
678 variable_reference_list
679 -> variable_reference
680 -> variable_reference_list, COMMA, variable_reference
681
682 variable_type
683 -> basic_type
684 -> structure_type
685
686 decimal number tail
687 ->
688 -> 'd'
689 -> '0-9', decimal number tail
690 -> '$', decimal number tail
691
692 decimal number
693 -> '0-9', decimal number tail
694
695 binary number tail
696 -> 'b' + 'B'
697 -> '0-1', binary number tail
698 -> '$', binary number tail
699
700 binary number
701 -> '0-1', binary number tail
702
703 octal number tail
704 -> 'o' + 'O' + 'q' + 'Q'
705 -> '0-7', octal number tail
706 -> '$', octal number tail
707
708 octal number
709 -> '0-7', octal number tail
710
711 hex number tail
712 -> 'h' + 'H'
713 -> '0-9' + 'a-f' + 'A-F', hex number tail
714 -> '$', hex number tail
715
716 hex number
717 -> '0-9', hex number tail
718
719 floating point number tail
720 -> fraction part
721 -> fraction part, exponent
722 -> '0-9', floating point number tail
723
724 floating point number
725 -> '0-9', floating point number tail
726
727 fraction part
728 -> DOT
729 -> fraction part, '0-9'
730
731 exponent
732 -> 'e' + '+', '0-9'...
733 -> '-', '0-9'...
734
735 IDENTIFIER
736 -> 'a-z'
737 -> IDENTIFIER, 'a-z' + '0-9' + '$' + '_'
738
739 STRING
740 -> '\'', [~(eof + '\'') | "''"]..., '\''
741
742 {
743
744
745 void
746 yyerror(char * s)
747 {
748 fprintf (stderr, "error at line %d: %s\n", lineno, s);
749 }
750
751 main()
752 {
753 init_scope();
754 return yyparse();
755 }
756
757 }