Search code examples
eclipsejavacc

eclipse "Compile with javacc" just does nothing


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.


Solution

  • OS

    Linux: Ubuntu

    JDK 17

    Please install your own JDK, recommended version: JDK 17.

    Download Eclipse IDE: eclipse-jee-2024-06

    https://www.eclipse.org/downloads/packages/release/2024-06/r

    UNZIP eclipse-jee-2024-06-R-linux-gtk-x86_64.tar.gz

    Run Eclipse

    cd eclipse-jee-2024-06-R-linux-gtk-x86_64/eclipse
    ./eclipse
    

    Config Workspace Directory:

    I use an empty directory WK as the workspace directory.

    /your-path/WK
    

    Install JavaCC Eclipse Plug-in

    Eclipse Marketplace

    003.png

    • Search -> Find , Input: JavaCC

    • Find: JavaCC Eclipse Plug-in 1.6.1

    • Click Button: Install

    license agreement

    004.png

    • I accept the terms of the license agreement
    • Click Button: Finish

    005.png

    • [V] https://eclipse.javacc.source....
    • Click Button: Trust Selected

    006.png

    • [V] x509
    • Click Button: Trust Selected

    007.png

    Software Updates

    • Click Button: Restart Now

    Create Project

    008.png

    Menu File -> New - Other

    009.png

    Select a wizard

    • Java Project
    • Click Button: Next

    010.png

    • Project Name: MyJavaCCExample
    • JRE: JavaSE-17
    • Click Button: Finish

    011.png

    Open Associated Perspective ?

    • Click Button: Open Perspective

    Create New Folder

    012.png

    MyJavaCCExample -> New -> Folder

    013.png

    • Folder Name: outputJavaCC
    • Click Button: Finish

    Add Source Folder

    014.png

    • MyJavaCCExample -> Properties

    015.png

    • Java Build Path -> Source
    • Click Button: Add Folder...

    016.png

    Source Folder Selection

    • outputJavaCC
    • Click Button: OK

    017.png

    • Click Button: Apply and Close

    Config JavaCC

    018.png

    JavaCC -> Javacc options

    • JDK_VERSION: 17
    • OUTPUT_DIRECTORY: Click Button: Browse...

    019.png

    • Select Project MyJavaCCExample/outputJavaCC
    • Click Button Open

    020.png

    021.png

    JavaCC options change

    Do you want to rebuild the project for options changes to take effect ?

    • Click Button: Yes

    Delete module-info.java

    022.png

    • Select MyJavaCCExample -> src -> module-info.java
    • Click Delete

    Create JavaCC jj file

    023.png

    MyJavaCCExample -> src -> New -> File

    024.png

    Create New File

    • File name: calculator.jj
    • Click Button: Finish

    025.png

    Use Browser Open https://github.com/gammasoft/gammalang/blob/master/calculator.jj

    Please note that the JavaCC Console is executed automatically.

    026.png

    MyJavaCCExample -> outputJavaCC -> (default package)

    Based on the contents of calculator.jj, Calculator.java and other files are automatically generated.

    Run Java Application or Run As (Run Configurations)

    027.png

    MyJavaCCExample -> outputJavaCC -> Calculator.java

    • Run As -> Java Application

    or

    028.png

    MyJavaCCExample -> outputJavaCC -> Calculator.java

    • Run As -> Run Configurations

    029.png

    Left Tree: Java Application

    Right Part:

    • Name: Calculator

    • Project: MyJavaCCExample

    • Main class: Calculator

    • Click Button: Run

    Console

    033.png

    In Console:

    Input: 11 + 22 Then Press Enter Key

    Then show 33.0