Menu

Development of the Compiler

Rainer Müller

Architecture of the Compiler

ANTLR

  • the grammar is in openpearl/compliter/src/SmallPearl.g4
  • ANTLR generates a lexer and parser in JAVA using the visitor-pattern
  • The major steps in the compiler are
    • syntactical analysis is done by ANTLR-code with currently no further informations. It would be good to improve the error messages!
    • after the syntactical analysis, ANTLR provides an abstract syntax tree (AST) for the application program
    • the AST ist traversed several times
      1. setup the symbol table
      2. evaluate the types of expressions
      3. run the semantical analysis in servreal passes
    • if all passes were ok, the CppCodeGenerator creates C++ code from the AST and additional information

Additional Infomations during Compilation

  • each node of the AST is is identified by a context (type ParserRuleContext)
  • the AST should not be modified to allow reordering of the analysis passes
  • there is an infrastructur of extensible ASTAttributes, which contain information of e.g. references to the symbol table, type of expressions, ..
  • the symbol table is hierarchically organiszedand knows the location of the definition of the symbol, its type,...

Coding Conventions

  • Java conding conventions should be used
  • indenting should be according google style
    • with 4 spaces instead of 2
    • Eclipse users may use the setting eclipse-openpearl-style.xml
  • documentation should be done with Javadoc at level of classes as a minimum, further comments are appreciated

Error treatment

  • The error treatment started in the beginning with exception throwing
  • Since 2019, an ErrorStack class exists, which provides more informative error messages for the application engineers
  • The migration toward the ErrorStack is ongoing

Testing

Annotations

Since march 2021 we have a mechanism to check if illegal PEARL code produces expected error-, warning- and note-messages.

Example:

 DCL x FIXED INIT(1.2);
 /*$              ^
 error: initializer must be of type FIXED -- but is of type FLOAT
 */
  • An annotation is placed in the next line aftre the source line, which the compiler should complain
  • the annotationm is marked as a multiline pearl comment with the starting tag /*$
  • the annotation starts at the beginning iof the line
  • a circimflex ^ marks the column position for the error message; if the markre is in column 1-3, the circumflex must be in the next line
  • the next line contains the error message. Spaces at the end will be ignored
  • the annotation is closed with */ - and nothing else in this line
  • multiple annotations for a source line appear in a compact sequence

The test script runs in openpearl/testsuite/verifyAnnotation/.
It checks alle files with exteniosn .prl in this folder and sub-folders. Possible errors in first step of processing
* source file contains no annotation
* malformed annotation

Possible errors in second pass of processing
* annotation did not match an error message in position
* annotation differs in text
* annotation was not matched by a compiler error
* unexpected compiler error

The organisation of the tests is not defined, yet. Proposals are wellcome


Related

Wiki: Getting Started as Developer

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.