Write Python. Run JavaScript.
SerpentJS is a modern Python → JavaScript transpiler built from scratch using compiler construction principles.
It converts a well-defined subset of Python into clean, readable, and executable JavaScript while preserving program structure and logic.
This project follows a full compiler pipeline — lexical analysis, parsing, semantic analysis, optimization, and code generation — without using parser generators or external compiler frameworks.
- Overview
- Project Goals
- Supported Features
- Key Algorithms & Techniques
- AST Visualization
- Technologies Used
- Installation
SerpentJS bridges Python’s expressive syntax with JavaScript’s runtime ecosystem.
It allows developers and students to reuse Python logic in JavaScript environments and understand how real-world compilers and transpilers work internally.
The transpiler is modular, extensible, and educational, making it suitable for:
- Compiler construction learning
- Language translation experiments
- Cross-platform logic reuse
- Build a Python-to-JavaScript transpiler from scratch
- Support core Python language constructs
- Preserve logic and execution behavior
- Provide clear grammar mapping
- Implement robust error handling and reporting
- Generate clean and optimized JavaScript code
- Functions (definition & calls)
- Control Flow
if / elif / elsewhilefor ... in ...
- Assignments (single variable)
- Expressions
- Arithmetic
- Comparison
- Logical
- Unary
- Grouping
- Literals
- Integers
- Floats
- Strings
- Booleans
None
def, return, if, elif, else, while, for, in, True, False, None
+ - * / % ** == != < > <= >= and or not
Each phase is implemented independently to ensure clarity, maintainability, and extensibility.
- Manual tokenization using regular expressions
- Indentation tracking via INDENT / DEDENT tokens
- Line and column–based error reporting
- Recursive Descent Parsing
- Operator precedence handling
- AST construction using structured node classes
- Symbol table with nested scopes
- Type inference and validation
- Detection of undeclared identifiers
- Protection of built-in names
- Constant folding
- Dead code elimination
- Expression simplification
- Scope-aware transformations
- Post-order AST traversal
- Python → JavaScript syntax mapping
- Automatic variable declaration tracking
- ES6+ compatible output
SerpentJS supports AST visualization for debugging and learning:
- Console-based AST printing
- Graphviz integration for graphical AST rendering
- Python 3.x – Core implementation language
- JavaScript (ES6+) – Target output language
- Graphviz – AST visualization
- Git & GitHub – Version control
- VS Code – Development environment
- Jupyter Notebook – Testing & demonstrations
git clone https://github.com/FatimaM05/SerpentJS.git