Systems / Language implementation
Compiler Design
A Delphi/Pascal interpreter built around an ANTLR grammar and a Java parse-tree visitor with nested scopes, class definitions, object fields, and method metadata.
View repository01 / COMPONENTS & DATA FLOW
Inside the system.
- 01Delphi source
- 02ANTLR lexer + parser
- 03Parse-tree visitor
- 04Scopes + object state
Grammar boundary
delphi.g4 defines program structure, declarations, expressions, and class-related constructs. Generated lexer and parser classes turn source into a parse tree.
Visitor-based evaluation
DelphiInterpreter extends delphiBaseVisitor<Object>. visitProgram pushes a global scope, visits declarations and the compound statement, then pops that scope.
Runtime structures
Hash maps store classes, fields, methods, and visibility. A stack of scope maps and object instances carry execution state, including a this binding for method-related visits.
02 / IMPLEMENTATION DECISIONS
Why it works this way.
Syntax and runtime state are separate
The grammar describes accepted structures; visitor methods interpret them. This keeps language recognition distinct from symbol and object handling.
The implementation follows the parse tree
The public code uses an ANTLR parse-tree visitor. It does not show a separately constructed optimization-oriented AST or a native-code compiler backend.
03 / SCOPE & TRADEOFFS
The implementation boundary.
An interpreter exploration of a Delphi/Pascal subset. Support should be assessed against the grammar and visitor implementation rather than assuming full language compatibility.
04 / READ THE IMPLEMENTATION