我试图用只有两个结构(hello
语句和fun
块定义)来解析一种非常幼稚的缩进敏感语言。
hello
hello
fun
hello
hello
hello
为了做到这一点,我用 Irony 编写了以下语法:
public class NaiveIndent : Grammar
{
public NaiveIndent()
: base(true) // CaseSensitive
{
var myexp = ToTerm("hello");
var fun = ToTerm("fun");
var statementList = new NonTerminal("statementList");
var statement = new NonTerminal("statement");
var block = new NonTerminal("block");
statementList.Rule = MakePlusRule(statementList, NewLineStar, statement);
statement.Rule = (myexp | block) + NewLine;
block.Rule = fun + NewLine + Indent + statementList + Dedent;
Root = statementList;
LanguageFlags = LanguageFlags.NewLineBeforeEOF;
}
}
然而,解析样本失败并出现错误(4,3) Syntax error, expected: INDENT
谁能指出我做错了什么?