...
Code gen templates for operators; assume root=null (not nil), kids=_adaptor.createChildList()nil. This is v3 compatible.
grammar fragment | code |
---|
A | Code Block |
---|
kids_adaptor.addaddChild(_root0, _adaptor.create($A));
if ( root==null && kids.size()>0
) root = _adaptor.nil();
_adaptor.addChildren(rulePostProcessing(root, kids); // A
_localctx.tree = root;
|
|
A B | Code Block |
---|
kids_adaptor.addaddChild(_root0, _adaptor.create($A));
kids_adaptor.addaddChild(_root0, _adaptor.create($B));
if (
root==null && kids.size()>0 ) root = _adaptor.nil();
_adaptor.addChildrenrulePostProcessing(root, kids); // ^(nil A B)
_localctx.tree = root;
|
|
A^ B | Code Block |
---|
root_root0 = root==null ? $A : _adaptor.becomeRoot(root, $A_adaptor.create($A), kids_root0);
kids_adaptor.addaddChild(_root0, _adaptor.create($B));
if ( root==null && kids.size()>0 ) root = _adaptor.nil();
_adaptor.addChildren(rulePostProcessing(root, kids); // ^(A B)
_localctx.tree = root;
|
|
A B^ | Code Block |
---|
kids_adaptor.addaddChild(_root0, _adaptor.create($A));
root_root0 = root==null ? $B : _adaptor.becomeRoot(root, $B_adaptor.create($B), kids_root0);
if ( root==null && kids.size()>0
) root = _adaptor.nil();
_adaptor.addChildren(rulePostProcessing(root, kids); // ^(B A)
_localctx.tree = root;
|
|
A B^ C | Code Block |
---|
kids_adaptor.addaddChild(_root0, _adaptor.create($A));
root_root0 = root==null ? $B : _adaptor.becomeRoot(root, $B, kids(_adaptor.create($B), _root0);
kids_adaptor.addaddChild(_root0, _adaptor.create($C));
if ( root==null && kids.size()>0
) root = _adaptor.nil();
_adaptor.addChildren(rulePostProcessing(root, kids); // ^(B A C)
_localctx.tree = root;
|
|
A B^ C^ D | Code Block |
---|
kids_adaptor.addaddChild(_root0, _adaptor.create($A));
root = root==null ? $B :_root0 = _adaptor.becomeRoot(root, $B_adaptor.create($B), kids_root0);
root_root0 = root==null ? $C : _adaptor.becomeRoot(root, $C_adaptor.create($C), kids_root0);
kids_adaptor.addaddChild(_root0, _adaptor.create($D));
if
( root==null && kids.size()>0 ) root = _adaptor.nil();
_adaptor.createrulePostProcessing(root, kids); // ^(C ^(B A) D)
_localctx.tree = root;
|
|
a^ b | Code Block |
---|
root = root==null ? $a.tree :_root0 = _adaptor.becomeRoot(root, $a.tree, kids_root0);
kids_adaptor.addaddChild(_root0, $b.tree);
if ( root==null && kids.size()>0 ) root = _adaptor.nil();
_adaptor.addChildren(rulePostProcessing(root, kids); // ^(A B)
_localctx.tree = root;
|
|
...
grammar fragment | code |
---|
A -> A | Code Block |
---|
A_it = _track_A_list.iterator(); // iterator of tokens
kids.add(A_it.next()); // let _adaptor.add() create appropriate node
_localctx.tree = _adaptor.create(null, kids); // A
|
|
A -> A A | Code Block |
---|
A_it = _track_A_list.iterator();
kids.add(A_it.next());
kids.add(A_it.next()); // iterator keeps returning A nodes
_localctx.tree = _adaptor.create(root, kids); // ^(nil A A)
|
|
A+ -> A A | Code Block |
---|
A_it = _track_A_list.iterator();
kids.add(A_it.next());
kids.add(A_it.next()); // iterator keeps returning A nodes
_localctx.tree = _adaptor.create(root, kids); // ^(nil A A)
|
|
A B -> ^(A B) | Code Block |
---|
root = _adaptor.create(A_it.next());; // don't create node yet
kids.add(_adaptor.create($B));
_localctx.tree = _adaptor.create(_adaptor.create(root), kids); // ^(nil A AB)
|
|
A+ -> A* | Code Block |
---|
A_it = _track_A_list.iterator();
while (A_it.hasNext()) {
kids.add(_adaptor.create(A_it.next()));
}
_localctx.tree = _adaptor.create(root, kids); // ^(nil A A ... A)
|
|
B A+ -> ^(B A*) | Code Block |
---|
A_it = _track_A_list.iterator();
B_it = _track_B_list.iterator();
root = _adaptor.create(B_it.next());
while (A_it.hasNext()) {
kids.add(_adaptor.create(A_it.next()));
}
_localctx.tree = _adaptor.create(_adaptor.create(root), kids); // ^(B A A ... A)
|
|
A+ -> ^(B A)* | Code Block |
---|
A_it = _track_A_list.iterator();
root_1 = null;
while (A_it.hasNext()) {
root_1 = _adaptor.create(_adaptor.create(B, "B")); // imaginary B root
kids_1.add(_adaptor.create(A_it.next()));
kids.add( _adaptor.create(root_1_adaptor.create(B, "B"), kids_1) ); // ^(B A)
}
_localctx.tree = _adaptor.create(root, kids); // ^(nil ^(B A) ^(B A) ...)
|
|