This project is an experimental transpiler that translates "Flutter-like" code into HTML and JavaScript. It was developed as a university assignment to demonstrate the process of building a transpiler, including lexical analysis, parsing, syntax and semantic error handling, Abstract Syntax Tree (AST) construction, and code generation.
The main goal of this project is to allow users to write code in a Flutter-like syntax and have it automatically translated into web technologies (HTML & JS). This showcases the ability to work with compiler design concepts and implement complex language processing systems.
- Custom lexer for tokenizing Flutter-like syntax
- Parser with comprehensive syntax and semantic error handling
- Multi-scoped symbol table implementation using a stack of hashmaps
- Abstract Syntax Tree (AST) generation
- Code generation from AST to HTML and JavaScript
- Visual representation of the AST using jGraphT library
The project is structured using the Composite Design Pattern, which is ideal for representing the parent-child relationships in the language structure. The main components are:
- Program: The root of the structure, containing statements and the main scaffold.
- Widgets: Both pre-defined and custom UI elements.
- Statements: Variable declarations, assignments, and custom widget definitions.
- Properties: Attributes and settings for widgets.
- Expressions: Mathematical and logical expressions.
- Lexical Analysis: Tokenizes the input code and checks for syntactic errors.
- Parsing and Semantic Analysis: Matches token sequences against parsing rules and performs semantic checks (e.g., undefined variables, duplicate names, nested scopes).
- Abstract Syntax Tree (AST) Generation: Builds an AST representing the essential structure of the code.
- Code Generation: Converts the AST into the target languages (HTML and JavaScript).
- Composite Design Pattern: Used to structure the project, representing the parent-child relationships in the language elements.
- Visitor Design Pattern: Employed to separate the logic applied to the parsing tree (for AST generation and syntactic error checking) and the AST (for code generation and other operations) from the structure itself.
- ANTLR4: Used for lexer and parser generation
- Java: Primary programming language
- jGraphT library: Utilized for visualizing the AST as a graph
For complete documentation of the project in Arabic, please refer to the following link:
[To be added in a future update]
Here's an example of how the Flutter-like code is transpiled to HTML and JavaScript:
The project's structure, thanks to the use of Composite and Visitor design patterns, allows for easy extensibility and improvements without affecting the existing codebase. Potential areas for enhancement include:
- Expanding the set of supported Flutter-like widgets and properties
- Optimizing the generated HTML and JavaScript code
- Adding support for more complex Flutter features
- Implementing a user-friendly interface for the transpiler
This project was developed as a university assignment by the following team members:
- Alaa Aldeen Zamel
- Mhd Hadi Barakat
- Anas Rish
- Anas Durra
- Sham Tuameh
We appreciate the hard work and dedication of all team members in bringing this project to fruition.
This project is licensed under the MIT License - see the LICENSE file for details.