本文整理汇总了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;
}
示例2: TrackInlineAction
protected void TrackInlineAction( GrammarAST actionAST )
{
Rule r = grammar.GetRule( currentRuleName );
if ( r != null )
{
r.TrackInlineAction( actionAST );
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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 );
}
示例13: BuildAtom
public virtual StateCluster BuildAtom( GrammarAST atomAST )
{
int tokenType = _nfa.Grammar.GetTokenType( atomAST.Text );
return BuildAtom( tokenType, atomAST );
}
示例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 );
}
示例15: TernaryAlt
public virtual void TernaryAlt(GrammarAST altTree, GrammarAST rewriteTree, int alt)
{
}