像这样定义块
compound_stat
= '{' decl exp_stat '}'
exp_stat
= exp ';'
decl
= decl_specs id ';'
decl_specs
= 'int'/'float'
id
=name:[a-z]+ {return name.join("");}
exp_stat
= left:multiplicative "+" right:exp_stat { right=right+1;return left + right; }
/ multiplicative
multiplicative
= left:primary "*" right:multiplicative { return left * right; }
/ primary
primary
= integer
/id
/ "(" exp_stat:exp_stat ")" { return exp_stat; }
integer "integer"
= digits:[0-9]+ { return parseInt(digits.join(""), 10); }
想要实现 {float a =3;a*3+1;} return 10 我不知道如何在“decl”和“exp_stat”这两个语句中引用 id。谁能分享一个例子?