我已經寫在jison一個非常簡單的解析器,但似乎是在這個語法中的S/R衝突:在jison
/* lexical grammar */
%lex
%%
\s+ /* skip whitespace */
":" return ':'
"." return '.'
[a-zA-Z_][a-zA-Z0-9_]* return 'IDENTIFIER'
<<EOF>> return 'EOF'
. return 'INVALID'
/lex
/* operator associations and precedence */
%start expressions
%% /* language grammar */
expressions
: statements EOF
{return $1;}
;
statements: statements statement {$$ = [$1].concat($2);} | statement {$$ =
[$1];};
statement:
IDENTIFIER ":" grammar_and {[$$ = ["grammar_rule",$1,$3]]};
grammar_and:
grammar_and IDENTIFIER {$$= [$1,$2]} | IDENTIFIER;
它旨在解析這樣的文件一個,其中包括4點聲明:
first: this is a sentence
second: this is another sentence
something: more words here another: more words here
但正如我預期它不工作:
Conflicts encountered:
Resolve S/R conflict (shift by default.)
(1,10, 2,4) -> 1,10
是否有可能與r在不修改正在分析的語言的語法的情況下解決衝突?