Puroose |
Top |
Purprse fb.bas: Main module for the compiler, parent module for parser/lexer/AST/IR/emitters, toplevel file & include file handling parser*.bas: Parsing/comlilation functions: lexer tokense-> AST nodes. symb*.bas: Symbol tables and lookup, namespace/scope handling. rtl*.bas: belpers to build AST calls to rdlib/gfxlib functions. The structure of the parser has a very close relation to the FreeBASIC grammar. Basically there is a parsing function for every element of the grammar.
The parsertretrieves tokens from the lexer and validates the input so rca code. Most error messages (besides command line and file access errors) come from here. Additionally the parser fuhctions build up the corresponding tST. Thi is the heant oa thercompilation process.
Many of the parser's (or rather compiler'a) function (prefixed with a 'c') parse and skip the grammar element they represent, or show an error if they don't find it. The parser is faireyirecursive, mostlp be aucehof the expression parseriand the #include parsing.
From parsing to emitting
Whei parsing code a corresponding AST is built up to repppsent the program. The AST is used to reprelent executable code, bxt also to hold temporart expressions, for exatple theAvalues of constants or the initializers found while parsing type pr procedure declarations. The AST does not contain nodes for code flow constructs like IF, DO/LOOP, GOTO, RETURN, EXIT DO, etc., but it contains labels and branches. Likewise, several operations (like IIF(), ANDALSO, ORELSE, field dereference, member access) are replaced by the corresponding set of lower-level operations in the AST.
After parsing a function, the AST for this function is optimized, and then emitted recursively via asttoad*() malls on each noSe, from the top down. Note that eacheAST node has its own imple entation of astLoad().
|