/Compiler

Primary LanguageJavaScript

Compiler Project

This repository contains a simple compiler project consisting of lexical analysis, syntax analysis, and semantic analysis components. The project is implemented in JavaScript.

Files

  1. input.txt

    • Input file for the custom language used in the compiler.
  2. output.txt

    • Output file of the lexical analyzer, containing a set of tokens generated from the input.
  3. main.js

    • JavaScript file containing the implementation of the lexical analyzer and syntax analyzer.
    • The syntax analyzer has a hard-coded CFG (Context-Free Grammar) that is customizable according to your specific language requirements.
    • to use your own cfg , update the Const grammer = { } according to your CFG .
  4. semantic.js

    • JavaScript file containing the implementation of the semantic analyzer.
    • Handles semantic analysis tasks, including scope checking, type checking, and error reporting.
  5. index.html

    • HTML file for displaying the results of the semantic analysis.
    • Utilizes JavaScript to interact with the semantic analyzer and showcase analysis results.

Running the Compiler

To run the compiler and perform lexical and syntax analysis, execute the following command in your terminal:

node main.js

input

image

Lexical Output

image

syntax Analysis (in terminal)

image

semantic Analysis

image

image