2

我是 Irony 的新手(大约 10 年前我在大学学习 BNF),并且开始创建一个准实坐标解析器。

下面是我认为应该能够解析输入 的语法类(完整代码位于https://github.com/spadger/notam-visualiser )

70 50' 44" N 1 13' 66" E

但是,当我在语法资源管理器中运行它时,在 1:4 "expected: space" 处出现语法错误

你能看出我的代码有什么问题吗?

谢谢,

乔恩

[Language("Simple non-real coordinates", "0.1", "A grammar to parse an imaginary coordinate system")]
public class CoordinateGrammar : Grammar
{
    //70 50' 44" N 1 13' 66" E
    public CoordinateGrammar()
    {
        #region Terminals
        var integer = new NumberLiteral("integer", NumberOptions.IntOnly);
        var space = ToTerm(" ", "space");
        var point = ToTerm(".", "dot");
        var lat = ToTerm("N", "north") | ToTerm("S", "south");
        var lon = ToTerm("E", "east") | ToTerm("W", "west");
        var minuteMarker = ToTerm("'", "minute");
        var secondMarker = ToTerm("\"", "second");
        #endregion

        #region Non-Terminals
        var decimalAmount = new NonTerminal("decimalAmount", typeof(DecimalAmountNode));
        var minute = new NonTerminal("minute", typeof(MinuteNode));
        var second = new NonTerminal("second", typeof(SecondNode));

        var imperialMagnitude = new NonTerminal("decimalMagnitude", typeof (ImperialMagnitudeNode));

        var imperialLatitude = new NonTerminal("imperialLatitude", typeof (ImperialLatitudeNode));
        var imperialLongitude = new NonTerminal("imperialLongitude", typeof (ImperialLongitudeNode));
        var imperialCoordinate = new NonTerminal("imperialCoordinate", typeof(ImperialCoordinateNode));
        #endregion

        #region Rules
        decimalAmount.Rule = integer | integer + point + integer;

        minute.Rule = integer + minuteMarker;
        second.Rule = integer + secondMarker;
        imperialMagnitude.Rule = integer + space + minute + space + second;
        imperialLatitude.Rule = imperialMagnitude + space + lat;
        imperialLongitude.Rule = imperialMagnitude + space + lon;
        imperialCoordinate.Rule = imperialLatitude + space + imperialLongitude;
        #endregion

        Root = imperialCoordinate;
    }
}
4

1 回答 1

1

修复!

我手动期待空格,但语法已经配置(默认情况下)将“空格”字符视为空白标记。将非临时规则更新到以下解决了我的问题。

decimalAmount.Rule = integer | integer + point + integer;

minute.Rule = integer + minuteMarker;
second.Rule = integer + secondMarker;
imperialMagnitude.Rule = integer + minute + second;
imperialLatitude.Rule = imperialMagnitude + lat;
imperialLongitude.Rule = imperialMagnitude + lon;
imperialCoordinate.Rule = imperialLatitude + imperialLongitude;
于 2013-03-09T19:03:00.753 回答