代码着色器错误

本文关键字:错误 代码 | 更新日期: 2023-09-27 18:30:10

我正在尝试编写语法来解析像这样的语句

b.a := 7;

我的语法如下所示

public class STGrammar : InterpretedLanguageGrammar
{
    public STGrammar() : base(caseSensitive: false)
    {
        LanguageFlags = LanguageFlags.CreateAst;
        # region Terminals
        Terminal n = new NumberLiteral("number");
        Terminal v = new IdentifierTerminal("variable");
        KeyTerm assignment = ToTerm(":=");
        KeyTerm left_paren = ToTerm("(");
        KeyTerm right_paren = ToTerm(")");
        KeyTerm terminate = ToTerm(";");
        KeyTerm left_sq = ToTerm("[");
        KeyTerm right_sq = ToTerm("]");
        KeyTerm dot = ToTerm(".");
        #endregion Terminals
        #region Nonterminals
        NonTerminal actionBlock = new NonTerminal("actionBlock", typeof(ActionBlock));
        NonTerminal assignmentExpr = new NonTerminal("assignmentExpr", typeof(AssignmentStNode));
        NonTerminal arrayOrStruct = new NonTerminal("arrayOrStruct", typeof(ArrayNode));
        NonTerminal arrayOrStructRHS = new NonTerminal("arrayOrStructRHS", typeof(AstNode));
        NonTerminal arrayOrStructRHSs = new NonTerminal("arrayOrStructRHSs");
        NonTerminal comparatorExp = new NonTerminal("comparatorExpression", typeof(ExpressionNode));
        #endregion Nonterminals
        #region BNFRules
        actionBlock.Rule =
            assignmentExpr + terminate
            | arrayOrStruct + terminate
            ;
        assignmentExpr.Rule =
            v + assignment + v
            | v + assignment + n
            | arrayOrStruct + assignment + v
            | v + assignment + arrayOrStruct
            | arrayOrStruct + assignment + arrayOrStruct
            | arrayOrStruct + assignment + n
            ;
        arrayOrStruct.Rule =
            v + arrayOrStructRHSs
            ;
        arrayOrStructRHS.Rule = 
            "." + v 
            | "[" + v + "]"
            ;
        arrayOrStructRHSs.Rule =
            MakePlusRule(arrayOrStructRHSs, arrayOrStructRHS)
            ;
        this.Root = actionBlock;
        #endregion BNFRules
        MarkPunctuation(",", ";", "[", "]", ")", "(", "..", ".");
        RegisterBracePair("(", ")");
    }
}

当我试图解析时,它工作得很好

b := 7;

即将到来的错误是Fatal Error in code colorizer. Colorizing had been disabled.即使我注释掉

LanguageFlags = LanguageFlags.CreateAst;

错误仍然存在。详细错误为

System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
  Source=Irony
  StackTrace:
       at Irony.Ast.AstBuilder.BuildAst(ParseTreeNode parseNode) in C:'Sreeja'downloads'Irony_2013_03_10'Irony'Ast'AstBuilder.cs:line 97
       at Irony.Ast.AstBuilder.BuildAst(ParseTreeNode parseNode) in C:'Sreeja'downloads'Irony_2013_03_10'Irony'Ast'AstBuilder.cs:line 86
       at Irony.Ast.AstBuilder.BuildAst(ParseTreeNode parseNode) in C:'Sreeja'downloads'Irony_2013_03_10'Irony'Ast'AstBuilder.cs:line 86
       at Irony.Ast.AstBuilder.BuildAst(ParseTreeNode parseNode) in C:'Sreeja'downloads'Irony_2013_03_10'Irony'Ast'AstBuilder.cs:line 86
       at Irony.Ast.AstBuilder.BuildAst(ParseTree parseTree) in C:'Sreeja'downloads'Irony_2013_03_10'Irony'Ast'AstBuilder.cs:line 38
       at Irony.Interpreter.InterpretedLanguageGrammar.BuildAst(LanguageData language, ParseTree parseTree) in C:'Sreeja'downloads'Irony_2013_03_10'Irony.Interpreter'InterpretedLanguageGrammar.cs:line 60
       at Irony.Parsing.Parser.Parse(String sourceText, String fileName) in C:'Sreeja'downloads'Irony_2013_03_10'Irony'Parsing'Parser'Parser.cs:line 88
       at Irony.GrammarExplorer.fmGrammarExplorer.ParseSample() in C:'Sreeja'downloads'Irony_2013_03_10'Irony.GrammarExplorer'fmGrammarExplorer.cs:line 348
       at Irony.GrammarExplorer.fmGrammarExplorer.btnParse_Click(Object sender, EventArgs e) in C:'Sreeja'downloads'Irony_2013_03_10'Irony.GrammarExplorer'fmGrammarExplorer.cs:line 507
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  InnerException: 

有人能帮我解决这个错误吗?我使用的是Irony_2013_03_10版本。

代码着色器错误

应该为所有非终结符(瞬态终结符除外)添加Ast节点类型。在每个Ast节点类中,重写Init()和DoEvaluate()函数。详细信息可以在本讨论中找到