当前位置: 首页>>代码示例>>C#>>正文


C# Tool.GrammarAST类代码示例

本文整理汇总了C#中Antlr3.Tool.GrammarAST的典型用法代码示例。如果您正苦于以下问题:C# GrammarAST类的具体用法?C# GrammarAST怎么用?C# GrammarAST使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GrammarAST类属于Antlr3.Tool命名空间,在下文中一共展示了GrammarAST类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ActionAnalysisLexer

 public ActionAnalysisLexer(Grammar grammar, string ruleName, GrammarAST actionAST)
     : this(new ANTLRStringStream(actionAST.Token.Text))
 {
     this.grammar = grammar;
     this.enclosingRule = grammar.GetLocallyDefinedRule(ruleName);
     this.actionToken = actionAST.Token;
     this.outerAltNum = actionAST.outerAltNum;
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:8,代码来源:ActionAnalysisLexerHelper.cs

示例2: TrackInlineAction

 protected void TrackInlineAction( GrammarAST actionAST )
 {
     Rule r = grammar.GetRule( currentRuleName );
     if ( r != null )
     {
         r.TrackInlineAction( actionAST );
     }
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:8,代码来源:DefineGrammarItemsWalkerHelper.cs

示例3: CountAltsForBlock

        public int CountAltsForBlock(GrammarAST t)
        {
            int n = 0;
            for ( int i = 0; i < t.ChildCount; i++ )
            {
                if ( t.GetChild( i ).Type == ALT )
                    n++;
            }

            return n;
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:11,代码来源:ANTLRTreePrinterHelper.cs

示例4: BlockHasSynPred

        public static bool BlockHasSynPred(GrammarAST blockAST)
        {
            GrammarAST c1 = blockAST.FindFirstType(ANTLRParser.SYN_SEMPRED);
            GrammarAST c2 = blockAST.FindFirstType(ANTLRParser.BACKTRACK_SEMPRED);
            if (c1 != null || c2 != null)
                return true;
            //		System.out.println(blockAST.enclosingRuleName+
            //						   " "+blockAST.getLine()+":"+blockAST.getColumn()+" no preds AST="+blockAST.toStringTree());

            return false;
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:11,代码来源:GrammarReport.cs

示例5: TernaryAlt

        /** Convert e ? e : e  ->  ? e : e_[nextPrec] */
        public override void TernaryAlt(GrammarAST altTree, GrammarAST rewriteTree, int alt)
        {
            altTree = GrammarAST.DupTree(altTree);
            rewriteTree = GrammarAST.DupTree(rewriteTree);

            StripSynPred(altTree);
            StripLeftRecursion(altTree);

            int nextPrec = NextPrecedence(alt);
            StringTemplate refST = recRuleTemplates.GetInstanceOf("recRuleRef");
            refST.SetAttribute("ruleName", ruleName);
            refST.SetAttribute("arg", nextPrec);
            altTree = ReplaceLastRuleRef(altTree, refST.Render());

            string altText = Text(altTree);
            altText = altText.Trim();
            altText += "{}"; // add empty alt to prevent pred hoisting
            StringTemplate nameST = recRuleTemplates.GetInstanceOf("recRuleName");
            nameST.SetAttribute("ruleName", ruleName);
            rewriteTree = ReplaceRuleRefs(rewriteTree, "$" + nameST.Render());
            string rewriteText = Text(rewriteTree);
            ternaryAlts.Add(alt, altText + (rewriteText != null ? " " + rewriteText : ""));
            //System.out.println("ternaryAlt " + alt + ": " + altText + ", rewrite=" + rewriteText);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:25,代码来源:LeftRecursiveRuleAnalyzer.cs

示例6: StripSynPred

 public void StripSynPred(GrammarAST altAST)
 {
     GrammarAST t = (GrammarAST)altAST.GetChild(0);
     if (t.Type == ANTLRParser.BACKTRACK_SEMPRED ||
          t.Type == ANTLRParser.SYNPRED ||
          t.Type == ANTLRParser.SYN_SEMPRED)
     {
         altAST.DeleteChild(0);
     }
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:10,代码来源:LeftRecursiveRuleAnalyzer.cs

示例7: SetTokenPrec

        public override void SetTokenPrec(GrammarAST t, int alt)
        {
            int ttype = g.GetTokenType(t.Text);
            //tokenToPrec.Add(ttype, alt);
            tokenToPrec[ttype] = alt;

            ASSOC assoc = ASSOC.left;
            if (t.terminalOptions != null)
            {
                object o;
                t.terminalOptions.TryGetValue("assoc", out o);
                string a = o as string;
                if (a != null)
                {
                    if (a.Equals(ASSOC.right.ToString()))
                    {
                        assoc = ASSOC.right;
                    }
                    else
                    {
                        ErrorManager.Error(ErrorManager.MSG_ILLEGAL_OPTION_VALUE, "assoc", assoc);
                    }
                }
            }

            ASSOC currentAssociativity;
            if (altAssociativity.TryGetValue(alt, out currentAssociativity))
            {
                if (currentAssociativity != assoc)
                    ErrorManager.Error(ErrorManager.MSG_ALL_OPS_NEED_SAME_ASSOC, alt);
            }
            else
            {
                altAssociativity.Add(alt, assoc);
            }

            //System.out.println("op " + alt + ": " + t.getText()+", assoc="+assoc);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:38,代码来源:LeftRecursiveRuleAnalyzer.cs

示例8: ReplaceLastRuleRef

 public GrammarAST ReplaceLastRuleRef(GrammarAST t, string name)
 {
     if (t == null)
         return null;
     GrammarAST last = null;
     foreach (GrammarAST rref in t.FindAllType(RULE_REF))
     {
         last = rref;
     }
     if (last != null && last.Text.Equals(ruleName))
         last.Text = name;
     return t;
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:13,代码来源:LeftRecursiveRuleAnalyzer.cs

示例9: Alias

        protected override void Alias( GrammarAST t, GrammarAST s )
        {
            string tokenID = t.Text;
            string literal = s.Text;
            string prevAliasLiteralID;
            _aliasesReverseIndex.TryGetValue(literal, out prevAliasLiteralID);
            if ( prevAliasLiteralID != null )
            { // we've seen this literal before
                if ( tokenID.Equals( prevAliasLiteralID ) )
                {
                    // duplicate but identical alias; might be tokens {A='a'} and
                    // lexer rule A : 'a' ;  Is ok, just return
                    return;
                }

                // give error unless both are rules (ok if one is in tokens section)
                if ( !( tokenRuleDefs.Contains( tokenID ) && tokenRuleDefs.Contains( prevAliasLiteralID ) ) )
                {
                    // don't allow alias if A='a' in tokens section and B : 'a'; is rule.
                    // Allow if both are rules.  Will get DFA nondeterminism error later.
                    ErrorManager.GrammarError( ErrorManager.MSG_TOKEN_ALIAS_CONFLICT,
                                              grammar,
                                              t.Token,
                                              tokenID + "=" + literal,
                                              prevAliasLiteralID );
                }
                return; // don't do the alias
            }
            int existingLiteralType = grammar.GetTokenType( literal );
            if ( existingLiteralType != Label.INVALID )
            {
                // we've seen this before from a tokenVocab most likely
                // don't assign a new token type; use existingLiteralType.
                _tokens[tokenID] = existingLiteralType;
            }
            string prevAliasTokenID;
            _aliases.TryGetValue(tokenID, out prevAliasTokenID);
            if ( prevAliasTokenID != null )
            {
                ErrorManager.GrammarError( ErrorManager.MSG_TOKEN_ALIAS_REASSIGNMENT,
                                          grammar,
                                          t.Token,
                                          tokenID + "=" + literal,
                                          prevAliasTokenID );
                return; // don't do the alias
            }
            _aliases[tokenID] = literal;
            _aliasesReverseIndex[literal] = tokenID;
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:49,代码来源:AssignTokenTypesBehavior.cs

示例10: TrackToken

 protected override void TrackToken( GrammarAST t )
 {
     // imported token names might exist, only add if new
     // Might have ';'=4 in vocab import and SEMI=';'. Avoid
     // setting to UNASSIGNED if we have loaded ';'/SEMI
     if ( grammar.GetTokenType( t.Text ) == Label.INVALID &&
          !_tokens.ContainsKey( t.Text ) )
     {
         _tokens[t.Text] = Unassigned;
     }
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:11,代码来源:AssignTokenTypesBehavior.cs

示例11: BuildSemanticPredicate

 /** Build what amounts to an epsilon transition with a semantic
  *  predicate action.  The pred is a pointer into the AST of
  *  the SEMPRED token.
  */
 public virtual StateCluster BuildSemanticPredicate( GrammarAST pred )
 {
     // don't count syn preds
     if ( !pred.Text.StartsWith( Grammar.SynpredRulePrefix, StringComparison.OrdinalIgnoreCase ) )
     {
         _nfa.Grammar.numberOfSemanticPredicates++;
     }
     NFAState left = NewState();
     NFAState right = NewState();
     Transition e = new Transition( new PredicateLabel( pred ), right );
     left.AddTransition( e );
     StateCluster g = new StateCluster( left, right );
     return g;
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:18,代码来源:NFAFactory.cs

示例12: BuildCharLiteralAtom

 /** From char 'c' build StateCluster o-intValue(c)->o
  */
 public virtual StateCluster BuildCharLiteralAtom( GrammarAST charLiteralAST )
 {
     int c = Grammar.GetCharValueFromGrammarCharLiteral( charLiteralAST.Text );
     return BuildAtom( c, charLiteralAST );
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:7,代码来源:NFAFactory.cs

示例13: BuildAtom

 public virtual StateCluster BuildAtom( GrammarAST atomAST )
 {
     int tokenType = _nfa.Grammar.GetTokenType( atomAST.Text );
     return BuildAtom( tokenType, atomAST );
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:5,代码来源:NFAFactory.cs

示例14: BuildAction

 /** Build what amounts to an epsilon transition with an action.
  *  The action goes into NFA though it is ignored during analysis.
  *  It slows things down a bit, but I must ignore predicates after
  *  having seen an action (5-5-2008).
  */
 public virtual StateCluster BuildAction( GrammarAST action )
 {
     NFAState left = NewState();
     NFAState right = NewState();
     Transition e = new Transition( new ActionLabel( action ), right );
     left.AddTransition( e );
     return new StateCluster( left, right );
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:13,代码来源:NFAFactory.cs

示例15: TernaryAlt

 public virtual void TernaryAlt(GrammarAST altTree, GrammarAST rewriteTree, int alt)
 {
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:3,代码来源:LeftRecursiveRuleWalker.g3.cs


注:本文中的Antlr3.Tool.GrammarAST类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。