[antlr-interest] help: scanning multiple lines of input

atif azad atif.azad at hotmail.com
Wed Sep 12 22:19:48 PDT 2007


hello Dears

I am writing an AST grammer . My input file is

add r2;
store r2 r2;

and output i get is like this

tree: (DECL add r2) (DECL store r2 r2)
text r2
type add

But I want output like this

tree: (DECL add r2) (DECL store r2 r2)
text r2
type add
text r2 r2
type store


But in my output as i wrote I only get the parsing of the ist line in 
brackets. I think there is some problöem with my Main fucntion.Can any body 
please tell me what wrong I am doing in my Main class. I would be greatful.
here is my Main class

import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;

public class Main {
	public static void main(String[] args) throws Exception {
		CharStream input = new ANTLRFileStream(args[0]);
		langLexer lex = new langLexer(input);
		CommonTokenStream tokens = new CommonTokenStream(lex);
		langParser parser = new langParser(tokens);
		//LangParser.decl_return r = parser.decl();
		langParser.start_return r = parser.start();
		System.out.println("tree: "+((Tree)r.tree).toStringTree());
		CommonTree r0 = ((CommonTree)r.tree);

		CommonTreeNodeStream nodes = new CommonTreeNodeStream(r0);
		nodes.setTokenStream(tokens);
		langDumpDecl walker = new langDumpDecl(nodes);
		walker.decl();
	}
}


Regards
Azad , Atif

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/



More information about the antlr-interest mailing list