Skip to content

Sample Eclipse project that uses both ANLTR4 and JastAdd for implementing source code program analysis

Notifications You must be signed in to change notification settings

jgaltidor/JSONAntlrAntMavenJastadd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONAntlrAntMavenJastadd

JSONAntlrAntMavenJastadd is a Java application that parses and performs an analysis over JSON files.

This software package is an example Eclipse package that using the following technologies:

  1. ANTLR4
  2. JastAdd
  3. Apache Maven
  4. Apache Ant
  5. ANTLR 4 Maven plugin
  6. Jastadd Eclipse Plugin for syntax highlighting for file types used by the JastAdd system in Eclipse.
  7. ANTLR 4 Eclipse plugin for syntax highlighting of ANTLR 4 grammar files in Eclipse.
  8. JUnit for running Unit tests.

The purpose of this software package is to provide a sample application that demonstrates how to implement a source code analysis by:

  1. Parsing source files with ANTLR4 and creating a concrete syntax tree (CST).
  2. Implementing a program analysis over an abstract syntax tree (AST) using JastAdd.
  3. Implementing a Visitor over an ANTLR4 CST to generate a corresponding JastAdd AST.
  4. Using Maven to hook in the library dependencies for running both ANTLR4 and ANT from the command line and from the Eclipse IDE.
  5. Calling an ANT script from a Maven POM file by following these steps.

Software Dependencies Installation and Troubleshooting Tips

Compiling and using the Eclipse IDE to edit this software package requires installing software dependencies such as Maven. Not all of the dependencies listed above need to be manually installed because some may be included in your Eclipse installation. This section provides instructions for installing the required dependencies.

Eclipse Plugins

Not all of the Eclipse plugin dependencies listed above need to be manually installed because some may be included in your Eclipse installation. Only the following Eclipse plugins probably need to be manually installed.

  1. Jastadd Eclipse Plugin
  2. ANTLR 4 Eclipse plugin

Tips for installing the ANTLR 4 Eclipse plugin are below.

ANTLR 4 Eclipse Plugin depends on Xtext 2.7.3

This Eclipse package has been tested with commit version b5a38e75ef06d0ebd25361c8e9e1cd51062e0287 of the ANTLR 4 Eclipse Plugin. This version depends on version 2.7.3 of Xtext. The following steps installs that version of Xtext:

  1. Download the zip archive of Xtext 2.7.3 from this webpage.
  2. From Eclipse Window, select the downloaded zip file for installing new Eclipse plugins:
  • Help -> Install New Software -> Add... -> Archive...
  • Check Xtext for installation in the popup window and follow the instructions for installation.

ANTLR 4 Maven Plugin Execution with Eclipse Troubleshooting Tip

For some Eclipse installations, the ANTLR 4 Maven Plugin does not execute in Eclipse without performing additional steps not listed on the ANTLR 4 Maven plugin webpage. Specifically, the ANTLR 4 plugin caused Eclipse to print the following error message: Plugin execution not covered by lifecycle configuration. If that error message occurs, this this StackOverflow webpage discusses how to solve that problem.

Building JSONAntlrAntMavenJastadd

To compile this software package, perform the following steps:

  1. Execute the ANT build script build.xml in directory JSONAntlrAntMavenJastadd/src/main/jastadd. This script can be executed two different ways:
    1. From the Eclipse window by, Right-clicking the default target -> Run As -> Ant Build.
    2. From the command line, execute ant from JSONAntlrAntMavenJastadd/src/main/jastadd.
  2. Run the Maven build script pom.xml from directory JSONAntlrAntMavenJastadd with the Maven goal compile. This script can be done two different ways:
    1. From the Eclipse window by, Right-clicking the Project Directory -> Run As -> Maven Build -> Enter goal compile in the Goals: textbox of the pop-up window.
    2. From the command line, execute mvn compile from JSONAntlrAntMavenJastadd.
  3. Right-clicking the Project Directory -> Refresh

Executing the steps above should generate the required source files and compile all of the source files of JSONAntlrAntMavenJastadd.

Single build step

If building JSONAntlrAntMavenJastadd from the command line, executing maven compile is the only step needed to build the application. Unfortunately, running the Maven build script from some Eclipse installations does not in turn run the ANT script JSONAntlrAntMavenJastadd/src/main/jastadd/build.xml, which will cause compilation errors. Specifically, if this ANT script did not execute, executing maven compile will generate an error message that includes the phrase "package AST does not exist". Executing this ANT script runs JastAdd to generate the source files that perform the program analysis. To run this ANT script manually, either execute ant from JSONAntlrAntMavenJastadd/src/main/jastadd or execute this script from the Eclipse window by Right-clicking the default target -> Run As -> Ant Build.

Running Sample Application using JSONAntlrAntMavenJastadd

JUnit tests that utilize the JSONAntlrAntMavenJastadd are in file JSONAntlrAntMavenJastadd/src/test/java/parser/TestJSONParser.java. To execute the JUnit tests in that file from Eclipse: in the Package Explorer, Right-click the file -> Run As -> JUnit Test.

About

Sample Eclipse project that uses both ANLTR4 and JastAdd for implementing source code program analysis

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published