Ich habe einen sehr einfachen Parser in Jison geschrieben, aber es scheint ein S/R Konflikt in dieser Grammatik zu sein:Resolving S/R Konflikte in 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;
Es ist beabsichtigt, Dokumente wie diese zu analysieren ein, die aus 4 Aussagen besteht:
first: this is a sentence
second: this is another sentence
something: more words here another: more words here
aber als ich beabsichtigt nicht funktioniert:
Conflicts encountered:
Resolve S/R conflict (shift by default.)
(1,10, 2,4) -> 1,10
Ist es möglich, r Lösen Sie diesen Konflikt, ohne die Syntax der Sprache zu ändern, die analysiert wird?