0
我有以下一段代碼:解析基於壓痕語法(如Python)與YECC
case 1
of 2
3
of 3
4
5
那我的自定義標記生成器轉換爲:
Tokens: [{'case',1},
{integer,1,1},
{eol,1},
{'of',1},
{integer,1,2},
{block,[{integer,1,3}]},
{eol,1},
{'of',1},
{integer,1,3},
{block,[{integer,1,4}]},
{eol,1},
{integer,1,5}]
但後來我不是能夠與以下Yecc解析它:
Nonterminals
grammar
statements statement
case_def case_conditions condition.
Terminals
eol block
integer
case of.
Rootsymbol grammar.
grammar -> statements : '$1'.
statements -> statement eol statements : ['$1'|'$3'].
statements -> statement : ['$1'].
statement -> case_def : '$1'.
statement -> integer : '$1'.
case_def -> 'case' integer case_conditions : ''.
case_conditions -> case_condition case_conditions : ['$1'|'$2'].
case_conditions -> case_condition : ['$1'].
case_condition -> eol 'of' integer block : ''.
它給了我下面的輸出:
["syntax error before: ","5"]
任何幫助真的歡迎,謝謝。