2
votes

Java, ANTLR and Netbeans newbie here.

I have installed a jdk and netbeans. I started a new project on netbeans 6.8 and i have added the antlr-3.2.jar as a library. I also created a lexer and parser class using AntlrWorks. These classes are named ExprParser.java and ExprLexer.java. I copied them into a directory named path-to-netbeans-project/src/parsers.

I have a main file:

package javaapplication2;

import org.antlr.runtime.*;
import parsers.*;

public class Main {

    public static void main(String[] args) throws Exception{

        ANTLRInputStream input = new ANTLRInputStream(System.in);
        ExprLexer lexer = new ExprLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        ExprParser parser = new ExprParser(tokens);
        parser.prog();

    }

}

The application builds fine. The book I'm reading says I should run the program and type in some stuff and then press Ctrl+Z (I'm on windows) to send EOF to the console. Problem is that nothing happens when I press Ctrl+z in the netbeans console. When I run from the command line, ctrl+z works fine.

This is probably WAY too much information, but I can't figure it out. Sorry. Probably not a good idea to learn 3 new technologies at once.

1

1 Answers

2
votes

Instead of:

ANTLRInputStream input = new ANTLRInputStream(System.in);

you could just do:

ANTLRStringStream input = new ANTLRStringStream(args[0]);

where args[0] is the first command line parameter.

Or just:

ANTLRStringStream input = new ANTLRStringStream("your source here");