Skip to content

Rezouali-Imane/MiniJavaCompiler-JS-DoWhile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎯 MiniJavaCompiler-JS-DoWhile

A Java mini-compiler for JavaScript do...while loops, featuring lexical and syntax analysis using automata-based methods.


📚 Project Overview

This project was developed for the Compilation module at Abderrahmane Mira University of Béjaia, as part of the final year Bachelor’s in Computer Science.

It demonstrates the front-end stages of a compiler:

  • Lexical Analysis (Lexer)
  • Syntax Analysis (Parser)

Specifically targets JavaScript do...while loops.


⚡ Features

📝 Lexical Analysis (Lexer)

  • Character-by-character scanning using a finite automaton
  • Breaks code into lexemes and classifies tokens:
    • keyword, identifier, number, string, operator, delimiter
  • Recognizes major JavaScript keywords: do, while, if, else, for, etc.
  • Supports custom keywords: Rezouali, Imane
  • Ignores comments and whitespace
  • Detects and reports lexical errors with line numbers

📐 Syntax Analysis (Parser)

Validates do...while loops:

do {
    <statements>
} while (<condition>);
  • Checks proper use of braces {}, parentheses (), and semicolons ;
  • Validates declarations, assignments, expressions, and operators
  • Detects and reports syntax errors with line numbers
  • Implemented using a recursive descent parser with finite automata and regular expressions

📖 Grammar Used

Simplified grammar for supported JavaScript constructs:

Program       -> StatementList EOF
StatementList -> Statement*
Statement     -> DoWhile | Declaration | Assignment | OtherStatement
DoWhile       -> 'do' Block 'while' '(' Expression ')' ';'
Block         -> '{' StatementList '}'
Declaration   -> ('var' | 'let' | 'const') Identifier ('=' Expression)? ';'
Assignment    -> Identifier '=' Expression ';'
Expression    -> Value ((Operator) Value)*
Value         -> Identifier | Number | String
Operator      -> ArithmeticOperator | ComparisonOperator

Arithmetic operators: +, -, *, /, %

Comparison operators: ==, !=, <, >, <=, >=

Testing the MiniJSIDE Compiler

Anyone wanting to test this from another machine should follow these steps:

  1. Download the project repository to your computer or clone the repo.

  2. Ensure Java is installed (Java JDK 8 or higher).

  3. Run the executable:

  • Option 1: Run via terminal (if you have Java 23 or higher):
java -jar B3_Rezouali_Imane.jar
  • Option 2: Building a New JAR (Java 8–22)

    1. Open a terminal in the project directory.
    2. Delete any previous out directory (safe):
 rm -rf out
  1. Create the output directory:
 mkdir -p out
  1. Delete any previous B3_Rezouali_Imane.jar file (safe):
 rm -f B3_Rezouali_Imane.jar
  1. Compile the source files. The repository places sources under src/ — compile all .java files and place class files into out:
 javac -d out src/*.java
  1. Create the JAR file.
 jar cfe B3_Rezouali_Imane.jar Main -C out . && java -jar B3_Rezouali_Imane.jar

this project has a Main class in the default package, so use Main:

 jar cfe B3_Rezouali_Imane.jar Main -C out .
  1. Run the JAR file:
 java -jar B3_Rezouali_Imane.jar
  1. Using the IDE:
  • Write, compile, and test JavaScript do...while loops.
  • Click Compile to run lexical and syntax analysis.
  • Click Show Tokens to display the tokens generated by the lexer.

About

Java mini-compiler for JavaScript “do...while” using lexical and syntax analysis.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages