https://github.com/dunningkrueg/compiler-assambler-basic-javascript
A lightweight JavaScript compiler built in C++. Features lexical analysis, parsing, and AST generation. Perfect for learning compiler fundamentals and exploring how JavaScript works under the hood
https://github.com/dunningkrueg/compiler-assambler-basic-javascript
Last synced: 3 months ago
JSON representation
A lightweight JavaScript compiler built in C++. Features lexical analysis, parsing, and AST generation. Perfect for learning compiler fundamentals and exploring how JavaScript works under the hood
- Host: GitHub
- URL: https://github.com/dunningkrueg/compiler-assambler-basic-javascript
- Owner: dunningkrueg
- Created: 2025-01-17T10:26:15.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-17T12:53:31.000Z (5 months ago)
- Last Synced: 2025-02-08T09:20:21.014Z (4 months ago)
- Language: C++
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Basic JavaScript Compiler
A simple JavaScript compiler implementation in C++ that demonstrates the fundamental concepts of compiler design. This project serves as an educational tool to understand the basic components of a compiler.
## Features
- **Lexical Analysis**: Converts source code into tokens
- **Parsing**: Generates Abstract Syntax Tree (AST) from tokens
- **Basic JavaScript Support**:
- Function declarations
- Variable declarations
- Binary operations (+, -, *, /)
- Function calls
- Return statements## Prerequisites
- CMake (3.10 or higher)
- C++ Compiler with C++17 support
- Visual Studio 2019/2022 (for Windows) or GCC/Clang (for Unix)## Building the Project
1. Create a build directory:
```bash
mkdir build
cd build
```2. Generate build files:
```bash
cmake ..
```3. Build the project:
```bash
cmake --build . --config Release
```## Usage
Run the compiler with a JavaScript file:
```bash
./js_compiler path/to/your/file.js
```Example JavaScript input:
```javascript
function add(a, b) {
return a + b;
}let x = 10;
let y = 20;
let result = add(x, y);
```## Limitations
This is a basic compiler implementation with the following limitations:
- No code optimization
- Limited JavaScript feature support
- No bytecode generation
- No runtime environment
- Basic error handling
- No support for complex JavaScript features (classes, async/await, etc.)## Future Improvements
Potential areas for enhancement:
1. Code optimization
2. More JavaScript features support
3. Bytecode generation
4. Better error handling and reporting
5. Symbol table implementation
6. Type checking
7. Support for modern JavaScript features## Contributing
This is an educational project demonstrating basic compiler concepts. Feel free to fork and extend it for your learning purposes.
## Acknowledgments
This project is created for educational purposes to demonstrate basic compiler construction concepts. It is not intended for production use.