5 /* This file contains the function mylex() which recognizes the following
8 * C_INSTR - 'C_loc', 'C_lol', etc.
9 * DEF_C_INSTR - 'C_loe..', 'C_ste..', '..icon, '..fcon', etc
10 * CONDITION - C-expression, for example: '$1 == 481'
12 * CALL - C-style functioncall, for example: 'error( 17)'
13 * ASSEM_INSTR - C-style string, for example: '"mov r0, (r1)"'
15 * ERROR - An error occured in one of the tokens.
17 * If the input matches non of these tokens the next character will be returned.
19 * Besides mylex() the following variable is exported :
21 * char yytext[]; - Contains the string representation of the current
23 * char *next; - Points to the first free position in yytext[].
28 char yytext[YYTEXT], /* string-buffer for the token */
29 *next; /* points to the first free posistion in yytext[] */
35 int CD_pos = FALSE; /* 'CD_pos' is used as a flag to signal if it is
36 * possible to match a CONDITION or DEFAULT-token at
37 * this moment. Thus mylex() knows about the grammar
39 * This flag is needed because CALL is a subset of
42 int CALL_pos = FALSE; /* Needed to distinguish between
43 * C_INSTR CONDITION and CALL
47 static char skip_space();
54 static int special = FALSE; /* rule with conditions + default ? */
57 c = *next++ = skip_space();
59 case EOF : next = yytext;
62 case '"' : read_string();
65 case '.' : c = scanc();
67 if ( c != '.') { /* Just a plain '.', not something like
77 case ';' : return( ';');
79 case '=' : if ( arrow()) {
86 case 'd' : if ( CD_pos && _default()) {
93 /* Possible tokens at this place : CONDITION, CALL, C_INSTR,
118 if ( is_DEF_C_INSTR( yytext)) {
120 return( DEF_C_INSTR);
122 if ( is_C_INSTR( yytext)) {
134 if ( is_DEF_C_INSTR( yytext)) {
136 return( DEF_C_INSTR);
148 static int isletter( c)
151 return( isalpha( c) || isdigit( c) || c == '_');
154 static char skip_space()
158 while ( isspace( c = scanc()))
164 /* first character has been read */
169 /* match something like "mov r0, (r1)".
170 * strip the double quotes off! Inside a string, the character '"' must
171 * be preceded by a '\'.
175 while( ( *next = scanc()) != '"' || *(next-1) == '\\')
179 int arrow() /* '==>' */
181 if ( ( *next++ = scanc()) == '=')
182 if ( ( *next++ = scanc()) == '>')
191 int _default() /* 'default' */
195 if ( ( *next++ = scanc()) == 'e')
196 if ( ( *next++ = scanc()) == 'f')
197 if ( ( *next++ = scanc()) == 'a')
198 if ( ( *next++ = scanc()) == 'u')
199 if ( ( *next++ = scanc()) == 'l')
200 if ( ( *next++ = scanc()) == 't')
201 if ( !isletter( c = skip_space())) {
226 while ( isletter( c = scanc()))
236 switch( *next++ = scanc()) {
251 /* A CONDITION is followed by '==>'
255 switch ( *next++ = scanc()) {
258 case '=' : if ( arrow()) {
273 if ( *str == 'C' && *(str+1) == '_') /* C_xxx */
282 /* yytext[] contains either '..[letter]*' ( 2 dots possibly followed by an
283 * identifer) * or '[letter]+' ( just an identifier)
284 * Try to match something like 'C_loe..' or '..icon'
287 if ( *str == '.' && *(str+1) == '.')
288 return( next > yytext+1);
290 if ( ( *next++ = scanc()) == '.')
291 if ( ( *next++ = scanc()) == '.')
292 return( next > yytext+1);