我试图解析一个非常天真的缩进敏感语言,只有两个构造(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
有人能指出我做错了吗?
答案 0 :(得分:0)