1

我试图用只有两个结构(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

谁能指出我做错了什么?

4

1 回答 1

0

你检查过他的 Python 示例吗?

http://irony.codeplex.com/SourceControl/latest#Irony.Samples/MiniPython/MiniPython.cs

于 2013-11-03T17:25:14.130 回答