Skip to content

About

Developed a custom programming language in JavaScript with a fully implemented lexer, parser, AST builder, and interpreter. Added support for variable declarations, expression evaluation, and print statements, creating a functional compiler pipeline capable of emitting runnable JavaScript code.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

🚀 NovaScript

A custom-designed programming language built from the ground up, featuring a complete compiler pipeline comprising lexical analysis, syntax parsing, Abstract Syntax Tree (AST) generation, semantic evaluation, and JavaScript code generation.


📖 Overview

NovaScript is an educational compiler engineering project that explores the complete lifecycle of a programming language—from raw source code to executable JavaScript. The project implements every fundamental stage of a modern compiler, including lexical analysis, parsing, AST construction, interpretation, and code generation.

Rather than relying on existing compiler frameworks, each phase was developed independently to provide a deeper understanding of language design, parsing techniques, runtime execution, and compiler architecture.


✨ Key Features

  • 📝 Custom programming language syntax
  • 🔍 Handcrafted lexical analyzer (Lexer)
  • 🌳 Recursive parser with Abstract Syntax Tree (AST) generation
  • ⚡ Runtime interpreter for immediate code execution
  • 🔄 JavaScript code generation pipeline
  • 📚 Variable declarations and scope management
  • ➕ Expression parsing and evaluation
  • 🛡️ Comprehensive syntax validation and error reporting
  • 🧩 Modular compiler architecture with clearly separated compilation stages

🏗️ Compiler Architecture

NovaScript follows a traditional compiler pipeline where each stage is responsible for transforming the source program into a more structured representation before execution.

Source Code
      │
      ▼
Lexical Analysis (Lexer)
      │
      ▼
Token Stream
      │
      ▼
Syntax Analysis (Parser)
      │
      ▼
Abstract Syntax Tree (AST)
      │
      ├──────────────► Interpreter
      │                    │
      │                    ▼
      │              Runtime Execution
      │
      ▼
JavaScript Code Generator
      │
      ▼
Executable JavaScript

🔍 Lexical Analysis

The lexical analyzer scans raw source code and transforms it into a structured stream of tokens while eliminating irrelevant whitespace and recognizing language constructs such as:

  • Identifiers
  • Keywords
  • Numeric literals
  • Operators
  • Delimiters
  • Parentheses and punctuation
  • Assignment expressions

This tokenization phase establishes the foundation for accurate syntax analysis.


🌳 Syntax Analysis & AST Generation

The parser processes the token stream according to the language grammar and constructs an Abstract Syntax Tree (AST) representing the hierarchical structure of the program.

The AST serves as the intermediate representation for both interpretation and code generation, enabling:

  • Expression parsing
  • Operator precedence handling
  • Nested statement evaluation
  • Variable declarations
  • Program structure validation

⚡ Runtime Interpreter

The interpreter traverses the generated AST to execute programs directly without requiring prior compilation.

Supported runtime capabilities include:

  • Variable declaration and initialization
  • Arithmetic and logical expression evaluation
  • Runtime execution of statements
  • Environment and symbol resolution
  • Sequential program execution

This execution model demonstrates the implementation of core interpreter concepts used in modern scripting languages.


🔄 Code Generation

Beyond interpretation, NovaScript includes a complete code generation phase that transforms the AST into executable JavaScript.

The generated output preserves the logical semantics of the original program while demonstrating concepts such as:

  • AST traversal
  • Intermediate representation transformation
  • Source-to-source compilation
  • Language transpilation techniques

🧪 Validation & Error Handling

The compiler incorporates validation mechanisms throughout multiple compilation stages to detect and report errors early.

Lexical Validation

  • Invalid characters
  • Unknown tokens
  • Malformed literals

Syntax Validation

  • Unexpected tokens
  • Missing delimiters
  • Invalid grammar structures
  • Parsing failures

Runtime Validation

  • Undefined variables
  • Invalid expression evaluation
  • Execution consistency

⚙️ Technical Highlights

  • Designed and implemented a complete compiler pipeline entirely in JavaScript.
  • Built a custom lexer for efficient tokenization of source code.
  • Developed a recursive-descent parser capable of generating structured Abstract Syntax Trees (ASTs).
  • Implemented an interpreter supporting runtime execution, variable management, and expression evaluation.
  • Created a source-to-source compiler that transpiles NovaScript into executable JavaScript.
  • Applied compiler design principles including lexical analysis, parsing, AST traversal, semantic evaluation, and code generation.
  • Structured the project with modular compiler stages to maximize maintainability, extensibility, and readability.

🛠️ Tech Stack

Category Technologies
Programming Language JavaScript
Compiler Components Lexer, Parser, AST, Interpreter
Core Concepts Compiler Design, Language Processing, Parsing Algorithms
Code Generation JavaScript Transpilation
Version Control Git & GitHub

🎯 Learning Outcomes

NovaScript demonstrates a practical understanding of compiler engineering through the implementation of every major compilation stage, combining theoretical computer science concepts with real-world software engineering practices.

Key concepts explored include:

  • Programming language design
  • Lexical analysis
  • Recursive-descent parsing
  • Abstract Syntax Tree construction
  • Interpreter implementation
  • Source-to-source compilation
  • Compiler pipeline architecture
  • Runtime environment management
  • Algorithmic problem solving
  • Modular software design

About

Developed a custom programming language in JavaScript with a fully implemented lexer, parser, AST builder, and interpreter. Added support for variable declarations, expression evaluation, and print statements, creating a functional compiler pipeline capable of emitting runnable JavaScript code.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages