Skip to content

NitinReddy-A/Custom_Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Custom Compiler built in JS

This project implements a custom compiler for a simple programming language. The compiler consists of three main phases: Lexer, Parser, and Code Generator. It takes code written in a custom language and translates it into executable JavaScript code.

Overview

The project is divided into the following phases:

Code Compiler: Invovles Lexer, Parser and Code Generator in the code compilation phase

Code Runner: This runs the code generated from the compiler.

Features

Lexical analysis of input code. Parsing of tokens to build an abstract syntax tree (AST). Generation of JavaScript code from the AST. Support for basic operations such as variable declaration, arithmetic operations, and output printing.

Usage

To use the custom compiler, follow these steps:

Clone the repository:

git clone https://github.com/your-username/custom-compiler.git

Navigate to the project directory:

cd custom-compiler

Run the compiler with your custom code:

node compile.js

How it Works

The compiler processes the input code in the following manner:

Lexer: The lexer scans the input code character by character, skipping whitespaces and identifying tokens such as keywords, identifiers, numbers, and operators.

Parser: The parser processes the tokens generated by the lexer and constructs an abstract syntax tree (AST) representing the structure of the code.

Code Generator: The code generator traverses the AST and generates equivalent JavaScript code, which can then be executed.

Example

Consider the following example code written in the custom language:

take x = 10
take y = 20
take sum = x / y
show sum

The output of the compiler will be the following JavaScript code:

const x = 10;
const y = 20;
const sum = x / y;
console.log(sum);

Contributions

Contributions are welcome! If you find any bugs or have suggestions for improvement, please open an issue or create a pull request on GitHub.

About

No description, website, or topics provided.

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors