本文整理汇总了C#中Antlr3.Codegen.CodeGenerator.CreateUniqueLabel方法的典型用法代码示例。如果您正苦于以下问题:C# Antlr3.Codegen.CodeGenerator.CreateUniqueLabel方法的具体用法?C# Antlr3.Codegen.CodeGenerator.CreateUniqueLabel怎么用?C# Antlr3.Codegen.CodeGenerator.CreateUniqueLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr3.Codegen.CodeGenerator
的用法示例。
在下文中一共展示了Antlr3.Codegen.CodeGenerator.CreateUniqueLabel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetElementLabel
/** For references to tokens rather than by label such as $ID, we
* need to get the existing label for the ID ref or create a new
* one.
*/
public virtual string GetElementLabel( string refdSymbol,
int outerAltNum,
CodeGenerator generator )
{
GrammarAST uniqueRefAST;
if ( grammar.type != GrammarType.Lexer &&
char.IsUpper( refdSymbol[0] ) )
{
// symbol is a token
IList tokenRefs = GetTokenRefsInAlt( refdSymbol, outerAltNum );
uniqueRefAST = (GrammarAST)tokenRefs[0];
}
else
{
// symbol is a rule
IList ruleRefs = GetRuleRefsInAlt( refdSymbol, outerAltNum );
uniqueRefAST = (GrammarAST)ruleRefs[0];
}
if ( uniqueRefAST.code == null )
{
// no code? must not have gen'd yet; forward ref
return null;
}
string labelName = null;
string existingLabelName =
(string)uniqueRefAST.code.GetAttribute( "label" );
// reuse any label or list label if it exists
if ( existingLabelName != null )
{
labelName = existingLabelName;
}
else
{
// else create new label
labelName = generator.CreateUniqueLabel( refdSymbol );
CommonToken label = new CommonToken( ANTLRParser.ID, labelName );
if ( grammar.type != GrammarType.Lexer &&
char.IsUpper( refdSymbol[0] ) )
{
grammar.DefineTokenRefLabel( Name, label, uniqueRefAST );
}
else
{
grammar.DefineRuleRefLabel( Name, label, uniqueRefAST );
}
uniqueRefAST.code.SetAttribute( "label", labelName );
}
return labelName;
}