[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The file `parse.y' contains the "bison" source code of GNU Pascal's parser. This stage of the compilation analyzes and checks the syntax of your Pascal program, and it generates an intermediate, language-independent code which is then passed to the GNU back-end.
The bison language essentially is a machine-readable form of the Backus-Naur Form, the symbolic notation of grammars of computer languages. "Syntax diagrams" are a graphical variant of the Backus-Naur Form.
For details about the "bison" language, see section `Top' in the Bison manual. A short overview how to pick up some information you might need for programming follows.
Suppose you have forgotten how a variable is declared in Pascal. After some searching in `parse.y' you have found the following:
/* variable declaration part */ |
Translated into English, this means: "The variable declaration part consists of the reserved word (lexical token) `var' followed by a `variable declaration list' and a semicolon. A semicolon immediately following `var' is an error. A `variable declaration list' in turn consists of one or more `variable declarations', separated by semicolons." (The latter explanation requires that you understand the recursive nature of the definition of `variable_declaration_list'.)
Now we can go on and search for `variable_declaration'.
variable_declaration: id_list { [...] } enable_caret ':' optional_qualifier_list type_denoter { [...] } absolute_or_value_specification { [...] } ; |
(The `[...]' are placeholders for some C statements which aren't important for understanding GPC's grammar.)
From this you can look up that a variable declaration in GNU Pascal consists of an "id list", followed by "enable_caret" (whatever that means), a colon, an "optional qualifier list", a "type denoter", and an "absolute or value specification". Some of these parts are easy to understand, the others you can look up from `parse.y'. Remember that the reserved word `var' precedes all this, and a semicolon follows all this.
Now you know the procedure how to get the exact grammar of the GNU Pascal language from the source.
The C statements, not shown above, are in some sense the most important part of the bison source, because they are responsible for the generation of the intermediate code of the GNU Pascal front-end, the so-called tree nodes. For instance, the C code in "type denoter" juggles a while with variables of the type `tree', and finally returns (assigns to `$$') a so-called tree list which contains the information about the type. The "variable declaration" gets this tree list (as the argument `$6') and passes the type information to the C function `declare_vars()' (declared in `util.c'). This function `declare_vars()' does the real work of compiling a variable declaration.
This, the parser, is the place where it becomes Pascal.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |