A lightweight programming language compiler and interpreter implemented in Java. This project processes a custom programming language, providing lexical analysis, parsing, semantic checking, and execution functionalities. It translates input code into an Abstract Syntax Tree (AST), validates semantics, and either interprets the AST or generates executable code.
- Tokenizes input source code into meaningful units (tokens), such as identifiers, operators, numbers, and keywords.
- Handles errors like invalid characters or malformed numbers.
- Converts the tokens into an Abstract Syntax Tree (AST).
- Implements grammar rules for the language to ensure syntactic correctness.
- Checks the validity of types, variable declarations, and function definitions.
- Ensures variables are used within scope and adheres to constant/mutable rules.
- Represents the structure of the source code using nodes for fields, methods, statements, and expressions.
- Translates the AST into Java syntax or other target executable code.
- Directly executes the AST by interpreting its semantics.
- Handles control flow (e.g.,
if
,for
,while
) and arithmetic/logical operations.
- Manages variable and function declarations, including types, values, and scope resolution.
P4
├── src
│ ├── Analyzer.java
│ ├── Ast.java
│ ├── Environment.java
│ ├── Generator.java
│ ├── Interpreter.java
│ ├── Lexer.java
│ ├── Parser.java
│ ├── Scope.java
│ └── Token.java
└── README.md
- Java Development Kit (JDK): Version 8 or higher.
- Git: Version control for cloning the repository.
git clone https://github.com/Retsamic/Programming-Language-Compiler.git
cd Programming-Language-Compiler
- Compile the Java files:
javac src/*.java
- Execute the main program (if a specific entry point exists):
java src.Main
- Provide a source code file in the custom language as input.
- The Lexer generates tokens from the input.
- The Parser builds an AST.
- The Analyzer checks semantic correctness.
- The Generator or Interpreter processes the AST for execution or code generation.
- Java: Core programming language for development.
- Git: Version control.
Contributions are welcome! Follow these steps to contribute:
- Fork the repository.
- Create a new feature branch.
- Commit changes and push the branch.
- Submit a pull request.