next up previous contents
Next: 3. Data-flow analysis Up: 2. The MURZ language Previous: 2.4 Abstract syntax tree

2.5 Parsing

As said above, parsing phase is performed using ocamlyacc. ocamlyacc is the Ocaml version of the more known yacc, that creates a parser for a language from its LALR grammar.

When parsing, the abstract syntax tree (AST) is built and type checking is performed. Building the AST is quite simple, as it is enough to call the suitable constructor from the semantic action of every production (every production is well typed, see parser.mly).

Type checking is a bit more complex. As in MURZ the user can declare procedures and local variables, a description of the environment is needed to solve the references. In env.ml, environment is represented as a stack of (identifier, type) pairs: every time a variable or a procedure is called, it is pushed into the stack. The remaining part of the type checking is done by the semantic actions of expr and command productions.

For instance, suppose the parser parses this production:

	
     expr: expr '+' expr

Now, it is enough to check (as part of the semantic action) if the sub-expressions are suitable typed (in this example, if they have Integer type). When type error are found, a type error exception is raised.

During the parsing phase, procedures are expanded, as shown above.


next up previous contents
Next: 3. Data-flow analysis Up: 2. The MURZ language Previous: 2.4 Abstract syntax tree
Diego
2000-05-17