Additional Syntactic Specifications

Grammar extensions

In addition to the rules of the standard Tiger grammar (see Syntactic Specifications), extensions adds the following productions.

(* A list of chunk metavariable *)
chunks = "_chunks" "(" integer ")" chunks ;


exp =
  (* Cast of an expression to a given type *)
   "_cast" "(" exp "," ty ")"
  (* An expression metavariable *)
 | "_exp" "(" integer ")"
 ;


lvalue =
  (* Cast of a l-value to a given type *)
   "_cast" "(" lvalue "," ty ")"
  (* A l-value metavariable *)
 | "_lvalue" "(" integer ")"
 ;


(* A type name metavariable *)
type-id = "_namety" "(" integer ")" ;
Metavariables

The _chunks, _exp, _lvalue, _namety keywords are used as metavariables, i.e. they are names attached to an already built AST. They don’t create new AST nodes, but are used to retrieve existing nodes, stored previously. For instance, upon an _exp(51) statement, the parser fetches the tree attached to the metavariable 51 (an expression) from the parsing context (see the implementation for details).