问题
I've written a little assembler using flex and bison, that builds and runs OK on my machine (ubuntu 10.10). Someone else is now trying to build it on arch linux, and their install of flex produces a different lex.yy.c which is mis-matching rules. Both versions report the same lex 2.5.35
version, but I've already seen differences between mine and another flex on Mac OSX which didn't grok (?i
patterns, so I don't trust that version string much.
I don't have access to the remote machine, so I'm looking at some lex --debug output I had the remote user generate.
The full source for my assembler is on github here.
Here's a snippet from my rules:
letter [A-Za-z]
digit [0-9]
hexdigit [0-9a-fA-F]
symbolchar {letter}|[\.$_]
symbol {symbolchar}({symbolchar}|{digit})*
gpreg [ABCXYZIJabcxyzij]
xreg SP|PC|EX|POP|PEEK|PUSH|PICK|sp|pc|ex|pop|peek|push|pick
op2 SET|ADD|SUB|MUL|MLI|DIV|DVI|MOD|MDI|AND|[BX]OR|SH[LR]|ASR|IF[BCENGALU]|ADX|SBX|ST[ID]
op2_lc set|add|sub|mul|mli|div|dvi|mod|mdi|and|[bx]or|sh[lr]|asr|if[bcengalu]|adx|sbx|st[id]
op1 JSR|HCF|INT|RFI|IA[GSQ]|HW[NQI]
op1_lc jsr|hcf|int|rfi|ia[gsq]|hw[nqi]
%%
\.set|\.equ return EQU;
:{symbol} { yylval.string = yytext + 1; return LABEL; }
{symbol}: {
yylval.string = yytext;
yytext[strlen(yytext) - 1] = 0;
return LABEL;
}
0x{hexdigit}+ return get_constant();
{digit}+ return get_constant();
{gpreg}|{xreg} { yylval.integer = str2reg(yytext); return REG; }
{op2}|{op2_lc} { yylval.integer = str2opcode(yytext); return OP2; }
{op1}|{op1_lc} { yylval.integer = str2opcode(yytext); return OP1; }
DAT|dat { return DAT; }
{symbol} { yylval.string = yytext; return SYMBOL; }
Here's an example input line:
SET A, 0x30 ; 7c01 0030
The remote lexer is matching the rule {symbol}:
for A instead of {gpreg}|{xreg}
. Could this be because I have a wildcard *
in my definition of symbol
up top? Why does this work for my flex and not the remote one?
The --debug output from my local (good) build:
--accepting rule at line 52 (" ")
--accepting rule at line 42 ("SET")
--accepting rule at line 52 (" ")
--accepting rule at line 41 ("A")
--accepting rule at line 50 (",")
--accepting rule at line 52 (" ")
--accepting rule at line 39 ("0x30")
--accepting rule at line 52 (" ")
--accepting rule at line 53 ("; 7c01 0030")
--accepting rule at line 50 ("
")
And the debug output (including yacc complaints) from the offending remote build. Note the different rule matched for 'A':
--accepting rule at line 52 (" ")
--accepting rule at line 42 ("SET")
--accepting rule at line 52 (" ")
--accepting rule at line 34 ("A")
line 4: syntax error
line 3: parse error: bad instruction
line 3: parse error: bad instruction
--accepting rule at line 50 (",")
line 3: parse error: bad instruction
--accepting rule at line 52 (" ")
--accepting rule at line 39 ("0x30")
line 3: parse error: bad instruction
--accepting rule at line 52 (" ")
--accepting rule at line 53 ("; 7c01 0030")
--accepting rule at line 50 ("
")
How should I fix this and are there any similar gotchas I can expect with different flex versions out there?
来源:https://stackoverflow.com/questions/10497301/remote-version-of-flex-misinterprets-my-rules