Package org.ek9lang.compiler.phase0
The Parsing
class is used to coordinate the preparation of
the CompilableSource
objects state; that are part of the
Workspace
.
Each CompilableSource
has its own ErrorListener
and error state. The methods:
Are then called in turn for each source file, note that the initial parsing of the source files is multi-threaded. This can be done in a multi-threaded manner because the compiler does not attempt to to cross reference anything.
The Parsing
class uses the methods within each
CompilableSource
to do the actual parsing.
ParserCreator
is used by the CompilableSource
to create the appropriate Ek9LexerForInput
and ANTLR based 'EK9Parser'.
The ParserCreator
configured both the lexer and the parser in an appropriate
manner (typically error listening).
It is the 'double team' of the Lexer and Parser that opens the file, scans for tokens and then pulls those tokens in to build an in-memory 'AST'. If there is anything wrong in the code at this stage, the errors will be 'ANTLR' style errors.
Only if this phase fully passes for every single source file do the EK9 Compiler continue to the next phase.
This same philosophy applies in all phases, all files must pass each phase before the compiler moves on. Importantly the EK9 Compiler attempts to identify issues in code as early as possible in each phase. It does not attempt to process most of the code to build an 'IR' and then assess the IR. Many of the rules for error detection are contained within each phase. There is an 'IR' generation phase and error assessment, but an EK9 compiler attempts to give error feedback as soon as it can.
So you may be thinking 'but where is the state stored'? Basically for phase 0, the
CompilableSource
keeps a reference to the 'ANTLR' 'EK9Parser.CompilationUnitContext'.
The CompilableSource
is used in most of the other phases in conjunction with
ParsedModule
and the CompilableProgram
to build uo
state.
The type of symbols that are available from org.ek9lang.compiler.symbols
are added to the
appropriate ParsedModule
.
See org.ek9lang.compiler.phase1
for the next stage of compilation.