Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

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 = A_it.next(); // don't create node yet
kids.add(_adaptor.create($B));
_localctx.tree = _adaptor.create(_adaptor.create(root), kids); // ^(A B)

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 = 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 = ; // imaginary B root
    kids_1.add(_adaptor.create(A_it.next()));
    kids.add( _adaptor.create(_adaptor.create(B, "B"), kids_1) ); // ^(B A)
}
_localctx.tree = _adaptor.create(root, kids); // ^(nil ^(B A) ^(B A) ...)