I haven't used javaCC for several years. Now (year 2024) that I try it again with the lates tools, "Compile with javacc" just does nothing: no *.java files generated, no error messages, just, plain, nothing.
It is possible to call javacc on my (old) *.jj and *.jjt files and I get my *.java files (where eclipse complains later about some errors, very probably to the fact that many things have changed by the time they were working, some 5-15 years ago).
One additional thing to mention is that the standard example file MyNewGrammer.jjt produces (via shell command "javacc MyNewGrammer.jjt") java files where jjtThis is unknown ... straight from the automatically generated jjt).
I also dimly remember that *.jjt was converted to *.jj first, but I see no trace of it now.
What's wrong? Are there currently know issues or common pitfalls?
helper@gg$ javac -version
javac 11.0.24
helper@gg$ javacc -version
7.0.12
helper@gg$ javacc -verbose MyNewGrammar.jjt
Java Compiler Compiler Version 7.0.12 (Parser Generator)
(type "javacc" with no arguments for help)
Warning: Bad option "-verbose" will be ignored.
Reading from file MyNewGrammar.jjt . . .
File "TokenMgrError.java" is being rebuilt.
File "ParseException.java" is being rebuilt.
File "Token.java" is being rebuilt.
File "SimpleCharStream.java" is being rebuilt.
Parser generated successfully.
helper@gg$
The tools I use are those coming with eclipse and what I got from "The Marketplace" searching for JavaCC.
Eclipse tells me it was "JavaCC Eclipse Plug-in Feature" (version 1.6.1):
JavaCC & JTB editor, views, nature and builder which process .jj, .jjt & .jtb files and integrate with Eclipse's incremental build system, for head (and headless) builds. Must be installed for head builds (ie with the UI). Will allow headless builds. Compatible with Eclipse Neon+ (4.6+) and Java 1.8+. Embeds some versions of JavaCC and JTB jars.
Linux: Ubuntu
Please install your own JDK, recommended version: JDK 17.
https://www.eclipse.org/downloads/packages/release/2024-06/r
UNZIP eclipse-jee-2024-06-R-linux-gtk-x86_64.tar.gz
cd eclipse-jee-2024-06-R-linux-gtk-x86_64/eclipse
./eclipse
I use an empty directory WK as the workspace directory.
/your-path/WK
Search
-> Find
, Input: JavaCC
Find: JavaCC Eclipse Plug-in 1.6.1
Click Button: Install
Finish
Trust Selected
Trust Selected
Software Updates
Restart Now
Menu File
-> New
- Other
Select a wizard
Next
MyJavaCCExample
JavaSE-17
Finish
Open Associated Perspective ?
Open Perspective
MyJavaCCExample
-> New
-> Folder
outputJavaCC
Finish
MyJavaCCExample
-> Properties
Java Build Path
-> Source
Add Folder...
Source Folder Selection
OK
Apply and Close
JavaCC -> Javacc options
17
Browse...
Open
JavaCC options change
Do you want to rebuild the project for options changes to take effect ?
Yes
module-info.java
MyJavaCCExample
-> src
-> module-info.java
Delete
MyJavaCCExample
-> src
-> New
-> File
Create New File
calculator.jj
Finish
Use Browser Open https://github.com/gammasoft/gammalang/blob/master/calculator.jj
LICENSE: MIT license
Copy the file content of calculator.jj
to our project file calculator.jj
Please note that the JavaCC Console
is executed automatically.
MyJavaCCExample
-> outputJavaCC
-> (default package)
Based on the contents of calculator.jj
, Calculator.java
and other files are automatically generated.
MyJavaCCExample
-> outputJavaCC
-> Calculator.java
Run As
-> Java Application
or
MyJavaCCExample
-> outputJavaCC
-> Calculator.java
Run As
-> Run Configurations
Left Tree: Java Application
Right Part:
Name: Calculator
Project: MyJavaCCExample
Main class: Calculator
Click Button: Run
In Console:
Input: 11 + 22
Then Press Enter Key
Then show 33.0