This is a Spring Boot application that uses JavaCC (Java Compiler Compiler) to parse and evaluate simple arithmetic expressions. The grammar is defined in SimpleArithmetic.jj, and the generated parser is integrated with the Spring Boot framework to expose parsing functionality through a REST API.
- Parse and evaluate arithmetic expressions involving addition, subtraction, multiplication, and division.
- Handle basic syntax errors in expressions.
- Easily extendable grammar using JavaCC.
Before you start, ensure you have the following installed:
- Java JDK 8+
- Maven (for building the Spring Boot project)
- JavaCC (for generating the parser)
- PostgreSQL (if the app interacts with a database, customize accordingly)
-
Clone the repository:
git clone https://github.com/TayssirGh/javacc-demo.git cd simple-arithmetic-parser -
Install JavaCC if you don't have it yet. Download it from the official JavaCC website
-
Compile the JavaCC grammar file (SimpleArithmetic.jj) to generate the parser classes:
javacc src/main/javacc/SimpleArithmetic.jj3+5*2 -
Run the application and test the endpoint at http://localhost:8080/api/arithmetic/parse?expression=yourexpression(3+5*2-for-example)
Here are some useful resources to help you get started with JavaCC : JavaCC Documentation: Official JavaCC documentation on how to write grammar files and generate parsers: