gpt4 book ai didi

c# - Irony 语法规范错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:45:59 24 4
gpt4 key购买 nike

我是 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;
}
}

最佳答案

已修复!

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

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;

关于c# - Irony 语法规范错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15314176/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com