Implementation of a customized version of Delphi programming language which is an Object Oriented Extension of Pascal in antlr4 + java using abstract syntax trees
In this project we use a java-based "visitor pattern" (visitor for short) to traverse the abstract syntax tree generated by our ANTLR grammar.
- Generate the proper java files from ANTLR grammar. Run the following command with the
-visitorflag, to generate a visitor in addition to the rest of the files:
antlr4 Delphi.g4 -visitor
- Compile generated java files:
javac -cp ".:$HOME/antlr4-4.13.2-complete.jar" Delphi*.java
- Run the Test Cases:
java -cp ".:$HOME/antlr4-4.13.2-complete.jar" DelphiInterpreter
A visitor is simply the action implementer for our parse tree. It has a method for each branch, containing what actions to perform for that branch.
Our base visitor, generated by the command -visitor above, is an interface; it is generated with empty methods for handling each branch. It's up to us to implement what actions they do in our ASTVisitor file.
- Note that instead of procedure we have used procd and func instead of function keyword.
- For each test case we have included a .txt file specifying what is expected to be printed by the program.
- Each test case will print the program and print statements showcasing the functionality developed.
- Test cases 1-12 cover part 1 scope and 13-24 cover part 2 scope.
- Please Enter only integers when entering values.
- Identifying Program name, End
- Variable declarations
- Procedure, Function declarations
- Readln
- Writeln
- User defined functions
- User defined procedures
- classes
- constructor declaration
- constructor definition
- destructor declaration
- destructor definition
- object creation
- Encapsulation
- Inheritance: parent classes (bonus)
- Interfaces (bonus)
- for-do Loop
- while-do Loop
- Arithmetic Operations
- If-Else statements
- Break
- Continue
- User Defined Procedures
- User Defined Functions
- Scoping
- Constant propagation (bonus)
- formal parameter passing in procedures (bonus)