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.
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.
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.
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
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.
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 are welcome! If you find any bugs or have suggestions for improvement, please open an issue or create a pull request on GitHub.