Java dynamic interpreter with a Bison-based parser, for Dynamic academic language similar to JavaScript
This project is part of the [F25] Compiler Construction course at Innopolis University
Javdin processes source code written in Project D, a dynamically-typed academic language with JavaScript-like syntax, and executes it on the Java Virtual Machine.
Key characteristics:
- Implementation language: Java 17
- Target language: Project D (dynamic typing, 1-based arrays, tuples, closures)
- Parser generation: CUP (Construction of Useful Parsers) for LALR(1) parsing
- Build system: Maven 3.6
- License: GNU GPL v3
Javdin contains these six main components:
-
A hand-written lexer. Takes source code in .d files and outputs stream of tokens with position information.
-
LexerAdapter. Bridge between lexer and CUP parser. Converts Token objects to CUP Symbol objects. Maps token types to CUP terminal symbols.
-
CUP-generated LR parser. We use CUP as mav Takes token stream from LexerAdapter as an input. Uses parser.cup as a grammar rules file (417 lines). Returns the Abstract Syntax Tree (AST).
-
Custom AST nodes (for creating custom ast tree xml visualization, see AstXmlSerializer, can be used with visualize-ast.sh). Node hierarchy: 23 specialized classes extending StatementNode or ExpressionNode Each production rule creates specific AST node type. All nodes are immutable with final fields. Every node stores source line and column which allows position tracking.
-
Semantic Analysis:
5.1) SemanticAnalyzer
- Performs non-modifying semantic validation
- Detects 4 types of semantic errors:
- Return outside function check
- Break(Exit) outside loop check
- Undeclared variable check
- Duplicate declaration check
5.2) Optimizer
- Performs AST-modifying optimizations
- Uses symbol table for scope management
- Implements 4 optimization techniques:
- Pass 1: Collect used variables
- Pass 2: Apply optimizations
- Constant folding
- Unused variable removal
- Dead branch elimination
- Unreachable code removal
-
Interpreter executes the optimized AST using the visitor pattern. It implements a tree-walking interpreter with dynamic typing, supporting eight value types: integer, real, boolean, string, array, tuple, function, and void. The interpreter uses a stack-based approach to handle lexical scoping in blocks and functions.
javdin/
- docs/ # Task statements, parser notes, milestone reports
- reports/ # Weekly reports and component presentations
- src/
- - main/
- - - java/com/javdin/
- - - - ast/ # 23 immutable AST node definitions
- - - - lexer/ # Hand-written lexer, tokens, and lexical utilities
- - - - parser/ # Parser wrapper, CUP adapter, grammar artifacts
- - - - semantics/ # Semantic analyzer and optimizer
- - - - interpreter/ # Tree-walking interpreter and runtime environment
- - - - visualization/ # AST XML serializer (for ast tree visualizations)
- - - resources/ # CUP/Flex outputs, demo assets, configs
- - test/java/ # JUnit integration and regression suites
- test-resources/ # Project D sample programs
- scripts (*.sh) # Helpers for demos, AST visualization, testgit clone https://github.com/team-806/javdin.git # Clone project
mvn clean compile # Compile project
mvn package # Create JAR
# If you want run Tests
mvn test jacoco:report
# Run example programs...
java -jar target/javdin-1.0.0.jar ./test-resources/test-allfuncs.d
# or try writing something on your own...You can see a lot of simple programs examples in test-resources. In case of any syntax related questions consult Project D.pdf.
