好的,这就是交易。
用我的语言,我有一些命令,比如说
XYZ 3 5
GGB 8 9
HDH 8783 33
在我的 Lex 文件中
XYZ { return XYZ; }
GGB { return GGB; }
HDH { return HDH; }
[0-9]+ { yylval.ival = atoi(yytext); return NUMBER; }
\n { return EOL; }
在我的 yacc 文件中
start : commands
;
commands : command
| command EOL commands
;
command : xyz
| ggb
| hdh
;
xyz : XYZ NUMBER NUMBER { /* Do something with the numbers */ }
;
etc. etc. etc. etc.
我的问题是,我怎样才能得到整个文本
XYZ 3 5
GGB 8 9
HDH 8783 33
在返回数字的同时进入命令?
另外,当我的 Lex 返回 STRING [0-9a-zA-Z]+,并且我想验证它的长度时,我应该这样做吗
rule: STRING STRING { if (strlen($1) < 5 ) /* Do some shit else error */ }
或者实际上在我的 Lex 中有一个令牌,它根据长度返回不同的令牌?