Package org.ek9lang.compiler.phase1


package org.ek9lang.compiler.phase1
E - Initial Symbol definition by traversing the 'ANTLR' - 'AST'.

This phase actually has a number of passes through the 'ANTLR' 'AST', in fact the EK9 Compiler uses both the 'ANTLR' Listener and Visitor models to process the 'AST'.

The reason for the multiple passes is to enable 'forward referencing', each successive pass tends to add more detail to the Symbols that are recorded.

The passes in phase 1 are:

These are configured in FrontEndSupplier

The SymbolDefinition mainly uses the DefinitionListener with an 'ANTLR' - tree walker to traverse the 'AST'. There are quite a few rules and checks - even at this early stage. Most of these are simple Java 'Consumers' or 'BiConsumers' and do simple basic checks - issuing errors by calling ErrorListener.semanticError(org.antlr.v4.runtime.Token, java.lang.String, org.ek9lang.compiler.common.ErrorListener.SemanticClassification) with an appropriate ErrorListener.SemanticClassification.

In general many of the phases use the 'Listener' approach and 'walk the tree'. Sometimes they process 'ANTLR' contexts on entry and at other times on exit. The 'Listeners' use SymbolsAndScopes and this uses a ScopeStack to 'push and 'pop' scopes as the 'AST' is traversed. In this way it is possible to add Symbols to the correct scope during AST traversal.

Most of the checks on symbols and constructs are very focussed and have a 'single responsibility'. They are then composed and applied. Initially most of these were just methods on classes. But this became quite complex, so it was refactored in to 'many' separate classes (Functions/Consumers). While there are many more it has helped enable more focus.

The latter two passes are really just cross source file and module checks and as such run in a single threaded manner.

See org.ek9lang.compiler.phase2 for the next stage of compilation.