Difference between revisions of "Assignment: Parser"

From Embedded Xinu
Jump to navigation Jump to search
(added link to grammar)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
= Overview =
 
= Overview =
In this project students use [https://javacc.dev.java.net/ JavaCC] to implement the scanner and parser rules for our [[Concurrent MiniJava Grammar|modified MiniJava]] language.
+
In this project students use [https://javacc.dev.java.net/ JavaCC] to implement the scanner and parser rules for our [http://www.mscs.mu.edu/~brylow/cosc4400/Spring2011/ConcurrentMiniJava.html Concurrent MiniJava] language.
  
 
== Notes ==
 
== Notes ==
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.  
+
[http://www.mscs.mu.edu/~brylow/cosc4400/Spring2011/ConcurrentMiniJava.html Concurrent MiniJava] requires that ''Xinu'', ''Thread'', ''run'', and ''synchronized'' 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 (AST) 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 [http://www.mscs.mu.edu/~brylow/cosc4400/Spring2011/ConcurrentMiniJava.html 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 [http://www.mscs.mu.edu/~brylow/cosc4400/Spring2011/ConcurrentMiniJava.html modified grammar].
 +
 
 +
To support the ''synchronized'' keyword the AST node for method declarations needs a new field to keep track of whether a method is synchronized or not.

Latest revision as of 19:30, 27 August 2010

Overview

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

Notes

Concurrent MiniJava requires that Xinu, Thread, run, and synchronized 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 (AST) 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.

To support the synchronized keyword the AST node for method declarations needs a new field to keep track of whether a method is synchronized or not.