684 * However, the standard is inconsistent in that in IL the newline character |
684 * However, the standard is inconsistent in that in IL the newline character |
685 * is considered a token (EOL - end of line). |
685 * is considered a token (EOL - end of line). |
686 * In our implementation we therefore have two definitions of whitespace |
686 * In our implementation we therefore have two definitions of whitespace |
687 * - one for ST, that includes the newline character |
687 * - one for ST, that includes the newline character |
688 * - one for IL without the newline character. |
688 * - one for IL without the newline character. |
689 * Additionally, when parsing IL, the newline character is treated as the EOL token. |
689 * |
690 * This requires the use of a state machine in the lexical parser that needs at least |
690 * IL whitespace is only active while parsing IL code, whereas ST whitespace |
691 * some knowledge of the syntax itself. |
691 * is used in all other circumstances. Additionally, when parsing IL, the newline |
|
692 * character is treated as the EOL token. |
|
693 * The above requires the use of a state machine in the lexical parser to track which |
|
694 * language is being parsed. This requires that the lexical parser (i.e. flex) |
|
695 * have some knowledge of the syntax itself. |
692 * |
696 * |
693 * NOTE: Our definition of whitespace will only work in ASCII! |
697 * NOTE: Our definition of whitespace will only work in ASCII! |
694 * |
698 * |
695 * NOTE: we cannot use |
699 * NOTE: we cannot use |
696 * st_whitespace [:space:]* |
700 * st_whitespace [:space:]* |
700 * not know which characters belong to the set [:space:]), and will |
704 * not know which characters belong to the set [:space:]), and will |
701 * generate a "dangerous trailing context" warning! |
705 * generate a "dangerous trailing context" warning! |
702 * We use this alternative just to stop the flex utility from |
706 * We use this alternative just to stop the flex utility from |
703 * generating the invalid (in this case) warning... |
707 * generating the invalid (in this case) warning... |
704 */ |
708 */ |
|
709 /* NOTE: il_whitespace_char is not currenty used, be we include it for completeness */ |
|
710 st_whitespace_char [ \f\n\r\t\v] |
|
711 il_whitespace_char [ \f\r\t\v] |
705 |
712 |
706 st_whitespace [ \f\n\r\t\v]* |
713 st_whitespace [ \f\n\r\t\v]* |
707 il_whitespace [ \f\r\t\v]* |
714 il_whitespace [ \f\r\t\v]* |
708 |
715 |
709 st_whitespace_or_pragma_or_commentX ({st_whitespace})|({pragma})|({comment}) |
716 st_whitespace_or_pragma_or_commentX ({st_whitespace})|({pragma})|({comment}) |
1162 } |
1169 } |
1163 |
1170 |
1164 |
1171 |
1165 /* vardecl_list_state -> (vardecl_state | body_state | INITIAL) */ |
1172 /* vardecl_list_state -> (vardecl_state | body_state | INITIAL) */ |
1166 <vardecl_list_state>{ |
1173 <vardecl_list_state>{ |
1167 VAR_INPUT | /* execute the next rule's action, i.e. fall-through! */ |
1174 /* NOTE: vardecl_list_state is an exclusive state, i.e. when in this state |
1168 VAR_OUTPUT | |
1175 * default rules do not apply! This means that when in this state identifiers |
1169 VAR_IN_OUT | |
1176 * are not recognised! |
1170 VAR_EXTERNAL | |
1177 * NOTE: Notice that we only change to vardecl_state if the VAR*** is followed by |
1171 VAR_GLOBAL | |
1178 * at least one whitespace. This is to dintinguish the VAR declaration |
1172 VAR_TEMP | |
1179 * from identifiers starting with 'var' (e.g. a variable named 'varint') |
1173 VAR_CONFIG | |
1180 * NOTE: Notice that we cannot use st_whitespace here, as it can legally be empty. |
1174 VAR_ACCESS | |
1181 * We therefore use st_whitespace_char instead. |
1175 VAR unput_text(0); yy_push_state(vardecl_state); |
1182 */ |
1176 |
1183 VAR_INPUT{st_whitespace_char} | /* execute the next rule's action, i.e. fall-through! */ |
1177 END_FUNCTION unput_text(0); BEGIN(INITIAL); |
1184 VAR_OUTPUT{st_whitespace_char} | |
1178 END_FUNCTION_BLOCK unput_text(0); BEGIN(INITIAL); |
1185 VAR_IN_OUT{st_whitespace_char} | |
1179 END_PROGRAM unput_text(0); BEGIN(INITIAL); |
1186 VAR_EXTERNAL{st_whitespace_char} | |
|
1187 VAR_GLOBAL{st_whitespace_char} | |
|
1188 VAR_TEMP{st_whitespace_char} | |
|
1189 VAR_CONFIG{st_whitespace_char} | |
|
1190 VAR_ACCESS{st_whitespace_char} | |
|
1191 VAR{st_whitespace_char} unput_text(0); yy_push_state(vardecl_state); //printf("\nChanging to vardecl_state\n"); |
|
1192 |
|
1193 END_FUNCTION{st_whitespace} unput_text(0); BEGIN(INITIAL); |
|
1194 END_FUNCTION_BLOCK{st_whitespace} unput_text(0); BEGIN(INITIAL); |
|
1195 END_PROGRAM{st_whitespace} unput_text(0); BEGIN(INITIAL); |
1180 |
1196 |
1181 /* NOTE: Handling of whitespace... |
1197 /* NOTE: Handling of whitespace... |
1182 * - Must come __before__ the next rule for any single character '.' |
1198 * - Must come __before__ the next rule for any single character '.' |
1183 * - If the rules were reversed, any whitespace with a single space (' ') |
1199 * - If the rules were reversed, any whitespace with a single space (' ') |
1184 * would be handled by the '.' rule instead of the {whitespace} rule! |
1200 * would be handled by the '.' rule instead of the {whitespace} rule! |