flex と bison を使用して、自分のマシン (ubuntu 10.10) で正常にビルドおよび実行される小さなアセンブラーを作成しました。他の誰かが arch Linux でビルドしようとしており、flex をインストールすると、ルールに一致しない別の lex.yy.c が生成されます。どちらのバージョンも同じバージョンを報告しますlex 2.5.35
が、パターンを理解していない Mac OSX 上の私のものと別の flex との違いをすでに見た(?i
ので、そのバージョン文字列をあまり信頼していません。
私はリモート マシンにアクセスできないので、リモート ユーザーに生成させた lex --debug の出力を見ています。
私のアセンブラの完全なソースは、こちらの github にあります。
これが私のルールの抜粋です。
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; }
入力行の例を次に示します。
SET A, 0x30 ; 7c01 0030
リモート レクサーは、{symbol}:
ではなく A のルールに一致してい{gpreg}|{xreg}
ます。これは、 up top*
の定義にワイルドカードがあるためでしょうか? symbol
リモートではなくフレックスでこれが機能するのはなぜですか?
私のローカル(良い)ビルドからの --debug 出力:
--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 ("
")
そして、問題のあるリモート ビルドからのデバッグ出力 (yacc の苦情を含む)。'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 ("
")
これをどのように修正すればよいですか? また、さまざまなフレックス バージョンで予想される同様の落とし穴はありますか?