Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Syntax Bridge

Syntax Bridge is a compiler and transpiler built for a custom educational programming language. This project demonstrates the implementation of a full language processing pipeline - from lexical analysis and parsing (using ANTLR4) to semantic analysis, Java code generation, and dynamic compilation.

It allows you to write code in a simplified syntax and compiles it directly into executable Java byte-code.

Features

  • Variable Declaration & Assignment:
    • var ID : type ; (int, float)
    • ID := expr ;
  • Control Flow:
    • if (expr) { ... } [else { ... }] / end
    • while (expr) { ... }
  • Functions: Define and call custom functions with parameters:
    • func ID(params) { ... }
    • ID(args);
  • Print Statements: print(expr);
  • Expressions & Operators:
    • Arithmetic: +, -, *, /
    • Unary: -expr
    • Relational: <, <=, >, >=
    • Equality: ==, !=
    • Grouping: (expr)
    • Casts: (type) expr
    • Literals: numbers, strings, identifiers
  • Comments:
    • Line: // ...
    • Block: /* ... */

Tech Stack

  • Language: Java 17+
  • Build Tool: Maven
  • Parser Generator: ANTLR4
  • Testing: JUnit 5

Prerequisites

Ensure you have the following installed:

  • Java JDK 17 (or higher)
  • Maven (3.8+)

Getting Started

1. Build the Project

This will generate the ANTLR sources (Parser/Lexer) and compile the project.

mvn clean install

2. Run the Application

You can run the main application via your IDE or:

Command Prompt / Bash (Standard)

mvn exec:java -Dexec.mainClass="org.example.Main"

PowerShell (Windows)

mvn exec:java "-Dexec.mainClass=org.example.Main"

3. Run Tests

The project includes unit tests for parsing, generation, and compilation logic.

mvn test

Project Architecture

  1. Lexer/Parser: ANTLR4 reads the .g4 grammar file and generates the EduLangLexer and EduLangParser.
  2. Code Generator: CodeGenerator.java visits the parse tree and constructs a standard Java String representing the program.
  3. Compiler Service: Takes the generated string, writes it to a file, and invokes the system Java Compiler.
  4. Java Execution: The resulting bytecode is executed.

About

Syntax Bridge: An educational language compiler and transpiler using ANTLR4, supporting variables, functions, control flow, expressions, and generating executable Java code.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages