Assignment: Parser

From Embedded Xinu
Revision as of 22:23, 28 July 2010 by Amallen (talk | contribs) (created page for Parser project)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


In this project students use JavaCC to implement the scanner and parser rules for our modified MiniJava language.


Our modifications to MiniJava require that Xinu, Thread, and run be added as reserved words for the Scanner and Parser. The external call productions must keep track of the name of the Xinu method being called.

Also, since our modified language allows programmers to declare classes which extend the Thread class without ever actually declaring a Thread class, the compiler must be informed implicitly that there exists a Thread class. To avoid the complexity of making the compiler aware of the entire Java Thread class, the Parser can automatically generate an Abstract Syntax Tree node for a Thread class with an empty run method. This ensures there are no runtime errors when the external call Xinu.threadCreate calls the run method of a class which extends Thread but does not override the run method. To do this, class declarations which extend Thread are handled by the additional ThreadClassDeclaration production in our modified grammar.

Further changes must be made to account for the declaration of the run method since void return types are not allowed in MiniJava, except in the special case of the main method declaration. To handle this, we add a RunMethodDeclaration production to our modified grammar.