Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
package {

	import flash.display.Sprite;

	import org.antlr.runtime.*;

	public class AntlrActionScriptTest extends Sprite {
		public function AntlrActionScriptTest ( ):void {
			var lexer:TLexer = new TLexer ( new ANTLRStringStream ( input ) );
			var tokens:CommonTokenStream = CommonTokenStream ( lexer );

			var parser:TParser = TParser ( tokens );
			parser.entry_rule ( );
 		}
	}
}

If you want to access the tokens types in your code, you'll have to import and access them from the lexer or parser module (e.g. TLexer.EOF, TLexer.IDENTIFIER):

...

Code Block
package {

	import flash.display.Sprite;

	import org.antlr.runtime.*;

	public class AntlrActionScriptTreeWalkerTest extends Sprite {
		public function AntlrActionScriptTest ( ):void {
			var lexer:TLexer = new TLexer ( new ANTLRStringStream ( input ) );
			var tokens:CommonTokenStream = CommonTokenStream ( lexer );

			var parser:TParser = TParser ( tokens );
			var r:ParserRuleReturnScope = parser.entry_rule ( );

			// This is the root of the AST.
			var root:Tree = r.tree;

			var nodes:CommonTreeNodeStream = CommonTreeNodeStream ( root );
			nodes.tokenStream = tokens;
			var walker:TWalker = new TWalker ( nodes );
			walker.entry_rule ( );

 		}
	}
}

API documentation

...