1 //****************************************************************
3 //* Syntax.y : Grammar for the LOGLAN-82 and the LOGLAN-93 *
6 //* (c) LITA, university of PAU (France), summer 1993. *
7 //****************************************************************
13 #define RULES_DEBUG_printf(a) fprintf(stderr,a)
14 #define RULES_ERROR_DEBUG
18 #define RULES_DEBUG_printf(a)
22 #ifdef RULES_ERROR_DEBUG
24 #define RULES_ERROR_printf(a) fprintf(stderr,a)
28 #define RULES_ERROR_printf(a)
43 extern int BeginningOfLine;
51 void initialize( void );
55 int yyerror( char * );
75 %type <bool> binary_operator
76 %type <arith> arith_operator arith_operator2
77 %type <ThisReal> opt_Num_const
78 %type <ThisInt> opt_prefix_sign
79 %type <Expr> factor expression expression_in_bracket
80 %type <Expr> NumberConst object_factor composed_expr2
81 %type <Expr> composed_expr logic_expr variable
82 %type <Expr> object generator r_value
83 %type <Expr> one_or_more_logic_factor one_or_more_logic_term
84 %type <Expr> one_or_more_factor one_or_more_term
85 %type <Expr> non_prefixed_variable non_prefixed_generator
86 %type <Expr> short_or_and_list
87 %type <object> object_operator
88 %type <Instr> affectation_instruction instruction
89 %type <Instr> single_instruction complex_instruction
90 %type <Instr> condition_instruction loop_instruction
91 %type <ThisArgJob> parameter_job_instruction
92 %type <ThisBlock> instructions opt_instructions opt_else loop_body
96 %token <ThisLoc> PROGRAM BLOCK PREF
100 %token <ThisLoc> UNIT CLASS PROCEDURE FUNCTION
101 %token <ThisLoc> COROUTINE PROCESS VIRTUAL SHARED ENUM
103 // Parameters transmission mode
105 %token <ThisLoc> INPUT OUTPUT INOUT TAKEN CLOSE HIDDEN
107 // Sub-parts of module
109 %token <ThisLoc> HANDLERS SIGNAL Begin END
111 // Variable and constants declarations
113 %token <ThisLoc> VAR CONST
114 %token <ThisString> IDENTIFIER
115 %token <ThisLoc> INTEGER TYPE REAL BOOLEAN CHARACTER
116 %token <ThisLoc> STRING File ARRAY
120 %token <ThisLoc> LIST_SEPARATOR VARSEPARATOR OPENINGBRACKET
121 %token <ThisLoc> CLOSINGBRACKET ENDSENTENCE POINT
125 %token <ThisLoc> STAR DIVIDE DIV MOD PLUS MINUS
126 %token <ThisLoc> LESS LESSOREQUAL EQUAL NEQUAL
127 %token <ThisLoc> GREATER GREATEROREQUAL
128 %token <ThisLoc> OR AND NOT ANDIF ORIF
129 %token <ThisLoc> AFFECTATION
130 %token <ThisLoc> QUA THIS IS IN NEW COPY ARRAY_OF
131 %token <ThisLoc> NONE
135 %token <ThisString> TEXTCONST
136 %token <ThisChar> CHARCONST
137 %token <ThisInt> DIGITSEQUENCE
138 %token <ThisBool> BOOLCONST
140 //Keywords for Instructions
142 %token <ThisLoc> IF THEN ELSE FI
143 %token <ThisLoc> CASE WHEN OTHERWISE ESAC
144 %token <ThisLoc> WHILE FOR STEP TO DOWNTO DO OD
145 %token <ThisLoc> ATTACH DETACH RESUME STOP TERMINATE
146 %token <ThisLoc> RESULT
147 %token <ThisLoc> GET PUT READ READLN WRITE WRITELN
149 %token <ThisLoc> RAISE KILL
150 %token <ThisLoc> CALL RETURN
151 %token <ThisLoc> EXIT REPEAT
152 %token <ThisLoc> INNER WIND
156 // We begin with the main rule that initialize the variables analyse the
157 // program and then go on is compilation.
159 but: initloglan program endprogram analyse
160 { RULES_DEBUG_printf(" but -> initloglan program analyse \n");} ;
162 // This rule is empty. Is only use is for side-effect.
164 initloglan: { initialize(); }
172 program: program_module
173 {RULES_DEBUG_printf("program -> program_module.\n"); }
175 {RULES_DEBUG_printf("program -> block_module.\n"); }
177 {RULES_DEBUG_printf("program -> unit_module.\n"); }
180 program_module: PROGRAM IDENTIFIER endsentence module_body
181 { RULES_DEBUG_printf("program_module -> PROGRAM IDENTIFIER endsentence module_body.\n"); }
182 | PROGRAM error module_body
183 { RULES_ERROR_printf(" error: program name missing.\n"); }
186 block_module: BLOCK module_body
187 { RULES_DEBUG_printf("block_module -> BLOCK module_body.\n"); }
189 { RULES_ERROR_printf(" error : BLOCK or PROGRAM expected.\n"); }
192 unit_module: module_header module_body
193 { RULES_DEBUG_printf("unit_module -> module_header module_body.\n"); }
196 module_body: opt_declarations module_code
197 { RULES_DEBUG_printf("module_body -> opt_declarations module_code.\n"); }
199 module_header: UNIT opt_virtual IDENTIFIER VARSEPARATOR prefix_list module_type parameters endsentence opt_visibility_declarations
200 { RULES_DEBUG_printf("module_header -> UNIT opt_virtual IDENTIFIER VARSEPARATOR prefix_list modul_type parameters endsentence opt_visibility_declarations.\n"); }
201 | UNIT opt_virtual IDENTIFIER VARSEPARATOR ENUM OPENINGBRACKET identifier_list CLOSINGBRACKET endsentence
202 { RULES_DEBUG_printf("module_header -> UNIT opt_virtual IDENTIFIER VARSEPARATOR ENUM OPENINGBRACKET identifier_list CLOSINGBRACKET endsentence.\n"); }
206 { RULES_DEBUG_printf("prefix_list -> .\n"); }
208 { RULES_DEBUG_printf("prefix_list -> list_prefix.\n"); };
210 list_prefix: opt_shared identifier_path
211 { RULES_DEBUG_printf("list_prefix -> identifier_path .\n"); }
212 | opt_shared identifier_path LIST_SEPARATOR prefix_list
213 { RULES_DEBUG_printf("list_prefix -> identifier_path LIST_SEPARATOR prefix_list.\n"); }
217 { RULES_DEBUG_printf("opt_shared -> SHARED.\n"); }
219 { RULES_DEBUG_printf("opt_shared -> .\n"); }
223 { RULES_DEBUG_printf("opt_virtual -> VIRTUAL.\n"); }
225 { RULES_DEBUG_printf("opt_virtual -> .\n"); }
230 { RULES_DEBUG_printf("identifier_path -> IDENTIFIER.\n"); }
231 | IDENTIFIER VARSEPARATOR identifier_path
232 { RULES_DEBUG_printf("identifier_path -> IDENTIFIER VARSEPARATOR identifier_path.\n"); }
236 { RULES_DEBUG_printf("module_type -> CLASS.\n"); }
238 { RULES_DEBUG_printf("module_type -> PROCEDURE.\n"); }
240 { RULES_DEBUG_printf("module_type -> FUNCTION.\n"); }
242 { RULES_DEBUG_printf("module_type -> COROUTINE.\n"); }
244 { RULES_DEBUG_printf("module_type -> PROCESS.\n"); }
247 parameters: OPENINGBRACKET formal_parameters_list opt_endsentence CLOSINGBRACKET end_parameters
248 { RULES_DEBUG_printf("parameters -> OPENINGBRACKET formal_parameters_list opt_endsentence CLOSINGBRACKET end_parameters.\n"); }
250 { RULES_DEBUG_printf("parameters -> end_parameters.\n"); }
253 end_parameters: VARSEPARATOR typeident
254 { RULES_DEBUG_printf("end_parameters -> VARSEPARATOR IDENTIFIER.\n"); }
256 { RULES_DEBUG_printf("end_parameters -> .\n"); }
259 formal_parameters_list: formal_parameters_list endsentence formal_parameter
260 { RULES_DEBUG_printf("formal_parameters_list -> formal_parameters_list endsentence formal_parameter.\n"); }
262 { RULES_DEBUG_printf("formal_parameters_list -> formal_parameter.\n"); }
265 formal_parameter: parametertype var_param_list
266 { RULES_DEBUG_printf("formal_parameter -> parametertype var_param_list.\n"); }
268 { RULES_DEBUG_printf("formal_parameter -> TYPE IDENTIFIER.\n"); }
270 { RULES_DEBUG_printf("formal_parameter -> callable_module.\n"); }
274 { RULES_DEBUG_printf("parametertype -> INPUT.\n"); }
276 { RULES_DEBUG_printf("parametertype -> OUTPUT.\n"); }
278 { RULES_DEBUG_printf("parametertype -> INOUT.\n"); }
280 { RULES_DEBUG_printf("parametertype -> .\n"); }
283 var_param_list: var_param_list LIST_SEPARATOR var_declaration
284 { RULES_DEBUG_printf("var_param_list -> var_param_list LIST_SEPARATOR var_declaration.\n"); }
286 { RULES_DEBUG_printf("var_param_list -> var_declaration.\n"); }
289 var_declaration: identifier_list VARSEPARATOR typeident
290 { RULES_DEBUG_printf("var_declaration -> identifier_list VARSEPARATOR typeident.\n"); }
293 identifier_list: identifier_list LIST_SEPARATOR IDENTIFIER
294 { RULES_DEBUG_printf("identifier_list -> identifier_list LIST_SEPARATOR IDENTIFIER.\n"); }
296 { RULES_DEBUG_printf("identifier_list -> IDENTIFIER.\n"); }
299 typeident: list_arrayof definedtype
300 { RULES_DEBUG_printf(" typeident -> list_arrayof definedtype .\n"); }
302 { RULES_DEBUG_printf(" typeident -> definedtype .\n"); }
305 list_arrayof: list_arrayof ARRAY_OF
306 { RULES_DEBUG_printf(" list_arrayof -> list_arrayof ARRAY_OF .\n"); }
308 { RULES_DEBUG_printf(" list_arrayof -> .\n"); }
311 definedtype: predefinedtype
315 predefinedtype: INTEGER
316 { RULES_DEBUG_printf(" predefinedtype -> INTEGER .\n"); }
318 { RULES_DEBUG_printf(" predefinedtype -> REAL.\n"); }
320 { RULES_DEBUG_printf(" predefinedtype -> BOOLEAN.\n"); }
322 { RULES_DEBUG_printf(" predefinedtype -> CHARACTER.\n"); }
324 { RULES_DEBUG_printf(" predefinedtype -> STRING.\n"); }
326 { RULES_DEBUG_printf(" predefinedtype -> FILE.\n"); }
328 { RULES_DEBUG_printf(" predefinedtype -> PROCESS.\n"); }
330 { RULES_DEBUG_printf(" predefinedtype -> PROCESS.\n"); }
333 callable_module: function_callable
334 { RULES_DEBUG_printf("callable_module -> function_callable.\n"); }
336 { RULES_DEBUG_printf("callable_module -> procedure_callable.\n"); }
339 function_callable: FUNCTION IDENTIFIER parameters
340 { RULES_DEBUG_printf("function_callable -> FUNCTION IDENTIFIER parameters.\n"); }
343 procedure_callable: PROCEDURE IDENTIFIER parameters
344 { RULES_DEBUG_printf("procedure_callable -> PROCEDURE IDENTIFIER parameters.\n"); }
347 handlers_declaration: HANDLERS handlers_body END HANDLERS opt_endsentence
348 { RULES_DEBUG_printf("handlers_declaration -> HANDLERS handlers_body END HANDLERS opt_endsentence.\n"); }
351 opt_endsentence: ENDSENTENCE
352 { RULES_DEBUG_printf("opt_endsentence -> ENDSENTENCE.\n"); }
354 { RULES_DEBUG_printf("opt_endsentence -> .\n"); }
357 endsentence: ENDSENTENCE
358 { RULES_DEBUG_printf("endsentence -> ENDSENTENCE.\n"); }
360 { RULES_ERROR_printf("error : ';' expected.\n"); }
362 handlers_body: when_list opt_others
363 { RULES_DEBUG_printf("handlers_body -> when_list opt_others.\n"); }
366 when_list: when_list when_unique
367 { RULES_DEBUG_printf("when_list -> when_list when_unique.\n"); }
369 { RULES_DEBUG_printf("when_list -> when_unique.\n"); }
372 when_unique: WHEN identifier_list VARSEPARATOR instructions
373 { RULES_DEBUG_printf("when_unique -> WHEN identifier_list VARSEPARATOR instructions.\n"); }
376 opt_others: OTHERWISE VARSEPARATOR instructions
377 { RULES_DEBUG_printf("opt_others -> OTHERWISE VARSEPARATOR instructions.\n"); }
379 { RULES_DEBUG_printf("opt_others -> .\n"); }
382 module_code: Begin opt_instructions END module_code_end
384 RULES_DEBUG_printf("module_code -> BEGIN opt_instructions END module_code_end.\n");
388 $<ThisBlock>2->Print( cout );
391 | END module_code_end
392 { RULES_DEBUG_printf("module_code -> END module_code_end.\n"); }
395 opt_instructions: instructions
397 RULES_DEBUG_printf("opt_instructions -> instructions opt_endsentence.\n");
398 SEMANTIC(( $<ThisBlock>$ = $<ThisBlock>1 ));
402 RULES_DEBUG_printf("opt_instructions ->.\n");
403 SEMANTIC(( $<ThisBlock>$ = NULL ));
409 { RULES_DEBUG_printf("module_code_end -> IDENTIFIER .\n"); }
411 { RULES_DEBUG_printf("module_code_end -> .\n"); }
415 { RULES_DEBUG_printf("opt_declarations -> .\n"); }
416 | declarations handlers_declaration
417 { RULES_DEBUG_printf("opt_declarations -> declarations handlers_declaration.\n"); }
418 | handlers_declaration
419 { RULES_DEBUG_printf("opt_declarations -> handlers_declaration.\n"); }
421 { RULES_DEBUG_printf("opt_declarations -> declarations .\n"); }
424 declarations: declarations declaration endsentence
425 { RULES_DEBUG_printf("declarations -> declarations declaration endsentence.\n"); }
426 | declaration endsentence
427 { RULES_DEBUG_printf("declarations -> declaration endsentence. \n"); }
430 declaration: const_declaration
431 { RULES_DEBUG_printf("declaration -> const_declaration.\n"); }
432 | variables_declaration
433 { RULES_DEBUG_printf("declaration -> variables_declaration.\n"); }
435 { RULES_DEBUG_printf("declaration -> unit_module.\n"); }
437 { RULES_DEBUG_printf("declarations -> signal_declaration.\n"); }
440 opt_visibility_declarations:
441 visibility_declarations
442 { RULES_DEBUG_printf("opt_visibility_declarations -> visibility_declarations.\n"); }
444 { RULES_DEBUG_printf("opt_visibility_declarations -> .\n"); }
447 visibility_declarations:
448 visibility_declarations visibility_declaration endsentence
449 { RULES_DEBUG_printf("visibility_declarations -> visibility_declarations visibility_declaration endsentence.\n"); }
450 | visibility_declaration endsentence
451 { RULES_DEBUG_printf("visibility_declarations ->visibility_declaration endsentence.\n"); }
454 visibility_declaration:
455 visibility_keyword identifier_list
456 { RULES_DEBUG_printf("visibility_declaration -> visibility_keyword identifier_list.\n"); }
461 { RULES_DEBUG_printf("visibility_keyword -> TAKEN.\n"); }
463 { RULES_DEBUG_printf("visibility_declarations -> CLOSE.\n"); }
465 { RULES_DEBUG_printf("visibility_declarations -> HIDDEN.\n"); }
468 variables_declaration: VAR vars_list
469 { RULES_DEBUG_printf("variables_declaration -> VAR vars_list.\n"); }
472 const_declaration: CONST const_list
473 { RULES_DEBUG_printf("variables_declaration -> CONST const_list.\n"); }
476 signal_declaration: SIGNAL IDENTIFIER parameters
477 { RULES_DEBUG_printf("signal_declaration -> SIGNAL IDENTIFIER parameters.\n");}
480 // instructions are composed of juxtaposition of several instruction.
481 instructions: instruction
483 RULES_DEBUG_printf("instructions -> instruction.\n");
484 SEMANTIC(( $<ThisBlock>$ = new Block( $<Instr>1 ) ));
486 | instructions instruction
488 RULES_DEBUG_printf("instructions -> instructions instruction.\n");
489 SEMANTIC(( *$<ThisBlock>1 += $<Instr>2 ));
493 // An Instruction could be a single instruction (like WRITE or STOP)
494 // or a complex instruction (i.e. composed ) (like IF FOR WHILE CASE ... )
495 instruction: single_instruction endsentence
497 RULES_DEBUG_printf("instruction -> single_instruction endsentence.\n");
498 SEMANTIC(( $<Instr>$ = $<Instr>1 ));
500 | complex_instruction
502 RULES_DEBUG_printf("instruction -> complex_instruction.\n");
503 SEMANTIC(( $<Instr>$ = $<Instr>1 ));
507 // List of every single instruction available
509 affectation_instruction
511 RULES_DEBUG_printf("instruction -> affectation_instruction.\n");
512 SEMANTIC(( $<Instr>$ = $<Instr>1 ));
516 RULES_DEBUG_printf("instruction -> job_instruction.\n");
517 SEMANTIC(( $<Instr>$ = $<Instr>1 ));
520 { RULES_DEBUG_printf("instruction -> io_instruction.\n"); }
522 { RULES_DEBUG_printf("instruction -> signal_instruction.\n"); }
524 { RULES_DEBUG_printf("instruction -> array_instruction.\n"); }
526 { RULES_DEBUG_printf("instruction -> object_instruction.\n"); }
528 { RULES_DEBUG_printf("instruction -> CALL variable.\n"); }
530 { RULES_DEBUG_printf("instruction -> RETURN.\n"); }
532 { RULES_DEBUG_printf("instruction -> exit_instruction.\n"); }
535 // Subdivision of complex instructions :
536 // instruction declaring a loop
537 // instruction declaring a condition
538 // instruction declaring a sub-block
542 RULES_DEBUG_printf("complex_instruction -> loop_instruction.\n");
543 $<Instr>$ = $<Instr>1;
545 | condition_instruction
546 { RULES_DEBUG_printf("complex_instruction -> condition_instruction.\n"); }
548 { RULES_DEBUG_printf("complex_instruction -> block_instruction.\n"); }
550 { RULES_DEBUG_printf("complex_instruction -> case_instruction.\n"); }
553 vars_list: vars_list LIST_SEPARATOR var_declaration
554 { RULES_DEBUG_printf("vars_list -> vars_list LIST_SEPARATOR var_declaration .\n"); }
556 { RULES_DEBUG_printf("vars_list -> var_declaration .\n"); }
559 const_list: const_list LIST_SEPARATOR one_const
560 { RULES_DEBUG_printf("const_list -> const_list LISTSEPARATOR one_const.\n");}
562 { RULES_DEBUG_printf("const_list -> one_const.\n");}
565 one_const: IDENTIFIER EQUAL expression
567 RULES_DEBUG_printf("one_const -> IDENTIFIER EQUAL expression. \n");
571 expression: one_or_more_logic_term
573 RULES_DEBUG_printf("expression -> one_or_more_logic_term.\n");
574 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
578 one_or_more_logic_term:
579 one_or_more_logic_factor
581 RULES_DEBUG_printf("one_or_more_logic_term -> one_or_more_logic_term.\n");
582 SEMANTIC(( $<Expr>$ = $<Expr>1 )) ;
584 | one_or_more_logic_term OR one_or_more_logic_factor
586 RULES_DEBUG_printf("one_or_more_logic_term -> one_or_more_logic_term OR one_or_more_logic_factor.\n");
587 SEMANTIC(( $<Expr>$ = new BoolOperator( $<Expr>1, $<Expr>3 , Or, $<ThisLoc>2 ) ));
591 one_or_more_logic_factor:
594 RULES_DEBUG_printf("one_or_more_logic_factor -> composed_expr.\n");
595 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
597 | one_or_more_logic_factor AND composed_expr
599 RULES_DEBUG_printf("one_or_more_logic_factor -> one_or_more_logic_factor AND composed_expr.\n");
600 SEMANTIC(( $<Expr>$ = new BoolOperator( $<Expr>1, $<Expr>3, And, $<ThisLoc>2 ) ));
604 composed_expr: NOT composed_expr2
606 RULES_DEBUG_printf("composed_expr -> NOT composed_expr2.\n");
607 SEMANTIC(( $<Expr>$ = new Not( $<Expr>2,$<ThisLoc>1 ) ));
611 RULES_DEBUG_printf("composed_expr -> composed_expr2.\n");
612 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
616 composed_expr2: logic_expr
618 RULES_DEBUG_printf("composed_expr2 -> logic_expr.\n");
619 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
621 | logic_expr binary_operator logic_expr
623 RULES_DEBUG_printf("composed_expr2 -> logic_expr binary_operator logic_expr.\n");
624 SEMANTIC(( $<Expr>$ = new BoolOperator( $<Expr>1 , $<Expr>3 , $<bool>2 ) ));
626 | logic_expr object_operator object
628 RULES_DEBUG_printf("composed_expr2 -> logic_expr object_operator logic_expr.\n");
629 SEMANTIC(( $<Expr>$ = new ObjOperator( $<Expr>1 , $<Expr>3 , $<object>2 ) ));
636 RULES_DEBUG_printf("binary_operator -> EQUAL.\n");
637 SEMANTIC(($<bool>$ = Equal));
641 RULES_DEBUG_printf("binary_operator -> NEQUAL.\n");
642 SEMANTIC(($<bool>$ = NotEqual));
646 RULES_DEBUG_printf("binary_operator -> LESS.\n");
647 SEMANTIC(($<bool>$ = Less));
651 RULES_DEBUG_printf("binary_operator -> LESSOREQUAL.\n");
652 SEMANTIC(($<bool>$ = LessOrEqual));
656 RULES_DEBUG_printf("binary_operator -> GREATER.\n");
657 SEMANTIC(($<bool>$ = Greater));
661 RULES_DEBUG_printf("binary_operator -> GREATEROREQUAL.\n");
662 SEMANTIC(($<bool>$ = GreaterOrEqual));
669 RULES_DEBUG_printf("object_operator -> IS.\n");
670 SEMANTIC(( $<object>$ = Is ));
674 RULES_DEBUG_printf("object_operator -> IN.\n");
675 SEMANTIC(( $<object>$ = In ));
680 { RULES_DEBUG_printf("object -> COROUTINE.\n"); }
682 { RULES_DEBUG_printf("object -> PROCESS.\n"); }
685 RULES_DEBUG_printf("object -> IDENTIFIER.\n");
686 SEMANTIC(( $<Expr>$ = new Identifier( $<ThisString>1.Str, $<ThisString>1.Loc ) ));
690 RULES_ERROR_printf("error : bad object.\n");
691 SEMANTIC(( $<Expr>$ = new Error( new Location( ThisPlace ) ));
695 logic_expr: opt_prefix_sign one_or_more_term
697 RULES_DEBUG_printf("expression -> opt_prefix_sign one_or_more_term.\n");
698 // To be modified, must take care of the optionnal prefix sign.
699 SEMANTIC(( $<Expr>$ = $<Expr>2 ));
703 // The optionnal prefixing sign: +a, -a, a
707 RULES_DEBUG_printf("opt_prefix_sign -> PLUS.\n");
708 SEMANTIC(( $<ThisInt>$.Int = 1 ));
709 SEMANTIC(( $<ThisInt>$.Loc = $<ThisLoc>1 ));
713 RULES_DEBUG_printf("opt_prefix_sign -> MINUS.\n");
714 SEMANTIC(( $<ThisInt>$.Int = -1 ));
715 SEMANTIC(( $<ThisInt>$.Loc = $<ThisLoc>1));
719 RULES_DEBUG_printf("opt_prefix_sign -> .\n");
720 SEMANTIC(( $<ThisInt>$.Int = 1 ));
721 SEMANTIC(( $<ThisInt>$.Loc = new Location(ThisPlace) ));
728 RULES_DEBUG_printf("one_or_more_term -> one_or_more_factor.\n");
729 SEMANTIC(($<Expr>$ = $<Expr>1));
731 | one_or_more_term arith_operator one_or_more_factor
733 RULES_DEBUG_printf("one_or_more_term -> one_or_more_term arith_operator one_or_more_factor.\n");
734 SEMANTIC(( $<Expr>$ = new ArithOperator( $<Expr>1 , $<Expr>3 , $<arith>2 ) ));
741 RULES_DEBUG_printf("one_or_more_factor -> factor.\n");
742 SEMANTIC(($<Expr>$ = $<Expr>1));
744 | one_or_more_factor arith_operator2 factor
746 RULES_DEBUG_printf("one_or_more_factor -> one_or_more_factor arith_operator2 factor.\n");
747 SEMANTIC(( $<Expr>$ = new ArithOperator( $<Expr>1 , $<Expr>3 , $<arith>2 ) ));
754 RULES_DEBUG_printf("arith_operator -> PLUS.\n");
755 SEMANTIC(($<arith>$ = Plus));
759 RULES_DEBUG_printf("arith_operator -> MINUS.\n");
760 SEMANTIC(($<arith>$ = Minus));
767 RULES_DEBUG_printf("arith_operator2 -> STAR.\n");
768 SEMANTIC(($<arith>$ = Multiply));
772 RULES_DEBUG_printf("arith_operator2 -> DIVIDE.\n");
773 SEMANTIC(($<arith>$ = Divide));
777 RULES_DEBUG_printf("arith_operator2 -> DIV.\n");
778 SEMANTIC(($<arith>$ = IntDivide));
782 RULES_DEBUG_printf("arith_operator2 -> MOD.\n");
783 SEMANTIC(($<arith>$ = Modulo));
788 RULES_DEBUG_printf("factor -> NumberConst.\n");
789 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
793 RULES_DEBUG_printf("factor -> TextConst.\n");
794 SEMANTIC(( $<Expr>$ = new StringConstant ( $<ThisString>1.Str,
795 $<ThisString>1.Loc ) ));
799 RULES_DEBUG_printf("factor -> CharConst.\n");
800 SEMANTIC(( $<Expr>$ = new CharConstant( $<ThisChar>1.Str,
801 $<ThisChar>1.Loc ) ));
805 RULES_DEBUG_printf("factor -> BOOLCONST.\n");
806 SEMANTIC(( $<Expr>$ = new BoolConstant( $<ThisBool>1.Bool,
807 $<ThisBool>1.Loc ) ));
811 RULES_DEBUG_printf("factor -> variable.\n");
812 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
816 RULES_DEBUG_printf("factor -> object_factor.\n");
817 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
821 RULES_DEBUG_printf("factor -> generator.\n");
822 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
824 | expression_in_bracket
826 RULES_DEBUG_printf("factor -> expression_in_bracket.\n");
827 SEMANTIC(($<Expr>$ = $<Expr>1));
831 RULES_ERROR_printf(" error : bad factor.\n");
832 SEMANTIC(($<Expr>$ = new Error ));
836 // Two results possible : an Integer constant if syntaxic string looks like
838 // or a Real constant if it looks like
840 NumberConst: DIGITSEQUENCE opt_Num_const
842 RULES_DEBUG_printf("NumberConst -> DIGITSEQUENCE opt_Num_const.\n");
845 if ($<ThisReal>2 >= 1)
847 $<Expr>$ = new IntegerConstant((int)($<ThisInt>1.Int * $<ThisReal>2.Real),
848 new Location(*$<ThisInt>1.Loc + *$<ThisReal>2.Loc));
852 $<Expr>$ = new RealConstant( $<ThisInt>1 * $<ThisReal>2,
853 new Location(*$<ThisInt>1.Loc + *$<ThisReal>2.Loc));
857 | DIGITSEQUENCE POINT DIGITSEQUENCE opt_Num_const
859 RULES_DEBUG_printf("NumberConst -> DIGITSEQUENCE POINT DIGITSEQUENCE opt_Num_const.\n");
862 double dec = $<ThisInt>3.Int;
864 while (dec > 1) dec /= 10;
867 $<Expr>$ = new RealConstant( dec * $<ThisReal>4 );
870 | DIGITSEQUENCE POINT opt_Num_const
872 RULES_DEBUG_printf("NumberConst -> DIGITSEQUENCE POINT opt_Num_const.\n");
875 printf("Valeur numerique : ");
876 $<Expr>$ = new RealConstant( $<ThisInt>1 * $<ThisReal>3 );
879 | POINT DIGITSEQUENCE opt_Num_const
881 RULES_DEBUG_printf("NumberConst -> POINT DIGITSEQUENCE opt_Num_const.\n");
884 double dec = $<ThisInt>2;
886 while (dec > 1) dec /= 10;
888 $<Expr>$ = new RealConstant( dec * $<ThisReal>3 );
893 // The IDENTIFIER must be the E letter for the analyse of an sci notated value
894 // ( for example 1E-2 ).
896 opt_Num_const: IDENTIFIER opt_prefix_sign DIGITSEQUENCE
898 RULES_DEBUG_printf("opt_Num_const -> IDENTIFIER opt_prefix_sign DIGITSEQUENCE.\n");
901 if ( *$<ThisString>1 == "E" )
902 $<ThisReal>$ = pow( 10 , (double) $<ThisInt>3 * $<ThisInt>2 );
904 printf("Error : E was expected.\n");
909 RULES_DEBUG_printf("opt_Num_const -> .\n");
910 SEMANTIC(( $<ThisReal>$ = 1 ));
914 RULES_DEBUG_printf(" error : exponant value expected.\n");
915 SEMANTIC(( $<ThisReal>$ = 1 ));
921 RULES_DEBUG_printf("object_factor -> NONE.\n");
922 SEMANTIC(( $<Expr>$ = new NoneObject ));
926 RULES_DEBUG_printf("object_factor -> THIS IDENTIFIER.\n");
927 SEMANTIC(( $<Expr>$ = new This( new Identifier ($<ThisString>2 ) ) ));
930 { RULES_ERROR_printf(" error : IDENTIFIER expected.\n"); }
933 qualifier_expr: non_prefixed_variable
934 { RULES_DEBUG_printf("qualifier_expr -> non_prefixed_variable.\n"); }
935 | non_prefixed_generator
936 { RULES_DEBUG_printf("qualifier_expr -> non_prefixed_generator.\n"); }
939 opt_qualifier: qualifier_expr opt_qua_list POINT
940 { RULES_DEBUG_printf("opt_qualifier -> qualifier_expr opt_qua_list POINT.\n"); }
941 | THIS IDENTIFIER opt_qua_list POINT
942 { RULES_DEBUG_printf("opt_qualifier -> THIS IDENTIFIER opt_qua_list POINT.\n"); }
944 { RULES_DEBUG_printf(" error : IDENTIFIER expected.\n"); }
947 opt_qua_list: opt_qua_list QUA IDENTIFIER
948 { RULES_DEBUG_printf("opt_qua_list -> QUA IDENTIFIER.\n"); }
950 { RULES_DEBUG_printf("opt_qua_list -> .\n"); }
951 | opt_qua_list QUA error
952 { RULES_ERROR_printf(" error : bad qua list (IDENTIFIER is missing).\n"); }
956 opt_list_qualifier opt_qualifier
957 { RULES_DEBUG_printf("opt_list_qualifier -> opt_list_qualifier opt_qualifier.\n"); }
959 { RULES_DEBUG_printf("opt_list_qualifier -> opt_qualifier.\n"); }
962 variable: opt_list_qualifier non_prefixed_variable
964 RULES_DEBUG_printf("variable -> opt_list_qualifier non_prefixed_variable.\n");
965 SEMANTIC(( $<Expr>$ = $<Expr>2 ));
967 | non_prefixed_variable
969 RULES_DEBUG_printf("variable -> non_prefixed_variable.\n");
970 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
974 non_prefixed_variable: RESULT
976 RULES_DEBUG_printf("non_prefixed_variable -> RESULT.\n");
977 SEMANTIC(( $<Expr>$ = new Result ));
981 RULES_DEBUG_printf("non_prefixed_variable -> identifier_path.\n");
982 SEMANTIC(( $<Expr>$ = new Identifier( $<ThisString>1 ) ));
984 | identifier_path OPENINGBRACKET one_or_more_expression CLOSINGBRACKET
986 RULES_DEBUG_printf("non_prefixed_variable -> identifier_path OPENINGBRACKET one_or_more_expression CLOSINGBRACKET.\n");
987 SEMANTIC(( $<Expr>$ = new Identifier( $<ThisString>1 ) ));
991 one_or_more_expression:
993 { RULES_DEBUG_printf("one_or_more_expression -> expression.\n"); }
994 | one_or_more_expression LIST_SEPARATOR expression
995 { RULES_DEBUG_printf("one_or_more_expression -> one_or_more_expression LIST_SEPARATOR expression.\n"); }
998 generator: opt_list_qualifier non_prefixed_generator
1000 RULES_DEBUG_printf("generator -> opt_list_qualifier non_prefixed_generator.\n");
1001 SEMANTIC(( $<Expr>$ = $<Expr>2 ));
1003 | non_prefixed_generator
1005 RULES_DEBUG_printf("generator -> non_prefixed_generator.\n");
1006 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
1010 non_prefixed_generator: NEW identifier_path actual_parameters
1012 RULES_DEBUG_printf(" non_prefixed_generator -> NEW identifier_path actual_paramters.\n");
1013 SEMANTIC(( $<Expr>$ = new New( new Identifier( $<ThisString>2 ) ) ));
1015 | NEW ARRAY OPENINGBRACKET expression LIST_SEPARATOR expression CLOSINGBRACKET
1017 RULES_DEBUG_printf("non_prefixed_generator -> NEW ARRAY OPENINGBRACKET expression VARSEPARATOR expression CLOSINGBRACKET");
1018 SEMANTIC(( $<Expr>$ = new Error ));
1021 { RULES_DEBUG_printf(" error : IDENTIFIER or ARRAY expected.\n"); }
1023 { RULES_DEBUG_printf(" error : syntax error in array definition.\n"); }
1027 | OPENINGBRACKET actual_parameters_list CLOSINGBRACKET
1028 { RULES_DEBUG_printf(" actual_parameters -> OPENINGBRACKET actual_parameters_list CLOSINGBRACKET.\n"); }
1031 actual_parameters_list:
1033 { RULES_DEBUG_printf("actual_paramters_list -> actual_parameter.\n"); }
1034 | actual_parameters_list LIST_SEPARATOR actual_parameter
1035 { RULES_DEBUG_printf("actual_parameters_list -> actual_parameters_list LIST_SEPARATOR actual_parameter.\n"); }
1040 { RULES_DEBUG_printf("actual_parameter -> expression.\n"); }
1042 { RULES_DEBUG_printf("actual_parameter -> predefinedtype.\n"); }
1045 affectation_instruction:
1046 l_identifiers_list AFFECTATION r_value
1048 RULES_DEBUG_printf("affectation_instruction -> l_identifiers_list AFFECTATION r_value.\n");
1049 SEMANTIC(( $<Instr>$ = new Affectation( $<Expr>1 , $<Expr>3 ) ));
1051 | l_identifiers_list error r_value
1053 RULES_ERROR_printf("error : ':=' expected.\n");
1054 SEMANTIC(( $<Instr>$ = new Affectation( $<Expr>1 , $<Expr>3 ) ));
1058 //** Warning !!! Theses actions are to be replaced by something right
1059 //** It's just Test Code .
1061 l_identifiers_list: variable
1063 RULES_DEBUG_printf("l_identifiers_list -> variable.\n");
1064 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
1066 | l_identifiers_list LIST_SEPARATOR variable
1068 RULES_DEBUG_printf("l_identifiers_list -> l_identifiers_list LIST_SEPARATOR variable.\n");
1069 SEMANTIC(( $<Expr>$ = $<Expr>3 ));
1075 RULES_DEBUG_printf("r_value -> expression .\n");
1076 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
1078 | COPY expression_in_bracket
1080 RULES_DEBUG_printf("r_value -> COPY expression_in_bracket .\n");
1081 SEMANTIC(( $<Expr>$ = new Copy( $<Expr>2 ) ));
1086 parameter_job_instruction OPENINGBRACKET expression CLOSINGBRACKET
1088 RULES_DEBUG_printf("job_instruction -> parameter_job_instruction ( expression ).\n");
1091 switch($<ThisArgJob>1)
1094 $<Instr>$ = new Attach( $<Expr>3 );
1097 $<Instr>$ = new Resume( $<Expr>3 );
1100 $<Instr>$ = new Stop( $<Expr>3 );
1107 RULES_DEBUG_printf("job_instruction -> DETACH.\n");
1108 SEMANTIC(( $<Instr>$ = new Detach ));
1112 RULES_DEBUG_printf("job_instruction -> STOP.\n");
1113 SEMANTIC(( $<Instr>$ = new Stop ));
1117 RULES_DEBUG_printf("job_instruction -> TERMINATE.\n");
1118 SEMANTIC(( $<Instr>$ = new Terminate ));
1122 parameter_job_instruction:
1125 RULES_DEBUG_printf("parameter_job_instruction -> ATTACH.\n");
1126 SEMANTIC(( $<ThisArgJob>$ = AttachInstr ));
1130 RULES_DEBUG_printf("parameter_job_instruction -> RESUME.\n");
1131 SEMANTIC(( $<ThisArgJob>$ = ResumeInstr ));
1135 RULES_DEBUG_printf("parameter_job_instruction -> STOP.\n");
1136 SEMANTIC(( $<ThisArgJob>$ = StopInstr ));
1142 { RULES_DEBUG_printf("io_instruction -> file_io_instruction .\n"); }
1144 { RULES_DEBUG_printf("io_instruction -> input_instruction .\n"); }
1145 | output_instruction
1146 { RULES_DEBUG_printf("io_instruction -> output_instruction .\n"); }
1149 file_io_instruction:
1150 file_io_keyword OPENINGBRACKET expression LIST_SEPARATOR one_or_more_expression CLOSINGBRACKET
1151 { RULES_DEBUG_printf("file_io_instruction -> file_io_keyword ( expression LIST_SEPARATOR one_or_more_expression ).\n"); }
1156 { RULES_DEBUG_printf("file_io_keyword -> PUT.\n"); }
1158 { RULES_DEBUG_printf("file_io_keyword -> GET.\n"); }
1162 input_keyword OPENINGBRACKET l_identifiers_list CLOSINGBRACKET
1163 { RULES_DEBUG_printf("input_instruction -> input_keyword ( l_identifiers_list ).\n"); }
1165 { RULES_DEBUG_printf("input_instruction -> READLN.\n"); }
1170 { RULES_DEBUG_printf("input_keyword -> READ.\n"); }
1172 { RULES_DEBUG_printf("input_keyword -> READLN.\n"); }
1176 output_keyword OPENINGBRACKET l_formated_identifiers_list CLOSINGBRACKET
1177 { RULES_DEBUG_printf("output_instructions -> output_keyword ( l_formated_identifiers_list ).\n"); }
1179 { RULES_DEBUG_printf("output_instructions -> WRITELN.\n"); }
1184 { RULES_DEBUG_printf("output_keyword -> WRITE.\n"); }
1186 { RULES_DEBUG_printf("output_keyword -> WRITELN.\n"); }
1189 l_formated_identifiers_list:
1190 expression opt_modifiers
1191 { RULES_DEBUG_printf("l_formatted_identifiers_list -> expression opt_modifiers.\n"); }
1192 | l_formated_identifiers_list LIST_SEPARATOR expression opt_modifiers
1193 { RULES_DEBUG_printf("l_formatted_identifiers_list -> l_formated_identifiers_list LIST_SEPARATOR expression opt_modifiers.\n"); }
1196 opt_modifiers: VARSEPARATOR NumberConst opt_modifiers2
1197 { RULES_DEBUG_printf(" opt_modifiers -> VARSEPARATOR NumberConst opt_modifiers2.\n");}
1199 { RULES_DEBUG_printf(" opt_modifiers -> .\n");}
1201 opt_modifiers2: VARSEPARATOR NumberConst
1202 { RULES_DEBUG_printf(" opt_modifiers2 -> VARSEPARATOR NumberConst.\n");}
1204 { RULES_DEBUG_printf(" opt_modifiers2 -> .\n");}
1208 RAISE IDENTIFIER actual_parameters
1209 { RULES_DEBUG_printf("signal_instruction -> RAISE IDENTIFIER actual_parameters.\n"); }
1213 ARRAY variable DIM OPENINGBRACKET expression VARSEPARATOR expression CLOSINGBRACKET
1214 { RULES_DEBUG_printf("array_instruction -> ARRAY variable DIM OPENINGBRACKET expression VARSEPARATOR expression CLOSINGBRACKET.\n"); }
1218 exit_list opt_repeat
1219 { RULES_DEBUG_printf("exit_instruction -> opt_exit_list opt_repeat.\n");}
1221 { RULES_DEBUG_printf("exit_instruction -> REPEAT.\n");}
1223 exit_list: exit_list EXIT
1224 { RULES_DEBUG_printf("opt_exit_list -> opt_exit_list EXIT.\n");}
1226 { RULES_DEBUG_printf("opt_exit_list -> EXIT .\n");}
1230 { RULES_DEBUG_printf("opt_repeat -> REPEAT.\n");}
1232 { RULES_DEBUG_printf("opt_repeat -> .\n");}
1236 WHILE expression loop_body
1238 RULES_DEBUG_printf("loop_header -> WHILE expression loop_body.\n");
1239 SEMANTIC(( $<Instr>$ = new While( $<Expr>2, $<ThisBlock>3 ) ));
1241 | FOR variable AFFECTATION expression DOWNTO expression loop_body
1243 RULES_DEBUG_printf("loop_header -> FOR variable AFFECTATION expression DOWNTO expression loop_body.\n");
1244 SEMANTIC(( $<Instr>$ = new For( $<Expr>2,
1246 new IntegerConstant( -1 ),
1249 | FOR variable AFFECTATION expression TO expression loop_body
1251 RULES_DEBUG_printf("loop_header -> FOR variable AFFECTATION expression TO expression loop_body.\n");
1252 SEMANTIC(( $<Instr>$ = new For( $<Expr>2,
1254 new IntegerConstant( 1 ),
1257 | FOR variable AFFECTATION expression TO expression STEP expression loop_body
1259 RULES_DEBUG_printf("loop_header -> FOR variable AFFECTATION expression TO expression STEP expression loop_body.\n");
1260 SEMANTIC(( $<Instr>$ = new For( $<Expr>2,
1268 DO opt_instructions OD
1270 RULES_DEBUG_printf("loop_body -> DO opt_instructions OD.\n");
1271 SEMANTIC(( $<ThisBlock>$ = $<ThisBlock>2 ));
1273 | DO opt_instructions error
1275 RULES_ERROR_printf("error OD expected.\n");
1276 SEMANTIC(( $<ThisBlock>$ = NULL ));
1280 condition_instruction:
1281 IF short_or_and_list THEN opt_instructions opt_else FI
1283 RULES_DEBUG_printf("condition_instruction -> IF short_or_and_list THEN opt_instructions opt_else FI.\n");
1284 SEMANTIC(( $<Instr>$ = new ConditionIf( $<Expr>2, $<ThisBlock>4, $<ThisBlock>5 ) ));
1286 | IF short_or_and_list error
1287 { RULES_ERROR_printf("error : THEN expected.\n"); }
1288 | IF short_or_and_list THEN opt_instructions opt_else error
1289 { RULES_ERROR_printf("error : FI or ELSE expected.\n"); }
1292 short_or_and_list: expression
1294 RULES_DEBUG_printf("short_or_and_list -> expression.\n");
1295 SEMANTIC(( $<Expr>$ = $<Expr>1 ));
1297 // The two next rules are wrong because ORIF and ANDIF are supposed to have
1298 // the same priority. This has to be fixed.
1299 | short_or_and_list ORIF expression
1301 RULES_DEBUG_printf("short_or_and_list -> short_or_and_list ORIF expression.\n");
1302 SEMANTIC(( $<Expr>$ = new BoolOperator( $<Expr>1, $<Expr>3, Or ) ));
1304 | short_or_and_list ANDIF expression
1306 RULES_DEBUG_printf("short_or_and_list -> short_or_and_list ANDIF expression.\n");
1307 SEMANTIC(( $<Expr>$ = new BoolOperator( $<Expr>1, $<Expr>3, And ) ));
1311 opt_else: ELSE opt_instructions
1313 RULES_DEBUG_printf("opt_else -> ELSE opt_instructions. \n");
1314 SEMANTIC(( $<ThisBlock>$ = $<ThisBlock>2 ));
1318 RULES_DEBUG_printf("opt_else -> . \n");
1319 SEMANTIC(( $<ThisBlock>$ = NULL ));
1324 CASE expression case_when_list opt_case_otherwise ESAC
1325 { RULES_DEBUG_printf("case_instruction -> CASE expression case_when_list opt_case_otherwise ESAC.\n"); }
1329 OTHERWISE opt_instructions
1330 { RULES_DEBUG_printf("opt_case_otherwise -> OTHERWISE opt_instructions.\n"); }
1332 { RULES_DEBUG_printf("opt_case_otherwise -> .\n"); }
1337 { RULES_DEBUG_printf("case_when_list -> one_when_case.\n"); }
1338 | case_when_list one_when_case
1339 { RULES_DEBUG_printf("case_when_list -> case_when_list one_when_case.\n"); }
1342 one_when_case: WHEN expression VARSEPARATOR opt_instructions
1343 { RULES_DEBUG_printf("one_when_case -> WHEN expression VARSEPARATOR opt_instructions.\n"); }
1348 { RULES_DEBUG_printf("object_instruction -> WIND.\n"); }
1350 { RULES_DEBUG_printf("object_instruction -> INNER.\n"); }
1351 | KILL expression_in_bracket
1352 { RULES_DEBUG_printf("object_instruction -> KILL expression_in_bracket.\n"); }
1354 { RULES_DEBUG_printf("object_instruction -> generator.\n"); }
1358 PREF IDENTIFIER actual_parameters BLOCK opt_block_taken module_body endsentence
1359 { RULES_DEBUG_printf("block_instruction -> PREF IDENTIFIER actual_parameters BLOCK opt_block_taken module_body endsentence.\n"); }
1363 TAKEN identifier_list endsentence
1364 { RULES_DEBUG_printf("opt_block_taken -> TAKEN identifier_list endsentence.\n"); }
1366 { RULES_DEBUG_printf("opt_block_taken -> .\n"); }
1368 expression_in_bracket:
1369 OPENINGBRACKET expression CLOSINGBRACKET
1371 RULES_DEBUG_printf("expression_in_bracket -> OPENINGBRACKET expression CLOSINGBRACKET.\n");
1372 SEMANTIC(( $<Expr>$ = $<Expr>2 ));
1374 | OPENINGBRACKET expression error
1375 { RULES_ERROR_printf("error : unbalanced bracket. \n"); }
1378 endprogram: ENDSENTENCE
1379 { RULES_DEBUG_printf("endprogram -> ENDSENTENCE.\n"); }
1381 { RULES_DEBUG_printf("endprogram -> POINT.\n"); }
1383 { RULES_ERROR_printf("error : ';' or '.' expected.\n"); }
1386 void initialize( void )
1388 BeginningOfLine = 1;
1398 printf("Syntax error at line %d.\n",line_number);
1402 int yyerror( char *s )