本文整理汇总了C#中Antlr3.Tool.GrammarAST.GetChild方法的典型用法代码示例。如果您正苦于以下问题:C# GrammarAST.GetChild方法的具体用法?C# GrammarAST.GetChild怎么用?C# GrammarAST.GetChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr3.Tool.GrammarAST
的用法示例。
在下文中一共展示了GrammarAST.GetChild方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: StripLeftRecursion
public void StripLeftRecursion(GrammarAST altAST)
{
GrammarAST rref = (GrammarAST)altAST.GetChild(0);
if (rref.Type == ANTLRParser.RULE_REF && rref.Text.Equals(ruleName))
{
// remove rule ref
altAST.DeleteChild(0);
// reset index so it prints properly
GrammarAST newFirstChild = (GrammarAST)altAST.GetChild(0);
altAST.TokenStartIndex = newFirstChild.TokenStartIndex;
}
}
示例4: TrackTokenRule
protected override void TrackTokenRule( GrammarAST t,
GrammarAST modifier,
GrammarAST block )
{
// imported token names might exist, only add if new
if ( grammar.type == GrammarType.Lexer || grammar.type == GrammarType.Combined )
{
if (Rule.GetRuleType(t.Text) == RuleType.Parser)
{
return;
}
if ( t.Text.Equals( Grammar.ArtificialTokensRuleName ) )
{
// don't add Tokens rule
return;
}
// track all lexer rules so we can look for token refs w/o
// associated lexer rules.
grammar.composite.LexerRules.Add( t.Text );
int existing = grammar.GetTokenType( t.Text );
if ( existing == Label.INVALID )
{
_tokens[t.Text] = Unassigned;
}
// look for "<TOKEN> : <literal> ;" pattern
// (can have optional action last)
if ( block.HasSameTreeStructure( charAlias ) ||
block.HasSameTreeStructure( stringAlias ) ||
block.HasSameTreeStructure( charAlias2 ) ||
block.HasSameTreeStructure( stringAlias2 ) )
{
tokenRuleDefs.Add( t.Text );
/*
Grammar parent = grammar.composite.getDelegator(grammar);
boolean importedByParserOrCombined =
parent!=null &&
(parent.type==GrammarType.Lexer||parent.type==GrammarType.Parser);
*/
if ( grammar.type == GrammarType.Combined || grammar.type == GrammarType.Lexer )
{
// only call this rule an alias if combined or lexer
Alias( t, (GrammarAST)block.GetChild( 0 ).GetChild( 0 ) );
}
}
}
// else error
}
示例5: TrackAltsWithRewrites
/** Track which rules have rewrite rules. Pass in the ALT node
* for the alt so we can check for problems when output=template,
* rewrite=true, and grammar type is tree parser.
*/
public virtual void TrackAltsWithRewrites( GrammarAST altAST, int outerAltNum )
{
if ( grammar.type == GrammarType.TreeParser &&
grammar.BuildTemplate &&
grammar.GetOption( "rewrite" ) != null &&
grammar.GetOption( "rewrite" ).Equals( "true" )
)
{
GrammarAST firstElementAST = (GrammarAST)altAST.GetChild( 0 );
grammar.sanity.EnsureAltIsSimpleNodeOrTree( altAST,
firstElementAST,
outerAltNum );
}
altsWithRewrites[outerAltNum] = true;
}
示例6: AddRule
public void AddRule(GrammarAST grammarTree, GrammarAST t)
{
GrammarAST p = null;
for (int i = 0; i < grammarTree.ChildCount; i++)
{
p = (GrammarAST)grammarTree.GetChild(i);
if (p == null || p.Type == ANTLRParser.RULE || p.Type == ANTLRParser.PREC_RULE)
break;
}
if (p != null)
grammarTree.AddChild(t);
}
示例7: HandleElementPlusAssign
private void HandleElementPlusAssign(GrammarAST id, GrammarAST elementStart)
{
if (elementStart.Type == ANTLRParser.ROOT || elementStart.Type == ANTLRParser.BANG)
{
elementStart = (GrammarAST)elementStart.GetChild(0);
}
if (elementStart.Type == RULE_REF)
{
grammar.DefineRuleListLabel(currentRuleName, id.Token, elementStart);
}
else if (elementStart.Type == WILDCARD && grammar.type == GrammarType.TreeParser)
{
grammar.DefineWildcardTreeListLabel(currentRuleName, id.Token, elementStart);
}
else
{
grammar.DefineTokenListLabel(currentRuleName, id.Token, elementStart);
}
}
示例8: HandleDotLoop
private void HandleDotLoop(GrammarAST start)
{
GrammarAST block = (GrammarAST)start.GetChild(0);
IDictionary<string, object> opts = new Dictionary<string, object>();
opts["greedy"] = "false";
if (grammar.type != GrammarType.Lexer)
{
// parser grammars assume k=1 for .* loops otherwise they (analysis?) look til EOF!
opts["k"] = 1;
}
block.SetOptions(grammar, opts);
}
示例9: EnsureAltIsSimpleNodeOrTree
/** Rules in tree grammar that use -> rewrites and are spitting out
* templates via output=template and then use rewrite=true must only
* use -> on alts that are simple nodes or trees or single rule refs
* that match either nodes or trees. The altAST is the ALT node
* for an ALT. Verify that its first child is simple. Must be either
* ( ALT ^( A B ) <end-of-alt> ) or ( ALT A <end-of-alt> ) or
* other element.
*
* Ignore predicates in front and labels.
*/
public virtual void EnsureAltIsSimpleNodeOrTree( GrammarAST altAST,
GrammarAST elementAST,
int outerAltNum )
{
if ( IsValidSimpleElementNode( elementAST ) )
{
GrammarAST next = (GrammarAST)elementAST.getNextSibling();
if ( !IsNextNonActionElementEOA( next ) )
{
ErrorManager.GrammarWarning( ErrorManager.MSG_REWRITE_FOR_MULTI_ELEMENT_ALT,
grammar,
next.Token,
outerAltNum );
}
return;
}
switch ( elementAST.Type )
{
case ANTLRParser.ASSIGN: // labels ok on non-rule refs
case ANTLRParser.PLUS_ASSIGN:
if ( IsValidSimpleElementNode( (GrammarAST)elementAST.GetChild( 1 ) ) )
{
return;
}
break;
case ANTLRParser.ACTION: // skip past actions
case ANTLRParser.SEMPRED:
case ANTLRParser.SYN_SEMPRED:
case ANTLRParser.BACKTRACK_SEMPRED:
case ANTLRParser.GATED_SEMPRED:
EnsureAltIsSimpleNodeOrTree( altAST,
(GrammarAST)elementAST.getNextSibling(),
outerAltNum );
return;
}
ErrorManager.GrammarWarning( ErrorManager.MSG_REWRITE_FOR_MULTI_ELEMENT_ALT,
grammar,
elementAST.Token,
outerAltNum );
}
示例10: GetChildrenForDupTree
static IEnumerable<GrammarAST> GetChildrenForDupTree( GrammarAST t )
{
for ( int i = 0; i < t.ChildCount; i++ )
{
GrammarAST child = (GrammarAST)t.GetChild( i );
int ttype = child.Type;
if ( ttype == ANTLRParser.REWRITE )
{
continue;
}
else if ( ttype == ANTLRParser.BANG || ttype == ANTLRParser.ROOT )
{
foreach ( GrammarAST subchild in GetChildrenForDupTree( child ) )
yield return subchild;
}
else
{
yield return child;
}
}
}