Difference between revisions of "Assignment: Parser"
(created page for Parser project) |
|||
Line 3: | Line 3: | ||
== Notes == | == Notes == | ||
− | Our [[Concurrent MiniJava Grammar|modifications]] | + | Our [[Concurrent MiniJava Grammar|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 [[Concurrent MiniJava Grammar|modified grammar]]. | 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 [[Concurrent MiniJava Grammar|modified grammar]]. | ||
Further changes must be made to account for the declaration of the ''run'' method since ''void'' return types are not allowed in [http://www.cambridge.org/resources/052182060X/ MiniJava], except in the special case of the main method declaration. To handle this, we add a ''RunMethodDeclaration'' production to our [[Concurrent MiniJava Grammar|modified grammar]]. | Further changes must be made to account for the declaration of the ''run'' method since ''void'' return types are not allowed in [http://www.cambridge.org/resources/052182060X/ MiniJava], except in the special case of the main method declaration. To handle this, we add a ''RunMethodDeclaration'' production to our [[Concurrent MiniJava Grammar|modified grammar]]. |
Revision as of 22:40, 28 July 2010
Overview
In this project students use JavaCC to implement the scanner and parser rules for our modified MiniJava language.
Notes
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.