私は行の内容を抽出し、その行の入力がbisonから拒否されたときにそれらを印刷しようとします。 私はこれらの提案を再現しようとしています:http://archive.oreilly.com/pub/a/linux/excerpts/9780596155971/error-reporting-recovery.htmlしかし、入力が拒否された場合、拒否された行の代わりに次の行が印刷されますが、行番号は正しく表示されます。フレックス/バイソンの行内容の抽出に失敗する
フレックス:
%{
#include <stdio.h>
#include "parser.tab.h"
int line_number = 0;
char linebuf[500];
%}
...
%%
\n.* { ++line_number; strncpy(linebuf, yytext+1, sizeof(linebuf)); /* save the next line */
yyless(1); /* give back all but the \n to rescan */
}
%%
バイソン:バイソンから文法エラーを含むものからprintd次のライン上のアプローチを拒否された入力に
%{
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "parser.tab.h"
extern int yylex(void);
extern int line_number;
extern char line_contents[500];
void yyerror(char const *s);
%}
...
%%
int main(){
if(yyparse() == 0)
printf("Accepted\n");
else
printf("Syntax error in line %d: %s\n" line_number, linebuf);
...
。
input:
result = function //(semicolon expected)
else
出力:
Syntax error in line 1: else
私は、字句規則\n.*
またはyytext+1
は、次の行に出力を駆動するが、字句のルールが正しいものであると考えていますか?