0
中獲得一個規則的許多實例我正在使用JISON(http://zaach.github.io/jison),並且正在學習。我遇到了一個問題,解析器停下來,並且沒有超過第一場比賽;我認爲。這裏是我的語法定義:我如何在JISON
/* lexical grammar */
%lex
%%
\n\s{4} return 'INDENT'
\n+ return 'NL'
[\s\t]+ /* ignore whitespace */
"(" return 'PAREN_OPEN'
")" return 'PAREN_CLOSE'
"AND"|"OR" return 'LOGIC'
"=="|"!=" return 'OPERATOR'
">="|"<="|">"|"<" return 'OPERATOR'
"IN"|"NOTIN" return 'OPERATOR'
"IF" return 'START'
"true"|"false" return 'VALUE'
[0-9]+("."[0-9]+)?\b return 'VALUE'
\"[^"]+\" return 'VALUE'
[a-zA-Z][_a-zA-Z0-9]+ return 'IDENTIFIER'
<<EOF>> return 'EOF'
. return 'INVALID'
/lex
/* language grammar */
%start set
%%
action
: INDENT IDENTIFIER VALUE
{$$ = [$2, $3];}
;
body
: action
| body action
{$$ = [$1, $2];}
;
condition
: group
| relation
| condition LOGIC relation
{$$ = [$1, $2, $3];}
;
end: NL|EOF;
group
: PAREN_OPEN condition PAREN_CLOSE
{$$ = {conditions: $2};}
;
relation
: IDENTIFIER OPERATOR VALUE
{$$ = [$1, $2, $3];}
;
rule
: START condition body NL
{$$ = {
conditions: $2,
statements: $3
};}
;
set
: rule
{return $1;}
| set rule
{return [$1, $2];}
;
...和我的樣本輸入:
IF Love > "Hate"
Live "life"
IF Evil < "Good"
Be "Happy"
我希望在我出現的「AST」是越來越兩個條目,但我只得到了第一個。任何幫助將不勝感激。