The text to be parsed has such examples of commands relating to file system
infile abc*.txt
list abc*ff.txt
where abc*.txt is like the general wildcard argument for shell commands.
However, there is also mathematical expression like:
x=a*b
A common expression rule (in yacc file) is like:
expression:
expression '+' expression { $$ = $1 + $3; }
| expression '-' expression { $$ = $1 - $3; }
| expression '*' expression { $$ = $1 * $3; }
;
The * is used as multiply operator.
And a rule to recognize token IDENTIFIER with * is as:
[A-Za-z][A-Za-z0-9_\.\*]* {
yylval.strval = strdup(yytext); return IDENTIFIER; }
For syntax relating to file system commands like infile or list, as the one at the beginning, the following token will be taken as IDENTIFIER, and might has * as a wildcard to match filenames.
But for an expression like
x = a*b
This should be an expression, but in above lex rule, a*b will be seen as a IDENTIFIER. And it becomes assign value of an identifier a*b to x.
How can I keep the grammar rule of expression and add the wildcard filename in lex or yacc?