PTHL Improvements

Possible improvements include:

Using %destructor

You may use %destructor to reclaim the memory lost during the error recovery. It is mandated in TC-2, see TC-2 FAQ.

Parser driver

You may implement a parser driver to handle the parsing context (flags, open files, etc.). Note that a driver class will be (partially) provided at TC-1.

Handling object-related constructs from PTHL

Your scanner and parser are not required to support OO constructs at PTHL, but you can implement them in your LALR(1) parser if you want. (Fully supporting them at TC-2 is highly recommended though, during the conversion of your LALR(1) parser to a GLR one.)

Object-related productions from the Tiger Grammar are:

# Class definition (canonical form).
<ty> ::= "class" [ "extends" <type-id> ] "{" <classfields> "}"


# Class definition (alternative form).
<dec> ::= "class" <id> [ "extends" <type-id> ] "{" <classfields> "}"


<classfields> ::= { <classfield> }
# Class fields.
<classfield> ::=
  # Attribute declaration.
    <vardec>
  # Method declaration.
  | "method" <id> "(" <tyfields> ")" [ ":" <type-id> ] "=" <exp>


# Object creation.
<exp> ::= "new" <type-id>

# Method call.
<exp> ::= <lvalue> "." <id> "(" [ <exp> { "," <exp> }] ")"