I wrote a small assembler using flex and bison that builds and runs OK on my machine (ubuntu 10.10). Someone else is trying to create it on arch linux, and installing them flex creates another lex.yy.c, which is an incorrect rule mapping. Both versions report the same lex 2.5.35
version, but I have already seen the differences between mine and another flex on Mac OSX that didn’t type patterns (?i
, so I don’t really believe in this version.
I do not have access to the remote computer, so I'm looking at some lex -debug output that I created for the remote user.
The full source for my assembler on github is here .
Here is a snippet of 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 is an example input line:
SET A, 0x30 ; 7c01 0030
The remote lexer follows the rule {symbol}:
for A instead of {gpreg}|{xreg}
. Could this be because I have a wildcard *
in my definition of symbol
at the top? Why does this work for my flexible and not remote?
The output of -debug 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 debug output (including yacc complaints) from a corrupted remote assembly. Note the other rule corresponding to "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 can I fix this and are there any similar improvements that I can expect with different versions of flex?