示例#1
0
 public override void Init(GrammarData grammarData)
 {
     base.Init(grammarData);
     if (!string.IsNullOrEmpty(NodeCaptionTemplate))
     {
         ConvertNodeCaptionTemplate();
     }
     if (TokenPreviewHint != null)
     {
         TokenPreviewHint.Init(grammarData);
     }
 }
        public ConflictGrammarWithHintsOnTerms()
          : base(true)
        {
            var name = new IdentifierTerminal("id");

            var stmt = new NonTerminal("Statement");
            var stmtList = new NonTerminal("StatementList");
            var fieldModifier = new NonTerminal("fieldModifier");
            var propModifier = new NonTerminal("propModifier");
            var methodModifier = new NonTerminal("methodModifier");
            var fieldModifierList = new NonTerminal("fieldModifierList");
            var propModifierList = new NonTerminal("propModifierList");
            var methodModifierList = new NonTerminal("methodModifierList");
            var fieldDef = new NonTerminal("fieldDef");
            var propDef = new NonTerminal("propDef");
            var methodDef = new NonTerminal("methodDef");

            //Rules
            this.Root = stmtList;
            stmtList.Rule = MakePlusRule(stmtList, stmt);
            stmt.Rule = fieldDef | propDef | methodDef;
            fieldDef.Rule = fieldModifierList + name + name + ";";
            propDef.Rule = propModifierList + name + name + "{" + "}";
            methodDef.Rule = methodModifierList + name + name + "(" + ")" + "{" + "}";
            fieldModifierList.Rule = MakeStarRule(fieldModifierList, fieldModifier);
            propModifierList.Rule = MakeStarRule(propModifierList, propModifier);
            methodModifierList.Rule = MakeStarRule(methodModifierList, methodModifier);

            fieldModifier.Rule = ToTerm("public") | "private" | "readonly" | "volatile";
            propModifier.Rule = ToTerm("public") | "private" | "readonly" | "override";
            methodModifier.Rule = ToTerm("public") | "private" | "override";

            // conflict resolution
            var fieldHint = new TokenPreviewHint(PreferredActionType.Reduce, thisSymbol: ";", comesBefore: new string[] { "(", "{" });
            fieldModifier.AddHintToAll(fieldHint);
            fieldModifierList.AddHintToAll(fieldHint);
            var propHint = new TokenPreviewHint(PreferredActionType.Reduce, thisSymbol: "{", comesBefore: new string[] { ";", "(" });
            propModifier.AddHintToAll(propHint);
            propModifierList.AddHintToAll(propHint);

            MarkReservedWords("public", "private", "readonly", "volatile", "override");
        }
示例#3
0
 public TokenPreviewHint Shiftif(Terminal first)
 {
     return(TokenPreviewHint = new TokenPreviewHint(ParserActionType.Shift, first));
 }
示例#4
0
 public TokenPreviewHint Reduceif(Terminal first)
 {
     return(TokenPreviewHint = new TokenPreviewHint(ParserActionType.Reduce, first));
 }
示例#5
0
 public TokenPreviewHint ShiftIf(string first)
 {
     return(TokenPreviewHint = new TokenPreviewHint(ParserActionType.Shift, first));
 }
示例#6
0
 public TokenPreviewHint ReduceIf(string first)
 {
     return(TokenPreviewHint = new TokenPreviewHint(ParserActionType.Reduce, first));
 }