本文整理汇总了C#中Antlr4.Tool.Ast.GrammarAST类的典型用法代码示例。如果您正苦于以下问题:C# GrammarAST类的具体用法?C# GrammarAST怎么用?C# GrammarAST使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GrammarAST类属于Antlr4.Tool.Ast命名空间,在下文中一共展示了GrammarAST类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: LabelElementPair
public LabelElementPair(Grammar g, GrammarAST label, GrammarAST element, int labelOp)
{
this.label = label;
this.element = element;
// compute general case for label type
if (element.GetFirstDescendantWithType(tokenTypeForTokens) != null)
{
if (labelOp == ANTLRParser.ASSIGN)
type = LabelType.TOKEN_LABEL;
else
type = LabelType.TOKEN_LIST_LABEL;
}
else if (element.GetFirstDescendantWithType(ANTLRParser.RULE_REF) != null)
{
if (labelOp == ANTLRParser.ASSIGN)
type = LabelType.RULE_LABEL;
else
type = LabelType.RULE_LIST_LABEL;
}
// now reset if lexer and string
if (g.IsLexer())
{
if (element.GetFirstDescendantWithType(ANTLRParser.STRING_LITERAL) != null)
{
if (labelOp == ANTLRParser.ASSIGN)
type = LabelType.LEXER_STRING_LABEL;
}
}
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:30,代码来源:LabelElementPair.cs
示例2: Choice
public Choice(OutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
IList<CodeBlockForAlt> alts)
: base(factory, blkOrEbnfRootAST)
{
this.alts = alts;
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:7,代码来源:Choice.cs
示例3: GrammarAST
public GrammarAST(GrammarAST node)
: base(node)
{
this.g = node.g;
this.atnState = node.atnState;
this.textOverride = node.textOverride;
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:7,代码来源:GrammarAST.cs
示例4: Loop
public Loop(OutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
IList<CodeBlockForAlt> alts)
: base(factory, blkOrEbnfRootAST, alts)
{
bool nongreedy = (blkOrEbnfRootAST is QuantifierAST) && !((QuantifierAST)blkOrEbnfRootAST).GetGreedy();
exitAlt = nongreedy ? 1 : alts.Count + 1;
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:8,代码来源:Loop.cs
示例5: ReduceBlocksToSets
public virtual void ReduceBlocksToSets(GrammarAST root)
{
CommonTreeNodeStream nodes = new CommonTreeNodeStream(new GrammarASTAdaptor(), root);
GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
BlockSetTransformer transformer = new BlockSetTransformer(nodes, g);
transformer.TreeAdaptor = adaptor;
transformer.Downup(root);
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:8,代码来源:GrammarTransformPipeline.cs
示例6: SrcOp
protected SrcOp(OutputModelFactory factory, GrammarAST ast)
: base(factory, ast)
{
if (ast != null)
uniqueID = ast.Token.TokenIndex;
enclosingBlock = factory.GetCurrentBlock();
enclosingRuleRunction = factory.GetCurrentRuleFunction();
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:8,代码来源:SrcOp.cs
示例7: AltBlock
// @ModelElement public ThrowNoViableAlt error;
public AltBlock(OutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
IList<CodeBlockForAlt> alts)
: base(factory, blkOrEbnfRootAST, alts)
{
decision = ((BlockStartState)blkOrEbnfRootAST.atnState).decision;
// interp.predict() throws exception
// this.error = new ThrowNoViableAlt(factory, blkOrEbnfRootAST, null);
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:11,代码来源:AltBlock.cs
示例8: TestSetInline
public TestSetInline(OutputModelFactory factory, GrammarAST ast, IntervalSet set, int wordSize)
: base(factory, ast)
{
bitsetWordSize = wordSize;
Bitset[] withZeroOffset = CreateBitsets(factory, set, wordSize, true);
Bitset[] withoutZeroOffset = CreateBitsets(factory, set, wordSize, false);
this.bitsets = withZeroOffset.Length <= withoutZeroOffset.Length ? withZeroOffset : withoutZeroOffset;
this.varName = "_la";
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:9,代码来源:TestSetInline.cs
示例9: DiscoverRule
public override void DiscoverRule(RuleAST rule, GrammarAST ID,
IList<GrammarAST> modifiers, ActionAST arg,
ActionAST returns, GrammarAST thrws,
GrammarAST options, ActionAST locals,
IList<GrammarAST> actions,
GrammarAST block)
{
currentRule = g.GetRule(ID.Text);
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:9,代码来源:SymbolCollector.cs
示例10: RuleRef
public override IList<SrcOp> RuleRef(GrammarAST ID, GrammarAST label, GrammarAST args)
{
InvokeRule invokeOp = new InvokeRule(this, ID, label);
// If no manual label and action refs as token/rule not label, we need to define implicit label
if (controller.NeedsImplicitLabel(ID, invokeOp))
DefineImplicitLabel(ID, invokeOp);
AddToLabelList listLabelOp = GetAddToListOpIfListLabelPresent(invokeOp, label);
return List(invokeOp, listLabelOp);
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:9,代码来源:ParserFactory.cs
示例11: MatchSet
public MatchSet(OutputModelFactory factory, GrammarAST ast)
: base(factory, ast)
{
SetTransition st = (SetTransition)ast.atnState.Transition(0);
int wordSize = factory.GetGenerator().GetTarget().GetInlineTestSetWordSize();
expr = new TestSetInline(factory, null, st.set, wordSize);
Decl.Decl d = new TokenTypeDecl(factory, expr.varName);
factory.GetCurrentRuleFunction().AddLocalDecl(d);
capture = new CaptureNextTokenType(factory, expr.varName);
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:10,代码来源:MatchSet.cs
示例12: ThrowRecognitionException
public ThrowRecognitionException(OutputModelFactory factory, GrammarAST ast, IntervalSet expecting)
: base(factory, ast)
{
//this.decision = ((BlockStartState)ast.ATNState).decision;
grammarLine = ast.Line;
grammarLine = ast.CharPositionInLine;
grammarFile = factory.GetGrammar().fileName;
//this.expecting = factory.createExpectingBitSet(ast, decision, expecting, "error");
// factory.defineBitSet(this.expecting);
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:10,代码来源:ThrowRecognitionException.cs
示例13: StarBlock
public StarBlock(OutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
IList<CodeBlockForAlt> alts)
: base(factory, blkOrEbnfRootAST, alts)
{
loopLabel = factory.GetTarget().GetLoopLabel(blkOrEbnfRootAST);
StarLoopEntryState star = (StarLoopEntryState)blkOrEbnfRootAST.atnState;
loopBackStateNumber = star.loopBackState.stateNumber;
decision = star.decision;
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:10,代码来源:StarBlock.cs
示例14: Sync
// public BitSetDecl expecting;
public Sync(OutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
IntervalSet expecting,
int decision,
string position)
: base(factory, blkOrEbnfRootAST)
{
this.decision = decision;
// this.expecting = factory.createExpectingBitSet(ast, decision, expecting, position);
// factory.defineBitSet(this.expecting);
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:13,代码来源:Sync.cs
示例15: LL1AltBlock
public LL1AltBlock(OutputModelFactory factory, GrammarAST blkAST, IList<CodeBlockForAlt> alts)
: base(factory, blkAST, alts)
{
this.decision = ((DecisionState)blkAST.atnState).decision;
/* Lookahead for each alt 1..n */
IntervalSet[] altLookSets = factory.GetGrammar().decisionLOOK[decision];
altLook = GetAltLookaheadAsStringLists(altLookSets);
IntervalSet expecting = IntervalSet.Or(altLookSets); // combine alt sets
this.error = GetThrowNoViableAlt(factory, blkAST, expecting);
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:12,代码来源:LL1AltBlock.cs
示例16: LL1StarBlockSingleAlt
public LL1StarBlockSingleAlt(OutputModelFactory factory, GrammarAST starRoot, IList<CodeBlockForAlt> alts)
: base(factory, starRoot, alts)
{
StarLoopEntryState star = (StarLoopEntryState)starRoot.atnState;
loopBackStateNumber = star.loopBackState.stateNumber;
this.decision = star.decision;
IntervalSet[] altLookSets = factory.GetGrammar().decisionLOOK[decision];
Debug.Assert(altLookSets.Length == 2);
IntervalSet enterLook = altLookSets[0];
IntervalSet exitLook = altLookSets[1];
loopExpr = AddCodeForLoopLookaheadTempVar(enterLook);
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:13,代码来源:LL1StarBlockSingleAlt.cs
示例17: PlusBlock
public PlusBlock(OutputModelFactory factory,
GrammarAST plusRoot,
IList<CodeBlockForAlt> alts)
: base(factory, plusRoot, alts)
{
BlockAST blkAST = (BlockAST)plusRoot.GetChild(0);
PlusBlockStartState blkStart = (PlusBlockStartState)blkAST.atnState;
PlusLoopbackState loop = blkStart.loopBackState;
stateNumber = blkStart.loopBackState.stateNumber;
blockStartStateNumber = blkStart.stateNumber;
loopBackStateNumber = loop.stateNumber;
this.error = GetThrowNoViableAlt(factory, plusRoot, null);
decision = loop.decision;
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:14,代码来源:PlusBlock.cs
示例18: InvokeRule
public InvokeRule(ParserFactory factory, GrammarAST ast, GrammarAST labelAST)
: base(factory, ast)
{
if (ast.atnState != null)
{
RuleTransition ruleTrans = (RuleTransition)ast.atnState.Transition(0);
stateNumber = ast.atnState.stateNumber;
}
this.name = ast.Text;
Rule r = factory.GetGrammar().GetRule(name);
ctxName = factory.GetTarget().GetRuleFunctionContextStructName(r);
// TODO: move to factory
RuleFunction rf = factory.GetCurrentRuleFunction();
if (labelAST != null)
{
// for x=r, define <rule-context-type> x and list_x
string label = labelAST.Text;
if (labelAST.Parent.Type == ANTLRParser.PLUS_ASSIGN)
{
factory.DefineImplicitLabel(ast, this);
string listLabel = factory.GetTarget().GetListLabel(label);
RuleContextListDecl l = new RuleContextListDecl(factory, listLabel, ctxName);
rf.AddContextDecl(ast.GetAltLabel(), l);
}
else
{
RuleContextDecl d = new RuleContextDecl(factory, label, ctxName);
labels.Add(d);
rf.AddContextDecl(ast.GetAltLabel(), d);
}
}
ActionAST arg = (ActionAST)ast.GetFirstChildWithType(ANTLRParser.ARG_ACTION);
if (arg != null)
{
argExprsChunks = ActionTranslator.TranslateAction(factory, rf, arg.Token, arg);
}
// If action refs rule as rulename not label, we need to define implicit label
if (factory.GetCurrentOuterMostAlt().ruleRefsInActions.ContainsKey(ast.Text))
{
string label = factory.GetTarget().GetImplicitRuleLabel(ast.Text);
RuleContextDecl d = new RuleContextDecl(factory, label, ctxName);
labels.Add(d);
rf.AddContextDecl(ast.GetAltLabel(), d);
}
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:49,代码来源:InvokeRule.cs
示例19: DiscoverRule
public override void DiscoverRule(RuleAST rule, GrammarAST ID,
IList<GrammarAST> modifiers, ActionAST arg,
ActionAST returns, GrammarAST thrws,
GrammarAST options, ActionAST locals,
IList<GrammarAST> actions,
GrammarAST block)
{
int numAlts = block.ChildCount;
Rule r;
if (LeftRecursiveRuleAnalyzer.HasImmediateRecursiveRuleRefs(rule, ID.Text))
{
r = new LeftRecursiveRule(g, ID.Text, rule);
}
else
{
r = new Rule(g, ID.Text, rule, numAlts);
}
rules[r.name] = r;
if (arg != null)
{
r.args = ScopeParser.ParseTypedArgList(arg, arg.Text, g);
r.args.type = AttributeDict.DictType.ARG;
r.args.ast = arg;
arg.resolver = r.alt[currentOuterAltNumber];
}
if (returns != null)
{
r.retvals = ScopeParser.ParseTypedArgList(returns, returns.Text, g);
r.retvals.type = AttributeDict.DictType.RET;
r.retvals.ast = returns;
}
if (locals != null)
{
r.locals = ScopeParser.ParseTypedArgList(locals, locals.Text, g);
r.locals.type = AttributeDict.DictType.LOCAL;
r.locals.ast = locals;
}
foreach (GrammarAST a in actions)
{
// a = ^(AT ID ACTION)
ActionAST action = (ActionAST)a.GetChild(1);
r.namedActions[a.GetChild(0).Text] = action;
action.resolver = r;
}
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:49,代码来源:RuleCollector.cs
示例20: LeftRecursiveRuleAnalyzer
public LeftRecursiveRuleAnalyzer(GrammarAST ruleAST,
AntlrTool tool, string ruleName, string language)
: base(new CommonTreeNodeStream(new GrammarASTAdaptor(ruleAST.Token.InputStream), ruleAST))
{
this.tool = tool;
this.ruleName = ruleName;
this.language = language;
this.tokenStream = ruleAST.g.tokenStream;
if (this.tokenStream == null)
{
throw new InvalidOperationException("grammar must have a token stream");
}
LoadPrecRuleTemplates();
}
开发者ID:sharwell,项目名称:antlr4cs,代码行数:15,代码来源:LeftRecursiveRuleAnalyzer.cs
注:本文中的Antlr4.Tool.Ast.GrammarAST类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论