Skip to content
Advertisement

How to call the javacc parser from a simple java class and execute

I am recently learning javacc releated concepts and writing tokens and parser. I was able to write a parser and it works perfectly when I run in the terminal using the commands javacc BusParser.jj //BusParser is file name javac *.java java Calculator //Calculator is parser name //and then type input

Here I am passing an input file when running the parser file

Here I want to know how to call this parser file from the another separate java class, so that we can verify the user input matches with the expected format.

The parser file is given here:

JavaScript

The java class

JavaScript

I tried simply running the java file. It was throwing the below exception exception

Therefore I want to know what the correct way of doing this, that is connecting the parser file and java file. Is there any build configurations to be added if it’s a gradle project?

Further, If using a gradle project, how to compile both javacc and java when entering gradle build and ./gradlew run

Advertisement

Answer

Your grammar requires an EOL after an expression, so try "2+3n".

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement