1
Fork 0

Left Precedence

Corrected left precedence rules when a right precedence rule is not
available (or parenthesis (woah)).
master
Joshua Potter 2014-03-05 09:33:26 -05:00
parent 690dc9d562
commit 242ca887f9
197 changed files with 2943 additions and 15 deletions

BIN
docs/PA3.pdf Normal file

Binary file not shown.

View File

@ -500,10 +500,11 @@ public class Parser {
* @throws IOException
*/
private Expression parseExpression() throws IOException {
Expression e = parseCExpression();
while(peek(1).spelling.equals("||")) {
Operator o = new Operator(accept(Token.TYPE.BINOP), null);
e = new BinaryExpr(o, e, parseExpression(), null);
e = new BinaryExpr(o, e, parseCExpression(), null);
}
return e;
@ -515,10 +516,11 @@ public class Parser {
* @throws IOException
*/
private Expression parseCExpression() throws IOException {
Expression e = parseEExpression();
while(peek(1).spelling.equals("&&")) {
Operator o = new Operator(accept(Token.TYPE.BINOP), null);
e = new BinaryExpr(o, e, parseCExpression(), null);
e = new BinaryExpr(o, e, parseEExpression(), null);
}
return e;
@ -530,10 +532,11 @@ public class Parser {
* @throws IOException
*/
private Expression parseEExpression() throws IOException {
Expression e = parseRExpression();
while(peek(1).spelling.equals("==") || peek(1).spelling.equals("!=")) {
Operator o = new Operator(accept(Token.TYPE.BINOP), null);
e = new BinaryExpr(o, e, parseEExpression(), null);
e = new BinaryExpr(o, e, parseRExpression(), null);
}
return e;
@ -545,11 +548,12 @@ public class Parser {
* @throws IOException
*/
private Expression parseRExpression() throws IOException {
Expression e = parseAExpression();
while(peek(1).spelling.equals("<") || peek(1).spelling.equals("<=")
|| peek(1).spelling.equals(">") || peek(1).spelling.equals(">=")) {
Operator o = new Operator(accept(Token.TYPE.BINOP), null);
e = new BinaryExpr(o, e, parseRExpression(), null);
e = new BinaryExpr(o, e, parseAExpression(), null);
}
return e;
@ -561,10 +565,11 @@ public class Parser {
* @throws IOException
*/
private Expression parseAExpression() throws IOException {
Expression e = parseMExpression();
while(peek(1).spelling.equals("+") || peek(1).spelling.equals("-")) {
Operator o = new Operator(accept(Token.TYPE.BINOP), null);
e = new BinaryExpr(o, e, parseAExpression(), null);
e = new BinaryExpr(o, e, parseMExpression(), null);
}
return e;
@ -576,10 +581,11 @@ public class Parser {
* @throws IOException
*/
private Expression parseMExpression() throws IOException {
Expression e = parseSingleExpression();
while(peek(1).spelling.equals("*") || peek(1).spelling.equals("/")) {
Operator o = new Operator(accept(Token.TYPE.BINOP), null);
e = new BinaryExpr(o, e, parseMExpression(), null);
e = new BinaryExpr(o, e, parseSingleExpression(), null);
}
return e;

View File

@ -0,0 +1,98 @@
package tester;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
import java.util.Scanner;
/* Automated regression tester for Checkpoint 2 tests
* Created by Max Beckman-Harned
* Put your tests in "tests/pa2_tests" folder in your Eclipse workspace directory
* If you preface your error messages / exceptions with ERROR or *** then they will be displayed if they appear during processing
*/
public class Checkpoint2 {
private static class ReturnInfo {
int returnCode;
String ast;
public ReturnInfo(int _returnCode, String _ast) {
returnCode = _returnCode;
ast = _ast;
}
}
public static void main(String[] args) throws IOException, InterruptedException {
File testDir = new File(System.getProperty("java.class.path")
+ "/../tests/pa2_tests");
int failures = 0;
for (File x : testDir.listFiles()) {
if (x.getName().endsWith("out") || x.getName().startsWith("."))
continue;
ReturnInfo info = runTest(x);
int returnCode = info.returnCode;
String ast = info.ast;
if (x.getName().indexOf("pass") != -1) {
if (returnCode == 0) {
String actualAST = getAST(new FileInputStream(x.getPath() + ".out"));
if (actualAST.equals(ast))
System.out.println(x.getName() + " parsed successfully and has a correct AST!");
else {
System.err.println(x.getName() + " parsed successfully but has an incorrect AST!");
failures++;
}
}
else {
failures++;
System.err.println(x.getName()
+ " failed to be parsed!");
}
} else {
if (returnCode == 4)
System.out.println(x.getName() + " failed successfully!");
else {
System.err.println(x.getName() + " did not fail properly!");
failures++;
}
}
}
System.out.println(failures + " failures in all.");
}
private static ReturnInfo runTest(File x) throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("java", "miniJava.Compiler", x.getPath()).directory(new File(System.getProperty("java.class.path")));
pb.redirectErrorStream(true);
Process p = pb.start();
String ast = getAST(p.getInputStream());
p.waitFor();
int exitValue = p.exitValue();
return new ReturnInfo(exitValue, ast);
}
public static String getAST(InputStream stream) {
Scanner scan = new Scanner(stream);
String ast = null;
while (scan.hasNextLine()) {
String line = scan.nextLine();
if (line.equals("======= AST Display =========================")) {
line = scan.nextLine();
while(scan.hasNext() && !line.equals("=============================================")) {
ast += line + "\n";
line = scan.nextLine();
}
}
if (line.startsWith("*** "))
System.out.println(line);
if (line.startsWith("ERROR")) {
System.out.println(line);
while(scan.hasNext())
System.out.println(scan.next());
}
}
scan.close();
return ast;
}
}

View File

@ -1,10 +1,7 @@
// Simple PA2 Example
class PA2 {
public boolean c;
private static id[] test;
public static void main(String[] args) {
int x = -1 || 2 + (8 <= 8) == -6 && (9 > 10) * 3;
}
// PA1 lex binop pass
class id {
void p(){
int x = 1 + 2 * 3 / 4 > 5 >= 6 < 7 <= 8 != 9 && 0 || 1;
}
}

View File

@ -0,0 +1,2 @@
// PA1 lex comment fail
class id {} /* unterminated

View File

@ -0,0 +1,2 @@
// PA1 lex ill char fail
class NonTokens{} #

View File

@ -0,0 +1,7 @@
// PA1 lex binop fail
class id {
void p(){
int x = 1 &| 0;
}
}

View File

@ -0,0 +1,5 @@
// PA1 lex trailing start char fail
class Almost {
public static void main (String [] args) {
} // nothing follows next slash
} /

View File

@ -0,0 +1,5 @@
// PA1 lex comment fail
class IllegalComment {
public static void main (String [] args) {
} // nothing follows final *
}/* ****

View File

@ -0,0 +1,6 @@
// PA1 parse field decl fail
class id {
public void [] x;
}

View File

@ -0,0 +1,8 @@
// PA1 parse local decl fail
class id {
void foo() {
Nonesuch x[2] = 3;
}
}

View File

@ -0,0 +1,8 @@
// PA1 parse local decl fail
class id {
public void f(){
Ref [] x(33);
}
}

View File

@ -0,0 +1,8 @@
// PA1 parse local decl fail
class id {
public void f(){
int x;
}
}

View File

@ -0,0 +1,6 @@
// PA1 parse local decl fail
class idfail {
public void foo () {
int [] x[3] = null;
}
}

View File

@ -0,0 +1,6 @@
// PA1 parse local decl fail
class LValueFail {
void foo () {
true = false;
}
}

View File

@ -0,0 +1,6 @@
// PA1 parse expr fail
class IllegalExpressions {
void main () {
z = a+!=b;
}
}

View File

@ -0,0 +1,6 @@
// PA1 parse stmt fail
class IllegalStmt {
void main () {
this;
}
}

View File

@ -0,0 +1,6 @@
// PA1 parse ref fail
class IllegalExpressions {
void foo () {
a b [c] = d; // not ok
}
}

View File

@ -0,0 +1,8 @@
// PA1 parse decl fail
class Test {
void p() {
boolean [] a = b;
}
}

View File

@ -0,0 +1,8 @@
// PA1 parse call fail
class Test {
void p(int a, boolean b) {
int p(a,b);
}
}

View File

@ -0,0 +1,8 @@
// PA1 parse decl fail
class Test {
void p(int a) {
Test [ ] x.y = a;
}
}

View File

@ -0,0 +1,8 @@
// PA1 parse assign fail
class Test {
void p(int a) {
Test [ ] = a * 3;
}
}

View File

@ -0,0 +1,8 @@
// PA1 parse call fail
class Test {
void p(int a) {
c.p(2,3)[3] = 4;
}
}

View File

@ -0,0 +1,8 @@
// PA1 parse assign fail
class Test {
void p() {
x.y() = z;
}
}

View File

@ -0,0 +1,8 @@
// PA1 parse decl fail
class Test {
void p() {
c [] d b = new int[4];
}
}

View File

@ -0,0 +1,4 @@
// PA2 local var decl fail
class A {
int p(){A A A = b;}
}

View File

@ -0,0 +1,7 @@
// PA2 statement after return
class A {
int p(){
return 2;
x = 3;
}
}

View File

@ -0,0 +1,4 @@
// PA2 missing first parameter name
class A {
int p(A [], int b){}
}

View File

@ -0,0 +1,4 @@
// PA2 illegal array type
class A {
int p(void [] x){}
}

View File

@ -0,0 +1,4 @@
// PA2 parameter decl fail
class A {
void foo(x){}
}

View File

@ -0,0 +1,7 @@
// PA2 local var decl fail
class A {
A p(){
private int stuff = 3;
}
}

View File

@ -0,0 +1,7 @@
// PA2 stmt fail
class A {
void p(){
if x
int x = 3;
}
}

View File

@ -0,0 +1,6 @@
// PA2 stmt fail
class A {
void p(){
this;
}
}

View File

@ -0,0 +1,6 @@
// PA2 lex fail
class A {
void f(){
p = p & !p;
}
}

View File

@ -0,0 +1,6 @@
// PA2 expr fail
class A {
void f(){
c = a <=< b;
}
}

View File

@ -0,0 +1,6 @@
// PA2 predecrement fail
class A {
void f(){
c = --b;
}
}

View File

@ -0,0 +1,6 @@
// PA2 expr fail
class A {
void f(){
c = ++b;
}
}

View File

@ -0,0 +1,6 @@
// PA2 stmt fail
class A {
private void p(){
return;
}
}

View File

@ -0,0 +1,6 @@
// PA2 expr fail
class A {
void p(){
int b = c / * d /* */;
}
}

View File

@ -0,0 +1,6 @@
// PA2 expr fail
class A {
void p(){
int b = p ! p;
}
}

View File

@ -0,0 +1,4 @@
// PA2 incorrect reference
class A {
void p(){ x = a.this; }
}

View File

@ -0,0 +1,4 @@
// PA2 incorrect reference
class A {
void p(){ x = this[i]; }
}

View File

@ -0,0 +1,4 @@
// PA2 incorrect reference
class A {
void p(){ x = a[i][j]; }
}

View File

@ -0,0 +1,4 @@
// PA2 incorrect new expr
class A {
void p(){ x = new void [3]; }
}

View File

@ -0,0 +1,4 @@
// PA2 invalid type in parameter declaration
class A {
void p(void [] x){ }
}

View File

@ -0,0 +1,3 @@
// PA1 lex id pass
class id {}

View File

@ -0,0 +1,8 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [0]
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,3 @@
// PA1 lex comment pass
class // comment $$ followed by \r\n
id {}

View File

@ -0,0 +1,8 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [0]
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,2 @@
// PA1 lex comment pass
class id {} // trailing comment terminated by \r\n

View File

@ -0,0 +1,8 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [0]
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,3 @@
// PA1 lex comment pass
class /*/$*/ id {}

View File

@ -0,0 +1,8 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [0]
. MethodDeclList [0]
=============================================

View File

View File

@ -0,0 +1,4 @@
======= AST Display =========================
Package
ClassDeclList [0]
=============================================

View File

@ -0,0 +1,12 @@
// PA1 lex whitespace including tab
class Test {
/* multiple comments between
*/
// tokens
/**//* is OK */
}

View File

@ -0,0 +1,8 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "Test" classname
. FieldDeclList [0]
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,3 @@
// PA1 lex comment pass
class // comment followed by \n only
id {}

View File

@ -0,0 +1,8 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [0]
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,3 @@
// PA1 lex comment pass
class // comment followed by \r only
id {}

View File

@ -0,0 +1,8 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [0]
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,2 @@
// PA1 lex comment pass
class id {} // unterminated comment - no trailing \r\n

View File

@ -0,0 +1,8 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [0]
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,2 @@
// PA1 lex comment pass
class id {} /* no trailing \r\n */

View File

@ -0,0 +1,8 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [0]
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,5 @@
// PA1 parse field decl pass
class id {
public static Type x;
}

View File

@ -0,0 +1,12 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [1]
. . (public static) FieldDecl
. . ClassType
. . "Type" classname
. . "x" fieldname
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,5 @@
// PA1 parse field decl pass
class id {
private static Type x;
}

View File

@ -0,0 +1,12 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [1]
. . (private static) FieldDecl
. . ClassType
. . "Type" classname
. . "x" fieldname
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,5 @@
// PA1 parse field decl pass
class id {
static Type x;
}

View File

@ -0,0 +1,12 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [1]
. . (public static) FieldDecl
. . ClassType
. . "Type" classname
. . "x" fieldname
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,5 @@
// PA1 parse field decl pass
class id {
Type x;
}

View File

@ -0,0 +1,12 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [1]
. . (public) FieldDecl
. . ClassType
. . "Type" classname
. . "x" fieldname
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,5 @@
// PA1 parse field decl pass
class id {
static void x;
}

View File

@ -0,0 +1,11 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [1]
. . (public static) FieldDecl
. . VOID BaseType
. . "x" fieldname
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,5 @@
// PA1 parse method decl pass
class id {
public static void main(String[] args){}
}

View File

@ -0,0 +1,18 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (public static) MethodDecl
. . VOID BaseType
. . "main" methodname
. . ParameterDeclList [1]
. . . ParameterDecl
. . . ArrayType
. . . ClassType
. . . "String" classname
. . . "args"parametername
. . StmtList [0]
=============================================

View File

@ -0,0 +1,5 @@
// PA1 parse method decl pass
class id {
private int f(int x, boolean b) {return 3;}
}

View File

@ -0,0 +1,21 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "id" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (private) MethodDecl
. . INT BaseType
. . "f" methodname
. . ParameterDeclList [2]
. . . ParameterDecl
. . . INT BaseType
. . . "x"parametername
. . . ParameterDecl
. . . BOOLEAN BaseType
. . . "b"parametername
. . StmtList [0]
. . LiteralExpr
. . "3" IntLiteral
=============================================

View File

@ -0,0 +1,9 @@
// PA1 parse classdecls pass
class MainClass {
public static void main (String [] args) {}
}
class OfItsOwn {
int A_01;
} // class OfItsOwn

View File

@ -0,0 +1,25 @@
======= AST Display =========================
Package
ClassDeclList [2]
. ClassDecl
. "MainClass" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (public static) MethodDecl
. . VOID BaseType
. . "main" methodname
. . ParameterDeclList [1]
. . . ParameterDecl
. . . ArrayType
. . . ClassType
. . . "String" classname
. . . "args"parametername
. . StmtList [0]
. ClassDecl
. "OfItsOwn" classname
. FieldDeclList [1]
. . (public) FieldDecl
. . INT BaseType
. . "A_01" fieldname
. MethodDeclList [0]
=============================================

View File

@ -0,0 +1,8 @@
// PA1 parse new pass
class MainClass {
public static void main (String [] args) {
SecondSubClass newobj = new SecondSubClass ();
}
}

View File

@ -0,0 +1,26 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "MainClass" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (public static) MethodDecl
. . VOID BaseType
. . "main" methodname
. . ParameterDeclList [1]
. . . ParameterDecl
. . . ArrayType
. . . ClassType
. . . "String" classname
. . . "args"parametername
. . StmtList [1]
. . . VarDeclStmt
. . . VarDecl
. . . ClassType
. . . "SecondSubClass" classname
. . . "newobj" varname
. . . NewObjectExpr
. . . ClassType
. . . "SecondSubClass" classname
=============================================

View File

@ -0,0 +1,8 @@
// PA1 parse new pass
class Foo {
void bar() {
int[] newarr = new int[20];
}
}

View File

@ -0,0 +1,22 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "Foo" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (public) MethodDecl
. . VOID BaseType
. . "bar" methodname
. . ParameterDeclList [0]
. . StmtList [1]
. . . VarDeclStmt
. . . VarDecl
. . . ArrayType
. . . INT BaseType
. . . "newarr" varname
. . . NewArrayExpr
. . . INT BaseType
. . . LiteralExpr
. . . "20" IntLiteral
=============================================

View File

@ -0,0 +1,23 @@
// PA1 parse methods pass
class MainClass {
public static void main (String [] args) {
}
}
class SuperClass
{
public void setWorth (int worth){
integer = worth;
}
public int getWorth (){
return this.integer;
}
public void setTruth (boolean truth){
bool = truth;
}
public int getTruth (){
return this.bool;
}
}

View File

@ -0,0 +1,68 @@
======= AST Display =========================
Package
ClassDeclList [2]
. ClassDecl
. "MainClass" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (public static) MethodDecl
. . VOID BaseType
. . "main" methodname
. . ParameterDeclList [1]
. . . ParameterDecl
. . . ArrayType
. . . ClassType
. . . "String" classname
. . . "args"parametername
. . StmtList [0]
. ClassDecl
. "SuperClass" classname
. FieldDeclList [0]
. MethodDeclList [4]
. . (public) MethodDecl
. . VOID BaseType
. . "setWorth" methodname
. . ParameterDeclList [1]
. . . ParameterDecl
. . . INT BaseType
. . . "worth"parametername
. . StmtList [1]
. . . AssignStmt
. . . IdRef
. . . "integer" Identifier
. . . RefExpr
. . . IdRef
. . . "worth" Identifier
. . (public) MethodDecl
. . INT BaseType
. . "getWorth" methodname
. . ParameterDeclList [0]
. . StmtList [0]
. . RefExpr
. . QualifiedRef
. . "integer" Identifier
. . ThisRef
. . (public) MethodDecl
. . VOID BaseType
. . "setTruth" methodname
. . ParameterDeclList [1]
. . . ParameterDecl
. . . BOOLEAN BaseType
. . . "truth"parametername
. . StmtList [1]
. . . AssignStmt
. . . IdRef
. . . "bool" Identifier
. . . RefExpr
. . . IdRef
. . . "truth" Identifier
. . (public) MethodDecl
. . INT BaseType
. . "getTruth" methodname
. . ParameterDeclList [0]
. . StmtList [0]
. . RefExpr
. . QualifiedRef
. . "bool" Identifier
. . ThisRef
=============================================

View File

@ -0,0 +1,21 @@
// PA1 parse parse pass
class MainClass {
public static void main (String [] args) {
SecondSubClass newobj = new SecondSubClass ();
}
}
class SuperClass
{
private void fillup (boolean open, int [] jar, int marble, int upto) {
int index = 0;
if (open == true) {
while ( index < upto ) {
ownjar [index] = jar [index];
jar [index] = marble;
} // while
} // if
} // fillup
} // class SuperClass

View File

@ -0,0 +1,99 @@
======= AST Display =========================
Package
ClassDeclList [2]
. ClassDecl
. "MainClass" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (public static) MethodDecl
. . VOID BaseType
. . "main" methodname
. . ParameterDeclList [1]
. . . ParameterDecl
. . . ArrayType
. . . ClassType
. . . "String" classname
. . . "args"parametername
. . StmtList [1]
. . . VarDeclStmt
. . . VarDecl
. . . ClassType
. . . "SecondSubClass" classname
. . . "newobj" varname
. . . NewObjectExpr
. . . ClassType
. . . "SecondSubClass" classname
. ClassDecl
. "SuperClass" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (private) MethodDecl
. . VOID BaseType
. . "fillup" methodname
. . ParameterDeclList [4]
. . . ParameterDecl
. . . BOOLEAN BaseType
. . . "open"parametername
. . . ParameterDecl
. . . ArrayType
. . . INT BaseType
. . . "jar"parametername
. . . ParameterDecl
. . . INT BaseType
. . . "marble"parametername
. . . ParameterDecl
. . . INT BaseType
. . . "upto"parametername
. . StmtList [2]
. . . VarDeclStmt
. . . VarDecl
. . . INT BaseType
. . . "index" varname
. . . LiteralExpr
. . . "0" IntLiteral
. . . IfStmt
. . . BinaryExpr
. . . "==" Operator
. . . RefExpr
. . . IdRef
. . . "open" Identifier
. . . LiteralExpr
. . . "true" BooleanLiteral
. . . BlockStmt
. . . StatementList [1]
. . . . WhileStmt
. . . . BinaryExpr
. . . . "<" Operator
. . . . RefExpr
. . . . IdRef
. . . . "index" Identifier
. . . . RefExpr
. . . . IdRef
. . . . "upto" Identifier
. . . . BlockStmt
. . . . StatementList [2]
. . . . . AssignStmt
. . . . . IndexedRef
. . . . . RefExpr
. . . . . IdRef
. . . . . "index" Identifier
. . . . . IdRef
. . . . . "ownjar" Identifier
. . . . . RefExpr
. . . . . IndexedRef
. . . . . RefExpr
. . . . . IdRef
. . . . . "index" Identifier
. . . . . IdRef
. . . . . "jar" Identifier
. . . . . AssignStmt
. . . . . IndexedRef
. . . . . RefExpr
. . . . . IdRef
. . . . . "index" Identifier
. . . . . IdRef
. . . . . "jar" Identifier
. . . . . RefExpr
. . . . . IdRef
. . . . . "marble" Identifier
=============================================

View File

@ -0,0 +1,6 @@
// PA1 parse Stmt this ref pass
class LegalStmt {
void main () {
this(3,4);
}
}

View File

@ -0,0 +1,20 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "LegalStmt" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (public) MethodDecl
. . VOID BaseType
. . "main" methodname
. . ParameterDeclList [0]
. . StmtList [1]
. . . CallStmt
. . . ThisRef
. . . ExprList [2]
. . . . LiteralExpr
. . . . "3" IntLiteral
. . . . LiteralExpr
. . . . "4" IntLiteral
=============================================

View File

@ -0,0 +1,12 @@
// PA1 parse refs pass
class Test {
void p() {
a = true;
a [b] = c;
p ();
a.b[3] = d;
c.p(e);
}
}

View File

@ -0,0 +1,52 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "Test" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (public) MethodDecl
. . VOID BaseType
. . "p" methodname
. . ParameterDeclList [0]
. . StmtList [5]
. . . AssignStmt
. . . IdRef
. . . "a" Identifier
. . . LiteralExpr
. . . "true" BooleanLiteral
. . . AssignStmt
. . . IndexedRef
. . . RefExpr
. . . IdRef
. . . "b" Identifier
. . . IdRef
. . . "a" Identifier
. . . RefExpr
. . . IdRef
. . . "c" Identifier
. . . CallStmt
. . . IdRef
. . . "p" Identifier
. . . ExprList [0]
. . . AssignStmt
. . . IndexedRef
. . . LiteralExpr
. . . "3" IntLiteral
. . . QualifiedRef
. . . "b" Identifier
. . . IdRef
. . . "a" Identifier
. . . RefExpr
. . . IdRef
. . . "d" Identifier
. . . CallStmt
. . . QualifiedRef
. . . "p" Identifier
. . . IdRef
. . . "c" Identifier
. . . ExprList [1]
. . . . RefExpr
. . . . IdRef
. . . . "e" Identifier
=============================================

View File

@ -0,0 +1,11 @@
// PA1 parse decl pass
class Test {
int [] a;
Test [] t;
void p() {
void x = y;
}
}

View File

@ -0,0 +1,29 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "Test" classname
. FieldDeclList [2]
. . (public) FieldDecl
. . ArrayType
. . INT BaseType
. . "a" fieldname
. . (public) FieldDecl
. . ArrayType
. . ClassType
. . "Test" classname
. . "t" fieldname
. MethodDeclList [1]
. . (public) MethodDecl
. . VOID BaseType
. . "p" methodname
. . ParameterDeclList [0]
. . StmtList [1]
. . . VarDeclStmt
. . . VarDecl
. . . VOID BaseType
. . . "x" varname
. . . RefExpr
. . . IdRef
. . . "y" Identifier
=============================================

View File

@ -0,0 +1,9 @@
// PA1 parse refs pass
class Test {
void p() {
A a = 23;
boolean b = c;
}
}

View File

@ -0,0 +1,27 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "Test" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (public) MethodDecl
. . VOID BaseType
. . "p" methodname
. . ParameterDeclList [0]
. . StmtList [2]
. . . VarDeclStmt
. . . VarDecl
. . . ClassType
. . . "A" classname
. . . "a" varname
. . . LiteralExpr
. . . "23" IntLiteral
. . . VarDeclStmt
. . . VarDecl
. . . BOOLEAN BaseType
. . . "b" varname
. . . RefExpr
. . . IdRef
. . . "c" Identifier
=============================================

View File

@ -0,0 +1,8 @@
// PA1 parse assign pass
class Test {
void p() {
a = b;
}
}

View File

@ -0,0 +1,19 @@
======= AST Display =========================
Package
ClassDeclList [1]
. ClassDecl
. "Test" classname
. FieldDeclList [0]
. MethodDeclList [1]
. . (public) MethodDecl
. . VOID BaseType
. . "p" methodname
. . ParameterDeclList [0]
. . StmtList [1]
. . . AssignStmt
. . . IdRef
. . . "a" Identifier
. . . RefExpr
. . . IdRef
. . . "b" Identifier
=============================================

View File

@ -0,0 +1,8 @@
// PA1 parse call pass
class Test {
void p(int a, boolean b) {
p(a,b);
}
}

Some files were not shown because too many files have changed in this diff Show More