本文整理汇总了C#中antlr.collections.AST类的典型用法代码示例。如果您正苦于以下问题:C# antlr.collections.AST类的具体用法?C# antlr.collections.AST怎么用?C# antlr.collections.AST使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
antlr.collections.AST类属于命名空间,在下文中一共展示了antlr.collections.AST类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: doTreeAction
public static void doTreeAction(string f, AST t, string[] tokenNames)
{
if (t == null)
return ;
if (showTree)
{
BaseAST.setVerboseStringConversion(true, tokenNames);
ASTFactory factory = new ASTFactory();
AST r = factory.create(0, "AST ROOT");
r.setFirstChild(t);
ASTFrame frame = new ASTFrame("Java AST", r);
frame.ShowDialog();
//frame.Visible = true;
// System.out.println(t.toStringList());
}
JavaTreeParser tparse = new JavaTreeParser();
try
{
tparse.compilationUnit(t);
// System.out.println("successful walk of result AST for "+f);
}
catch (RecognitionException e)
{
Console.Error.WriteLine(e.Message);
Console.Error.WriteLine(e.StackTrace);
}
}
开发者ID:BackupTheBerlios,项目名称:ccl-plugin,代码行数:27,代码来源:Main.cs
示例2: resetState
public virtual void resetState()
{
traceDepth = 0;
returnAST = null;
retTree_ = null;
inputState.reset();
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:7,代码来源:TreeParser.cs
示例3: match
protected internal virtual void match(AST t, int ttype)
{
//System.out.println("match("+ttype+"); cursor is "+t);
if (t == null || t == ASTNULL || t.Type != ttype)
{
throw new MismatchedTokenException(getTokenNames(), t, ttype, false);
}
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:8,代码来源:TreeParser.cs
示例4: advanceChildToEnd
public AST child; // current child to which siblings are added
/*Make sure that child is the last sibling */
public void advanceChildToEnd()
{
if (child != null)
{
while (child.getNextSibling() != null)
{
child = child.getNextSibling();
}
}
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:13,代码来源:ASTPair.cs
示例5: ASTFrame
public ASTFrame(string title, AST rootAST) : this()
{
this.Text = title;
JTreeASTPanel treePanel = new JTreeASTPanel(new TreeViewEventHandler(tree_AfterSelect), rootAST);
this.Controls.Add(treePanel);
treePanel.Location= new Point(5, 5);
treePanel.Dock=DockStyle.Fill;
treePanel.Anchor=AnchorStyles.Top|AnchorStyles.Left;
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:10,代码来源:ASTFrame.cs
示例6: visit
public void visit(AST node)
{
// Flatten this level of the tree if it has no children
bool flatten = /*true*/ false;
AST node2;
for (node2 = node; node2 != null; node2 = node2.getNextSibling())
{
if (node2.getFirstChild() != null)
{
flatten = false;
break;
}
}
for (node2 = node; node2 != null; node2 = node2.getNextSibling())
{
if (!flatten || node2 == node)
{
tabs();
}
if (node2.getText() == null)
{
Console.Out.Write("nil");
}
else
{
Console.Out.Write(node2.getText());
}
Console.Out.Write(" [" + node2.Type + "] ");
if (flatten)
{
Console.Out.Write(" ");
}
else
{
Console.Out.WriteLine("");
}
if (node2.getFirstChild() != null)
{
level++;
visit(node2.getFirstChild());
level--;
}
}
if (flatten)
{
Console.Out.WriteLine("");
}
}
开发者ID:BackupTheBerlios,项目名称:ccl-plugin,代码行数:53,代码来源:DumpASTVisitor.cs
示例7: MismatchedTokenException
// Expected token / not token
public MismatchedTokenException(string[] tokenNames_, AST node_, int expecting_, bool matchNot) :
base("Mismatched Token", "<AST>", -1, -1)
{
tokenNames = tokenNames_;
node = node_;
if (node_ == null)
{
tokenText = "<empty tree>";
}
else
{
tokenText = node_.ToString();
}
mismatchType = matchNot ? TokenTypeEnum.NotTokenType : TokenTypeEnum.TokenType;
expecting = expecting_;
}
开发者ID:logikonline,项目名称:DDay.iCal,代码行数:17,代码来源:MismatchedTokenException.cs
示例8: addChild
/*Add a node to the end of the child list for this node */
public virtual void addChild(AST node)
{
if (node == null)
return ;
BaseAST t = this.down;
if (t != null)
{
while (t.right != null)
{
t = t.right;
}
t.right = (BaseAST) node;
}
else
{
this.down = (BaseAST) node;
}
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:19,代码来源:BaseAST.cs
示例9: doWorkForFindAll
private void doWorkForFindAll(ArrayList v, AST target, bool partialMatch)
{
AST sibling;
// Start walking sibling lists, looking for matches.
//siblingWalk:
for (sibling = this; sibling != null; sibling = sibling.getNextSibling())
{
if ((partialMatch && sibling.EqualsTreePartial(target)) || (!partialMatch && sibling.EqualsTree(target)))
{
v.Add(sibling);
}
// regardless of match or not, check any children for matches
if (sibling.getFirstChild() != null)
{
((BaseAST) sibling.getFirstChild()).doWorkForFindAll(v, target, partialMatch);
}
}
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:19,代码来源:BaseAST.cs
示例10: ifAtom
//throws RecognitionException
public Object ifAtom(AST _t)
{
Object value=null;
antlr.stringtemplate.language.StringTemplateAST ifAtom_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
try { // for error handling
value=expr(_t);
_t = retTree_;
}
catch (RecognitionException ex)
{
reportError(ex);
if (null != _t)
{
_t = _t.getNextSibling();
}
}
retTree_ = _t;
return value;
}
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:22,代码来源:ActionEvaluator.cs
示例11: makeASTRoot
/// <summary>
/// Make an AST the root of current AST.
/// </summary>
/// <param name="currentAST"></param>
/// <param name="root"></param>
public virtual void makeASTRoot(ASTPair currentAST, AST root)
{
if (root != null)
{
// Add the current root as a child of new root
root.addChild(currentAST.root);
// The new current child is the last sibling of the old root
currentAST.child = currentAST.root;
currentAST.advanceChildToEnd();
// Set the new root
currentAST.root = root;
}
}
开发者ID:BackupTheBerlios,项目名称:ccl-plugin,代码行数:18,代码来源:ASTFactory.cs
示例12: make
/// <summary>
/// Make a tree from a list of nodes. The first element in the
/// array is the root. If the root is null, then the tree is
/// a simple list not a tree. Handles null children nodes correctly.
/// For example, build(a, b, null, c) yields tree (a b c). build(null,a,b)
/// yields tree (nil a b).
/// </summary>
/// <param name="nodes">List of Nodes.</param>
/// <returns>AST Node tree.</returns>
public virtual AST make(AST[] nodes)
{
if (nodes == null || nodes.Length == 0)
return null;
AST root = nodes[0];
AST tail = null;
if (root != null)
{
root.setFirstChild(null); // don't leave any old pointers set
}
// link in children;
for (int i = 1; i < nodes.Length; i++)
{
if (nodes[i] == null)
continue;
// ignore null nodes
if (root == null)
{
// Set the root and set it up for a flat list
root = (tail = nodes[i]);
}
else if (tail == null)
{
root.setFirstChild(nodes[i]);
tail = root.getFirstChild();
}
else
{
tail.setNextSibling(nodes[i]);
tail = tail.getNextSibling();
}
// Chase tail to last sibling
while (tail.getNextSibling() != null)
{
tail = tail.getNextSibling();
}
}
return root;
}
开发者ID:BackupTheBerlios,项目名称:ccl-plugin,代码行数:48,代码来源:ASTFactory.cs
示例13: dupTree
/// <summary>
/// Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
/// </summary>
/// <param name="t">Root of AST Node tree.</param>
/// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
public virtual AST dupTree(AST t)
{
AST result = dup(t); // make copy of root
// copy all children of root.
if (t != null)
{
result.setFirstChild(dupList(t.getFirstChild()));
}
return result;
}
开发者ID:BackupTheBerlios,项目名称:ccl-plugin,代码行数:15,代码来源:ASTFactory.cs
示例14: dupList
/// <summary>
/// Duplicate AST Node tree rooted at specified AST node and all of it's siblings.
/// </summary>
/// <param name="t">Root of AST Node tree.</param>
/// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
public virtual AST dupList(AST t)
{
AST result = dupTree(t); // if t == null, then result==null
AST nt = result;
while (t != null)
{
// for each sibling of the root
t = t.getNextSibling();
nt.setNextSibling(dupTree(t)); // dup each subtree, building new tree
nt = nt.getNextSibling();
}
return result;
}
开发者ID:BackupTheBerlios,项目名称:ccl-plugin,代码行数:18,代码来源:ASTFactory.cs
示例15: singleTemplateArg
//throws RecognitionException
public void singleTemplateArg(AST _t,
StringTemplate embedded, IDictionary argumentContext
)
{
antlr.stringtemplate.language.StringTemplateAST singleTemplateArg_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
Object e = null;
try { // for error handling
AST __t41 = _t;
antlr.stringtemplate.language.StringTemplateAST tmp22_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
match((AST)_t,SINGLEVALUEARG);
_t = _t.getFirstChild();
e=expr(_t);
_t = retTree_;
_t = __t41;
_t = _t.getNextSibling();
if ( e!=null ) {
String soleArgName = null;
// find the sole defined formal argument for embedded
bool error = false;
IDictionary formalArgs = embedded.getFormalArguments();
if ( formalArgs!=null )
{
ICollection argNames = formalArgs.Keys;
if ( argNames.Count==1 )
{
string[] argNamesArray = new string[argNames.Count];
argNames.CopyTo(argNamesArray,0);
soleArgName = argNamesArray[0];
//System.out.println("sole formal arg of "+embedded.getName()+" is "+soleArgName);
}
else
{
error=true;
}
}
else
{
error=true;
}
if ( error )
{
self.error("template "+embedded.getName()+
" must have exactly one formal arg in template context "+
self.getEnclosingInstanceStackString());
}
else
{
self.rawSetArgumentAttribute(embedded,argumentContext,soleArgName,e);
}
}
}
catch (RecognitionException ex)
{
reportError(ex);
if (null != _t)
{
_t = _t.getNextSibling();
}
}
retTree_ = _t;
}
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:66,代码来源:ActionEvaluator.cs
示例16: create
/// <summary>
/// Creates and initializes a new AST node using the specified AST Node instance.
/// the new AST node is initialized with the specified Token type ID and string.
/// The <see cref="System.Type"/> used for creating this new AST node is
/// determined solely by <c>aNode</c>.
/// The AST Node type must have a default/parameterless constructor.
/// </summary>
/// <param name="aNode">AST Node instance to be used for creating the new AST Node.</param>
/// <returns>An initialized AST node object.</returns>
public virtual AST create(AST aNode)
{
AST newNode;
if (aNode == null)
newNode = null;
else
{
newNode = createFromNodeTypeObject(aNode.GetType());
newNode.initialize(aNode);
}
return newNode;
}
开发者ID:BackupTheBerlios,项目名称:ccl-plugin,代码行数:22,代码来源:ASTFactory.cs
示例17: value
//throws RecognitionException
public String value(AST _t)
{
String s ;
AST value_AST_in = (AST)_t;
AST l = null;
AST ql = null;
AST v = null;
String variable = null;
s = null;
try { // for error handling
if (null == _t)
_t = ASTNULL;
switch ( _t.Type )
{
case LITERAL:
{
l = _t;
match(_t,LITERAL);
_t = _t.getNextSibling();
s = l.getText();
break;
}
case QLITERAL:
{
ql = _t;
match(_t,QLITERAL);
_t = _t.getNextSibling();
s = ql.getText();
break;
}
case VAR:
{
AST tmp18_AST_in = _t;
match(_t,VAR);
_t = _t.getNextSibling();
AST tmp19_AST_in = _t;
match(_t,LPAREN);
_t = _t.getNextSibling();
v = _t;
match(_t,LITERAL);
_t = _t.getNextSibling();
AST tmp20_AST_in = _t;
match(_t,RPAREN);
_t = _t.getNextSibling();
variable = v.getText();
s = (String) environment.get(variable);
if (s == null) {
throw new RecognitionException("unrecognized variable " + variable);
}
break;
}
default:
{
throw new NoViableAltException(_t);
}
}
}
catch (RecognitionException ex)
{
reportError(ex);
if (null != _t)
{
_t = _t.getNextSibling();
}
}
retTree_ = _t;
return s ;
}
开发者ID:yinghau76,项目名称:filewalk,代码行数:80,代码来源:MyTreeParser.cs
示例18: ifCondition
//throws RecognitionException
public bool ifCondition(AST _t)
{
bool value=false;
antlr.stringtemplate.language.StringTemplateAST ifCondition_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
Object a=null, b=null;
try { // for error handling
if (null == _t)
_t = ASTNULL;
switch ( _t.Type )
{
case APPLY:
case MULTI_APPLY:
case INCLUDE:
case VALUE:
case FUNCTION:
case LIST:
case PLUS:
case DOT:
case ID:
case ANONYMOUS_TEMPLATE:
case STRING:
case INT:
{
a=ifAtom(_t);
_t = retTree_;
value = chunk.testAttributeTrue(a);
break;
}
case NOT:
{
AST __t30 = _t;
antlr.stringtemplate.language.StringTemplateAST tmp18_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
match((AST)_t,NOT);
_t = _t.getFirstChild();
a=ifAtom(_t);
_t = retTree_;
_t = __t30;
_t = _t.getNextSibling();
value = !chunk.testAttributeTrue(a);
break;
}
default:
{
throw new NoViableAltException(_t);
}
}
}
catch (RecognitionException ex)
{
reportError(ex);
if (null != _t)
{
_t = _t.getNextSibling();
}
}
retTree_ = _t;
return value;
}
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:62,代码来源:ActionEvaluator.cs
示例19: list
//throws RecognitionException
/** create a new list of expressions as a new multi-value attribute */
public Object list(AST _t)
{
Object value=null;
antlr.stringtemplate.language.StringTemplateAST list_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
Object e = null;
IList elements = new ArrayList();
value = new CatIterator(elements);
try { // for error handling
AST __t6 = _t;
antlr.stringtemplate.language.StringTemplateAST tmp14_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
match((AST)_t,LIST);
_t = _t.getFirstChild();
{ // ( ... )+
int _cnt8=0;
for (;;)
{
if (_t == null)
_t = ASTNULL;
if ((tokenSet_0_.member(_t.Type)))
{
e=expr(_t);
_t = retTree_;
if ( e!=null ) {
e = ASTExpr.convertAnythingToIterator(e);
elements.Add(e);
}
}
else
{
if (_cnt8 >= 1) { goto _loop8_breakloop; } else { throw new NoViableAltException(_t);; }
}
_cnt8++;
}
_loop8_breakloop: ;
} // ( ... )+
_t = __t6;
_t = _t.getNextSibling();
}
catch (RecognitionException ex)
{
reportError(ex);
if (null != _t)
{
_t = _t.getNextSibling();
}
}
retTree_ = _t;
return value;
}
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:57,代码来源:ActionEvaluator.cs
示例20: traceOut
public virtual void traceOut(string rname, AST t)
{
traceIndent();
Console.Out.WriteLine("< " + rname + "(" + ((t != null) ? t.ToString() : "null") + ")" + ((inputState.guessing > 0) ? " [guessing]" : ""));
traceDepth--;
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:6,代码来源:TreeParser.cs
注:本文中的antlr.collections.AST类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论