Giter VIP home page Giter VIP logo

javascript-compiler's Introduction

JavaScript Compiler

This repository contains a JavaScript compiler implemented using ANTLRv4 and Java. The compiler performs lexical analysis, parsing, semantic analysis, and generates both a parse tree and an abstract syntax tree (AST) for JavaScript code.

Features

  • ANTLR Grammar: Utilizes the hello.g4 file in the src directory to define the JavaScript grammar.
  • ANTLR Recognizer Generation: Generates ANTLR recognizer classes using the ANTLR tool.
  • Lexer and Parser: Utilizes ANTLR-generated lexer and parser for JavaScript grammar.
  • Semantic Analysis: Performs semantic analysis to ensure correctness and coherence of the input code.
  • Parse Tree and AST Generation: Generates a parse tree and an abstract syntax tree (AST) representing the structure of the JavaScript code.
  • Error Handling: Implements robust error handling mechanisms to provide informative messages for syntax and semantic errors.
  • Optimizations: (Optional) Includes any optimizations or enhancements applied to the generated AST or code.

Getting Started

Prerequisites

Building ANTLR Recognizer

  1. Install ANTLR:

    # On Unix-based systems (Linux/Mac)
    cd /usr/local/lib
    sudo curl -O https://www.antlr.org/download/antlr-4.x-complete.jar
    export CLASSPATH=".:/usr/local/lib/antlr-4.x-complete.jar:$CLASSPATH"
    alias antlr4='java -jar /usr/local/lib/antlr-4.x-complete.jar'
    alias grun='java org.antlr.v4.gui.TestRig'
    # On Windows
    # Download the ANTLR JAR from https://www.antlr.org/download.html
    # Set up CLASSPATH and alias commands accordingly
  2. Generate ANTLR Recognizer:

    antlr4 src/hello.g4
  3. Compile the generated files:

    javac -cp .:antlr-4.x-complete.jar src/*.java

Running the Compiler

  1. Run the compiler:

    # Replace 'YourMainClass' with the actual main class of your compiler
    java -cp .:antlr-4.x-complete.jar src/YourMainClass input.js

Example Usage

# Replace 'YourCompilerExecutable' with the actual name of your compiled executable
./YourCompilerExecutable input.js

javascript-compiler's People

Contributors

akash-r-prabhu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.