89 * function from the resulting c code, so the compiler |
89 * function from the resulting c code, so the compiler |
90 * no longer complains. |
90 * no longer complains. |
91 */ |
91 */ |
92 %option noyy_top_state |
92 %option noyy_top_state |
93 |
93 |
|
94 /* We will not be using unput() in our flex code... */ |
|
95 %option nounput |
|
96 |
94 /**************************************************/ |
97 /**************************************************/ |
95 /* External Variable and Function declarations... */ |
98 /* External Variable and Function declarations... */ |
96 /**************************************************/ |
99 /**************************************************/ |
97 |
100 |
98 |
101 |
149 extern const char *current_filename; |
152 extern const char *current_filename; |
150 */ |
153 */ |
151 |
154 |
152 |
155 |
153 /* We will not be using unput() in our flex code... */ |
156 /* We will not be using unput() in our flex code... */ |
|
157 /* NOTE: it seems that this #define is no longer needed, It has been |
|
158 * replaced by %option nounput. |
|
159 * Should we simply delete it? |
|
160 * For now leave it in, in case someone is using an old version of flex. |
|
161 * In any case, the most harm that can result in a warning message |
|
162 * when compiling iec.flex.c: |
|
163 * warning: ‘void yyunput(int, char*)’ defined but not used |
|
164 */ |
154 #define YY_NO_UNPUT |
165 #define YY_NO_UNPUT |
155 |
166 |
156 /* Variable defined by the bison parser. |
167 /* Variable defined by the bison parser. |
157 * It must be initialised with the location |
168 * It must be initialised with the location |
158 * of the token being parsed. |
169 * of the token being parsed. |
443 |
454 |
444 /*****************************/ |
455 /*****************************/ |
445 /* Prelimenary constructs... */ |
456 /* Prelimenary constructs... */ |
446 /*****************************/ |
457 /*****************************/ |
447 |
458 |
448 |
459 /* In order to allow the declaration of POU prototypes (Function, FB, Program, ...), |
449 /* A pragma... */ |
460 * especially the prototypes of Functions and FBs defined in the standard |
|
461 * (i.e. standard functions and FBs), we extend the IEC 61131-3 standard syntax |
|
462 * with two pragmas to indicate that the code is to be parsed (going through the |
|
463 * lexical, syntactical, and semantic analysers), but no code is to be generated. |
|
464 * |
|
465 * The accepted syntax is: |
|
466 * {no_code_generation begin} |
|
467 * ... prototypes ... |
|
468 * {no_code_generation end} |
|
469 * |
|
470 * When parsing these prototypes the abstract syntax tree will be populated as usual, |
|
471 * allowing the semantic analyser to correctly analyse the semantics of calls to these |
|
472 * functions/FBs. However, stage4 will simply ignore all IEC61131-3 code |
|
473 * between the above two pragmas. |
|
474 */ |
|
475 |
|
476 disable_code_generation_pragma "{disable code generation}" |
|
477 enable_code_generation_pragma "{enable code generation}" |
|
478 |
|
479 |
|
480 /* Any other pragma... */ |
450 |
481 |
451 pragma "{"[^}]*"}" |
482 pragma "{"[^}]*"}" |
452 |
483 |
453 /* NOTE: this seemingly unnecessary complex definition is required |
484 /* NOTE: this seemingly unnecessary complex definition is required |
454 * to be able to eat up comments such as: |
485 * to be able to eat up comments such as: |
730 /* Handle the pragmas! */ |
761 /* Handle the pragmas! */ |
731 /***************************/ |
762 /***************************/ |
732 |
763 |
733 /* We start off by searching for the pragmas we handle in the lexical parser. */ |
764 /* We start off by searching for the pragmas we handle in the lexical parser. */ |
734 <INITIAL>{file_include_pragma} unput_text(0); yy_push_state(include_beg); |
765 <INITIAL>{file_include_pragma} unput_text(0); yy_push_state(include_beg); |
|
766 |
|
767 /* Pragmas sent to syntax analyser (bison) */ |
|
768 {disable_code_generation_pragma} return disable_code_generation_pragma_token; |
|
769 {enable_code_generation_pragma} return enable_code_generation_pragma_token; |
|
770 <body_state>{disable_code_generation_pragma} return disable_code_generation_pragma_token; |
|
771 <body_state>{enable_code_generation_pragma} return enable_code_generation_pragma_token; |
735 |
772 |
736 /* Any other pragma we find, we just pass it up to the syntax parser... */ |
773 /* Any other pragma we find, we just pass it up to the syntax parser... */ |
737 /* Note that the <body_state> state is exclusive, so we have to include it here too. */ |
774 /* Note that the <body_state> state is exclusive, so we have to include it here too. */ |
738 {pragma} {/* return the pragmma without the enclosing '{' and '}' */ |
775 {pragma} {/* return the pragmma without the enclosing '{' and '}' */ |
739 yytext[strlen(yytext)-1] = '\0'; |
776 yytext[strlen(yytext)-1] = '\0'; |
967 /***************************************/ |
1004 /***************************************/ |
968 /* NOTE: pragmas are handled right at the beginning... */ |
1005 /* NOTE: pragmas are handled right at the beginning... */ |
969 |
1006 |
970 <INITIAL,config_state,decl_state,st_state,sfc_state,task_init_state,sfc_qualifier_state>{st_whitespace_no_pragma} /* Eat any whitespace */ |
1007 <INITIAL,config_state,decl_state,st_state,sfc_state,task_init_state,sfc_qualifier_state>{st_whitespace_no_pragma} /* Eat any whitespace */ |
971 <il_state>{il_whitespace_no_pragma} /* Eat any whitespace */ |
1008 <il_state>{il_whitespace_no_pragma} /* Eat any whitespace */ |
|
1009 |
972 |
1010 |
973 |
1011 |
974 /*****************************************/ |
1012 /*****************************************/ |
975 /* B.1.1 Letters, digits and identifiers */ |
1013 /* B.1.1 Letters, digits and identifiers */ |
976 /*****************************************/ |
1014 /*****************************************/ |