commit 983f4cd852fcc2511de1f186f59d82afe7173aed Author: Joshua Potter Date: Sat Feb 15 21:00:29 2014 -0500 Recursive Descent Parsing Implemented tokenizer/scanner and recursive descent parser. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9d6bd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,215 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/docs/PA1.pdf b/docs/PA1.pdf new file mode 100644 index 0000000..b934180 Binary files /dev/null and b/docs/PA1.pdf differ diff --git a/miniJava/src/miniJava/Compiler.java b/miniJava/src/miniJava/Compiler.java new file mode 100644 index 0000000..40fe744 --- /dev/null +++ b/miniJava/src/miniJava/Compiler.java @@ -0,0 +1,35 @@ +package miniJava; + +import java.io.*; +import miniJava.SyntacticAnalyzer.*; + +public class Compiler { + + private static final int rc = 4; + + public static void main(String[] args) { + + if(args.length == 0) { + System.out.println("No file specified"); + System.exit(rc); + } + + try(FileReader input = new FileReader(args[0])) { + + Scanner scanner = new Scanner(new BufferedReader(input)); + Parser parser = new Parser(scanner); + parser.parse(); + + System.out.println("Works"); + System.exit(0); + + } catch(FileNotFoundException e) { + System.out.println("Not Found"); + System.exit(rc); + } catch(IOException e) { + System.out.println("Not Works"); + System.exit(rc); + } + } + +} diff --git a/miniJava/src/miniJava/SyntacticAnalyzer/Parser.java b/miniJava/src/miniJava/SyntacticAnalyzer/Parser.java new file mode 100644 index 0000000..068cf4b --- /dev/null +++ b/miniJava/src/miniJava/SyntacticAnalyzer/Parser.java @@ -0,0 +1,409 @@ +package miniJava.SyntacticAnalyzer; + +import java.io.*; +import java.util.LinkedList; + +public class Parser { + + private Scanner scanner; + private LinkedList stream; + + public Parser(Scanner scanner) { + this.scanner = scanner; + this.stream = new LinkedList(); + } + + + /** + * Program ::= (ClassDeclaration)* eot + * @throws IOException + */ + public void parse() throws IOException { + while(peek(1).type == Token.TYPE.CLASS) parseClassDeclaration(); + accept(Token.TYPE.EOT); + } + + + /** + * ClassDeclaration ::= + * class id { + * (Declarators id (; | MethodDeclaration))* + * } + * @throws IOException + */ + private void parseClassDeclaration() throws IOException { + + // Class Header + accept(Token.TYPE.CLASS); + accept(Token.TYPE.ID); + accept(Token.TYPE.LBRACKET); + + // Class Body + while(peek(1).type != Token.TYPE.RBRACKET) { + parseDeclarators(); + accept(Token.TYPE.ID); + if(peek(1).type == Token.TYPE.SEMICOLON) accept(Token.TYPE.SEMICOLON); + else parseMethodDeclaration(); + } + + accept(Token.TYPE.RBRACKET); + } + + + /** + * MethodDeclaration ::= + * (ParameterList?) { + * Statement* (return Expression ;)? + * } + * @throws IOException + */ + private void parseMethodDeclaration() throws IOException { + + // Method Header + accept(Token.TYPE.LPAREN); + if(peek(1).type != Token.TYPE.RPAREN) parseParameterList(); + accept(Token.TYPE.RPAREN); + accept(Token.TYPE.LBRACKET); + + // Method Body + while(peek(1).type != Token.TYPE.RBRACKET) { + + if(peek(1).type == Token.TYPE.RETURN) { + accept(Token.TYPE.RETURN); + parseExpression(); + accept(Token.TYPE.SEMICOLON); + break; + } + + parseStatement(); + } + + accept(Token.TYPE.RBRACKET); + } + + + /** + * Declarators ::= (public | private)? static? Type + * @throws IOException + */ + private void parseDeclarators() throws IOException { + + if(peek(1).type == Token.TYPE.PUBLIC) accept(Token.TYPE.PUBLIC); + else if(peek(1).type == Token.TYPE.PRIVATE) accept(Token.TYPE.PRIVATE); + + if(peek(1).type == Token.TYPE.STATIC) accept(Token.TYPE.STATIC); + parseType(); + } + + + /** + * Type ::= boolean | void | int ([])? | id ([])? + * @throws IOException + */ + private void parseType() throws IOException { + + Token.TYPE type = peek(1).type; + + switch(type) { + + case BOOLEAN: + case VOID: + accept(type); + break; + + case INT: + case ID: + accept(type); + if(peek(1).type == Token.TYPE.LSQUARE) { + accept(Token.TYPE.LSQUARE); + accept(Token.TYPE.RSQUARE); + } + break; + + default: + throw new IOException(); + } + } + + + /** + * ParameterList ::= Type id (, Type id)* + * @throws IOException + */ + private void parseParameterList() throws IOException { + parseType(); + accept(Token.TYPE.ID); + while(peek(1).type == Token.TYPE.COMMA) { + accept(Token.TYPE.COMMA); + parseType(); + accept(Token.TYPE.ID); + } + } + + + /** + * ArgumentList ::= Expression (, Expression)* + * @throws IOException + */ + private void parseArgumentList() throws IOException { + parseExpression(); + while(peek(1).type == Token.TYPE.COMMA) { + accept(Token.TYPE.COMMA); + parseExpression(); + } + } + + + /** + * Reference ::= BaseRef (. BaseRef)* + * @throws IOException + */ + private void parseReference() throws IOException { + parseBaseRef(); + while(peek(1).type == Token.TYPE.PERIOD) { + accept(Token.TYPE.PERIOD); + accept(Token.TYPE.ID); + if(peek(1).type == Token.TYPE.LSQUARE) { + accept(Token.TYPE.LSQUARE); + parseExpression(); + accept(Token.TYPE.RSQUARE); + } + } + } + + + /** + * BaseRef ::= this | id ([ Expression])? + * @throws IOException + */ + private void parseBaseRef() throws IOException { + + switch(peek(1).type) { + + // this + case THIS: + accept(Token.TYPE.THIS); + break; + + // id ([ Expression])? + default: + accept(Token.TYPE.ID); + if(peek(1).type == Token.TYPE.LSQUARE) { + accept(Token.TYPE.LSQUARE); + parseExpression(); + accept(Token.TYPE.RSQUARE); + } + break; + } + } + + + /** + * Statement ::= + * {Statement*} + * | Type id = Expression; + * | Reference = Expression; + * | Reference ( ArgumentList? ); + * | if (Expression) Statement (else Statement)? + * | while (Expression) Statement + * @throws IOException + */ + private void parseStatement() throws IOException { + + switch(peek(1).type) { + + // { Statement* } + case LBRACKET: + accept(Token.TYPE.LBRACKET); + while(peek(1).type != Token.TYPE.RBRACKET) { + parseStatement(); + } + accept(Token.TYPE.RBRACKET); + break; + + // if (Expression) Statement (else Statement)? + case IF: + accept(Token.TYPE.IF); + accept(Token.TYPE.LPAREN); + parseExpression(); + accept(Token.TYPE.RPAREN); + parseStatement(); + if(peek(1).type == Token.TYPE.ELSE) { + accept(Token.TYPE.ELSE); + parseStatement(); + } + break; + + // while (Expression) Statement + case WHILE: + accept(Token.TYPE.WHILE); + accept(Token.TYPE.LPAREN); + parseExpression(); + accept(Token.TYPE.RPAREN); + parseStatement(); + break; + + // Type id = Expression ; + case BOOLEAN: + case VOID: + case INT: + case ID: + + // Must be a type though there is a possibility of a reference + if(peek(1).type != Token.TYPE.ID + || peek(2).type == Token.TYPE.ID + ||(peek(2).type == Token.TYPE.LSQUARE && peek(3).type == Token.TYPE.RSQUARE)) { + parseType(); + accept(Token.TYPE.ID); + accept(Token.TYPE.EQUALS); + parseExpression(); + accept(Token.TYPE.SEMICOLON); + break; + } + + /* Fall Through */ + + // Reference = Expression ; | Reference ( ArgumentList? ) ; + default: + parseReference(); + + if(peek(1).type == Token.TYPE.LPAREN) { + accept(Token.TYPE.LPAREN); + if(peek(1).type != Token.TYPE.RPAREN) parseArgumentList(); + accept(Token.TYPE.RPAREN); + } else { + accept(Token.TYPE.EQUALS); + parseExpression(); + } + + accept(Token.TYPE.SEMICOLON); + break; + } + } + + + /** + * Expression ::= + * Reference + * | Reference ( ArgumentList? ) + * | unop Expression + * | Expression binop Expression + * | ( Expression ) + * | num | true | false + * | new (id() | int [ Expression ] | id [ Expression ] ) + * @throws IOException + */ + private void parseExpression() throws IOException { + + switch(peek(1).type) { + + // num | true | false + case NUM: + case TRUE: + case FALSE: + accept(peek(1).type); + break; + + // ( Expression ) + case LPAREN: + accept(Token.TYPE.LPAREN); + parseExpression(); + accept(Token.TYPE.RPAREN); + break; + + // unop Expression + case UNOP: + accept(Token.TYPE.UNOP); + parseExpression(); + break; + + // Must be a minus sign + case BINOP: + if(peek(1).attr.equals("-")) { + accept(Token.TYPE.BINOP); + parseExpression(); + } + else throw new IOException(); + break; + + // new ( int [ Expression ] | id ( ) | id [ Expression ] ) + case NEW: + accept(Token.TYPE.NEW); + + if(peek(1).type == Token.TYPE.INT) { + accept(Token.TYPE.INT); + accept(Token.TYPE.LSQUARE); + parseExpression(); + accept(Token.TYPE.RSQUARE); + } + + else { + accept(Token.TYPE.ID); + + if(peek(1).type == Token.TYPE.LPAREN){ + accept(Token.TYPE.LPAREN); + accept(Token.TYPE.RPAREN); + } + + else { + accept(Token.TYPE.LSQUARE); + parseExpression(); + accept(Token.TYPE.RSQUARE); + } + } + + break; + + // Reference | Reference (ArgumentList?) + case THIS: + case ID: + parseReference(); + if(peek(1).type == Token.TYPE.LPAREN) { + accept(Token.TYPE.LPAREN); + if(peek(1).type != Token.TYPE.RPAREN) parseArgumentList(); + accept(Token.TYPE.RPAREN); + } + break; + + // Expression binop Expression + default: + accept(Token.TYPE.BINOP); + parseExpression(); + break; + } + + // Expression binop Expression + if(peek(1).type == Token.TYPE.BINOP) { + accept(Token.TYPE.BINOP); + parseExpression(); + } + } + + + /** + * Sees what the next token is, caching the result. + * @return + * @throws IOException + */ + private Token peek(int lookahead) throws IOException { + + // Cache tokens + while(stream.size() < lookahead) { + Token next = scanner.scan(); + stream.addLast(next); + } + + return stream.get(lookahead - 1); + } + + + /** + * Consumes token or throws exception. + * @throws IOException + */ + private void accept(Token.TYPE type) throws IOException { + Token next = peek(1); + if(next.type == type) stream.poll(); + else throw new IOException(); + } +} diff --git a/miniJava/src/miniJava/SyntacticAnalyzer/Scanner.java b/miniJava/src/miniJava/SyntacticAnalyzer/Scanner.java new file mode 100644 index 0000000..49cb14d --- /dev/null +++ b/miniJava/src/miniJava/SyntacticAnalyzer/Scanner.java @@ -0,0 +1,249 @@ +package miniJava.SyntacticAnalyzer; + +import java.io.*; + +public class Scanner { + + private BufferedReader input; + + public Scanner(BufferedReader input) { + this.input = input; + } + + /** + * Scans in input, returning next token. + * @return + * @throws IOException + */ + public Token scan() throws IOException { + + String attr = ""; + Token token = null; + + while(token == null) { + + // Check for EOF + int c = input.read(); + if(c == -1) return new Token("", Token.TYPE.EOT); + + // Setup + attr += (char) c; + + switch(c) { + + // Operators + case '+': + case '*': + case '-': + token = new Token(attr, Token.TYPE.BINOP); + break; + + // Check for comment + case '/': + if(peek('*')) { input.read(); readComment(); attr = ""; } + else if(peek('/')) { readLine(); attr = ""; } + else token = new Token(attr, Token.TYPE.BINOP); + break; + + // Check for c or c= + case '>': + case '<': + if(peek('=')) attr += (char) input.read(); + token = new Token(attr, Token.TYPE.BINOP); + break; + + // Check for ! or != + case '!': + if(!peek('=')) token = new Token(attr, Token.TYPE.UNOP); + else { + attr += (char) input.read(); + token = new Token(attr, Token.TYPE.BINOP); + } + break; + + // Check for && or || + case '&': + case '|': + if(!peek((char) c)) throw new IOException(); + else { + attr += (char) input.read(); + token = new Token(attr, Token.TYPE.BINOP); + } + break; + + // Other Operators + case '=': + if(!peek('=')) token = new Token(attr, Token.TYPE.EQUALS); + else { + attr += (char) input.read(); + token = new Token(attr, Token.TYPE.BINOP); + } + break; + + case '.': + token = new Token(attr, Token.TYPE.PERIOD); + break; + + case ',': + token = new Token(attr, Token.TYPE.COMMA); + break; + + case '[': + token = new Token(attr, Token.TYPE.LSQUARE); + break; + + case ']': + token = new Token(attr, Token.TYPE.RSQUARE); + break; + + case '{': + token = new Token(attr, Token.TYPE.LBRACKET); + break; + + case '}': + token = new Token(attr, Token.TYPE.RBRACKET); + break; + + case '(': + token = new Token(attr, Token.TYPE.LPAREN); + break; + + case ')': + token = new Token(attr, Token.TYPE.RPAREN); + break; + + case ';': + token = new Token(attr, Token.TYPE.SEMICOLON); + break; + + default: + + // Identifier or Keyword + if(isAlpha((char) c)) { + for(char n = peek(); isAlpha(n) || isDigit(n) || n == '_';) { + attr += (char) input.read(); + n = peek(); + } + + if(Token.keywords.containsKey(attr)) { + token = new Token(attr, Token.keywords.get(attr)); + } else { + token = new Token(attr, Token.TYPE.ID); + } + } + + // Number + else if(isDigit((char) c)) { + for(char n = peek(); isDigit(n);) { + attr += (char) input.read(); + n = peek(); + } + + token = new Token(attr, Token.TYPE.NUM); + } + + // Whitespace + else if(isWhitespace((char) c)) { + attr = ""; + } + + // Unrecognized Character + else throw new IOException(); + + break; + } + } + System.out.println(token.type); + return token; + } + + + /** + * Looks at next character in stream without consuming. + * @return + * @throws IOException + */ + private char peek() throws IOException { + input.mark(1); + int next = input.read(); + input.reset(); + + return next == -1 ? '\0' : (char) next; + } + + + /** + * Returns whether passed character is next in stream. + * @param c + * @return + * @throws IOException + */ + private boolean peek(char c) throws IOException { + input.mark(1); + int next = input.read(); + input.reset(); + + return c == next; + } + + + /** + * Consumes input until an end of comment has been reached. + * @throws IOException + */ + private void readComment() throws IOException { + char prev = '\0', current = '\0'; + while(prev != '*' || current != '/') { + + prev = current; + + int next = input.read(); + if(next == -1) throw new IOException(); + else current = (char) next; + } + } + + + /** + * Consumes input until the end of line is reached + * @throws IOException + */ + private void readLine() throws IOException { + for(int n = 0; n != '\n' && n != '\r' && n != -1; n = input.read()) {} + } + + + /** + * Tells whether character is alphabetical. + * @param c + * @return + */ + private boolean isAlpha(char c) { + return (c >= 'a' && c <= 'z') + || (c >= 'A' && c <= 'Z'); + } + + + /** + * Tells whether character is numerical. + * @param c + * @return + */ + private boolean isDigit(char c) { + return c >= '0' && c <= '9'; + } + + + /** + * Tells wheter character is whitespace. + * @param c + * @return + */ + private boolean isWhitespace(char c) { + return c == ' ' + || c == '\n' + || c == '\r' + || c == '\t'; + } + +} diff --git a/miniJava/src/miniJava/SyntacticAnalyzer/Token.java b/miniJava/src/miniJava/SyntacticAnalyzer/Token.java new file mode 100644 index 0000000..f2593b2 --- /dev/null +++ b/miniJava/src/miniJava/SyntacticAnalyzer/Token.java @@ -0,0 +1,78 @@ +package miniJava.SyntacticAnalyzer; + +import java.util.HashMap; + +public class Token { + + public enum TYPE { + + // Possible Terminals + ID, + NUM, + UNOP, + BINOP, + + // Keywords + IF, + ELSE, + NEW, + INT, + VOID, + THIS, + TRUE, + FALSE, + CLASS, + WHILE, + RETURN, + BOOLEAN, + + // Declarators + STATIC, + PUBLIC, + PRIVATE, + + // Other Terminals + EQUALS, + PERIOD, + COMMA, + LPAREN, + RPAREN, + LSQUARE, + RSQUARE, + LBRACKET, + RBRACKET, + SEMICOLON, + + // End of Token Stream + EOT + }; + + public final static HashMap keywords; + static + { + keywords = new HashMap(); + keywords.put("class", TYPE.CLASS); + keywords.put("return", TYPE.RETURN); + keywords.put("public", TYPE.PUBLIC); + keywords.put("private", TYPE.PRIVATE); + keywords.put("static", TYPE.STATIC); + keywords.put("int", TYPE.INT); + keywords.put("boolean", TYPE.BOOLEAN); + keywords.put("void", TYPE.VOID); + keywords.put("this", TYPE.THIS); + keywords.put("if", TYPE.IF); + keywords.put("else", TYPE.ELSE); + keywords.put("while", TYPE.WHILE); + keywords.put("true", TYPE.TRUE); + keywords.put("false", TYPE.FALSE); + keywords.put("new", TYPE.NEW); + } + + public final TYPE type; + public final String attr; + + public Token(String attr, TYPE type) { + this.type = type; + this.attr = attr; + } +} diff --git a/miniJava/src/miniJava/SyntacticAnalyzer/grammar.txt b/miniJava/src/miniJava/SyntacticAnalyzer/grammar.txt new file mode 100644 index 0000000..0cf2bc3 --- /dev/null +++ b/miniJava/src/miniJava/SyntacticAnalyzer/grammar.txt @@ -0,0 +1,40 @@ +Program ::= (ClassDeclaration)* eot + +ClassDeclaration ::= + class id { + (Declarators id (; | MethodDeclaration))* + } + +MethodDeclaration ::= + (ParameterList?) { + Statement* (return Expression ;)? + } + +Declarators ::= (public | private)? static? Type + +Type ::= boolean | void | int ([])? | id ([])? + +ParameterList ::= Type id (, Type id)* + +ArgumentList ::= Expression (, Expression)* + +Reference ::= BaseRef (. id ([ Expression])?)* + +BaseRef ::= this | id ([ Expression])? + +Statement ::= + {Statement*} + | Type id = Expression; + | Reference = Expression; + | Reference ( ArgumentList? ); + | if (Expression) Statement (else Statement)? + | while (Expression) Statement + +Expression ::= + Reference + | Reference ( ArgumentList? ) + | unop Expression + | Expression binop Expression + | ( Expression ) + | num | true | false + | new (id() | int [ Expression ] | id [ Expression ] ) \ No newline at end of file diff --git a/miniJava/src/tester/Checkpoint1.java b/miniJava/src/tester/Checkpoint1.java new file mode 100644 index 0000000..2798140 --- /dev/null +++ b/miniJava/src/tester/Checkpoint1.java @@ -0,0 +1,71 @@ +package tester; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Scanner; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/* Automated regression tester for Checkpoint 1 tests + * Created by Max Beckman-Harned + * Put your tests in "tests/pa1_tests" folder in your Eclipse workspace directory + */ +public class Checkpoint1 { + + static ExecutorService threadPool = Executors.newCachedThreadPool(); + + public static void main(String[] args) throws IOException, InterruptedException { + File testDir = new File(System.getProperty("java.class.path") + "/../tests/pa1_tests"); + System.out.println(testDir.getAbsolutePath()); + int failures = 0; + for (File x : testDir.listFiles()) { + int returnCode = runTest(x); + if (x.getName().indexOf("pass") != -1) { + if (returnCode == 0) + System.out.println(x.getName() + " passed successfully!"); + else { + failures++; + System.err.println(x.getName() + + " failed but should have passed!"); + } + } 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 int runTest(File x) throws IOException, InterruptedException { + ProcessBuilder pb = new ProcessBuilder("java", "miniJava.Compiler", x.getPath()).directory(new File(System.getProperty("java.class.path"))); + Process p = pb.start(); + threadPool.execute(new ProcessOutputter(p.getInputStream(), false)); + p.waitFor(); + return p.exitValue(); + } + + static class ProcessOutputter implements Runnable { + private Scanner processOutput; + private boolean output; + + public ProcessOutputter(InputStream _processStream, boolean _output) { + processOutput = new Scanner(_processStream); + output = _output; + } + @Override + public void run() { + while(processOutput.hasNextLine()) { + String line = processOutput.nextLine(); + if (output) + System.out.println(line); + } + } + + + } +} diff --git a/miniJava/test.java b/miniJava/test.java new file mode 100644 index 0000000..eb38ef4 --- /dev/null +++ b/miniJava/test.java @@ -0,0 +1,7 @@ +// PA1 parse assign fail +class Test { + + void p(int a) { + that.this = 4; + } +} \ No newline at end of file diff --git a/miniJava/tests/pa1_tests/fail101.java b/miniJava/tests/pa1_tests/fail101.java new file mode 100644 index 0000000..bef9a56 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail101.java @@ -0,0 +1,2 @@ +// PA1 lex id fail +class _id {} diff --git a/miniJava/tests/pa1_tests/fail102.java b/miniJava/tests/pa1_tests/fail102.java new file mode 100644 index 0000000..2e6101b --- /dev/null +++ b/miniJava/tests/pa1_tests/fail102.java @@ -0,0 +1,2 @@ +// PA1 lex id fail +class boolean {} diff --git a/miniJava/tests/pa1_tests/fail103.java b/miniJava/tests/pa1_tests/fail103.java new file mode 100644 index 0000000..82e3c80 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail103.java @@ -0,0 +1,2 @@ +// PA1 parse fail +class Foo {}. \ No newline at end of file diff --git a/miniJava/tests/pa1_tests/fail104.java b/miniJava/tests/pa1_tests/fail104.java new file mode 100644 index 0000000..d92c716 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail104.java @@ -0,0 +1,2 @@ +// PA1 lex id fail +class true {} diff --git a/miniJava/tests/pa1_tests/fail117.java b/miniJava/tests/pa1_tests/fail117.java new file mode 100644 index 0000000..51c7eaf --- /dev/null +++ b/miniJava/tests/pa1_tests/fail117.java @@ -0,0 +1,2 @@ +// PA1 lex comment fail +class id {} /* unterminated diff --git a/miniJava/tests/pa1_tests/fail118.java b/miniJava/tests/pa1_tests/fail118.java new file mode 100644 index 0000000..ca9bf28 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail118.java @@ -0,0 +1,3 @@ +// PA1 lex comment fail +class /* /* nested */ */ id {} + diff --git a/miniJava/tests/pa1_tests/fail119.java b/miniJava/tests/pa1_tests/fail119.java new file mode 100644 index 0000000..9c6137f --- /dev/null +++ b/miniJava/tests/pa1_tests/fail119.java @@ -0,0 +1,2 @@ +// PA1 lex ill char fail +class NonTokens{} # diff --git a/miniJava/tests/pa1_tests/fail125.java b/miniJava/tests/pa1_tests/fail125.java new file mode 100644 index 0000000..935b0ea --- /dev/null +++ b/miniJava/tests/pa1_tests/fail125.java @@ -0,0 +1,7 @@ +// PA1 lex binop fail +class id { + void p(){ + int x = 1 &| 0; + } +} + diff --git a/miniJava/tests/pa1_tests/fail126.java b/miniJava/tests/pa1_tests/fail126.java new file mode 100644 index 0000000..826a67f --- /dev/null +++ b/miniJava/tests/pa1_tests/fail126.java @@ -0,0 +1,7 @@ +// PA1 lex binop fail +class id { + void p(){ + x = 1 + 2*3 = 4; + } +} + diff --git a/miniJava/tests/pa1_tests/fail127.java b/miniJava/tests/pa1_tests/fail127.java new file mode 100644 index 0000000..2b09ac6 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail127.java @@ -0,0 +1,7 @@ +// PA1 lex/parse binop fail +class id { + void p(){ + int x = 1 >> 0; + } +} + diff --git a/miniJava/tests/pa1_tests/fail128.java b/miniJava/tests/pa1_tests/fail128.java new file mode 100644 index 0000000..b8aec5e --- /dev/null +++ b/miniJava/tests/pa1_tests/fail128.java @@ -0,0 +1,7 @@ +// PA1 lex binop fail +class id { + void p(){ + while ( 1 > = 0) {} + } +} + diff --git a/miniJava/tests/pa1_tests/fail130.java b/miniJava/tests/pa1_tests/fail130.java new file mode 100644 index 0000000..11ded62 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail130.java @@ -0,0 +1,5 @@ +// PA1 lex trailing start char fail +class Almost { + public static void main (String [] args) { + } // nothing follows next slash +} / \ No newline at end of file diff --git a/miniJava/tests/pa1_tests/fail131.java b/miniJava/tests/pa1_tests/fail131.java new file mode 100644 index 0000000..bd14a4f --- /dev/null +++ b/miniJava/tests/pa1_tests/fail131.java @@ -0,0 +1,5 @@ +// PA1 lex comment fail +class IllegalComment { + public static void main (String [] args) { + } // nothing follows final * +}/* **** \ No newline at end of file diff --git a/miniJava/tests/pa1_tests/fail140.java b/miniJava/tests/pa1_tests/fail140.java new file mode 100644 index 0000000..1c2e42f --- /dev/null +++ b/miniJava/tests/pa1_tests/fail140.java @@ -0,0 +1,6 @@ +// PA1 parse field decl fail +class id { + static private Type x; +} + + diff --git a/miniJava/tests/pa1_tests/fail141.java b/miniJava/tests/pa1_tests/fail141.java new file mode 100644 index 0000000..c80863f --- /dev/null +++ b/miniJava/tests/pa1_tests/fail141.java @@ -0,0 +1,6 @@ +// PA1 parse field decl fail +class id { + public private static Type x; +} + + diff --git a/miniJava/tests/pa1_tests/fail142.java b/miniJava/tests/pa1_tests/fail142.java new file mode 100644 index 0000000..01a3966 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail142.java @@ -0,0 +1,6 @@ +// PA1 parse field decl fail +class id { + int x = 3; +} + + diff --git a/miniJava/tests/pa1_tests/fail143.java b/miniJava/tests/pa1_tests/fail143.java new file mode 100644 index 0000000..9ab06fe --- /dev/null +++ b/miniJava/tests/pa1_tests/fail143.java @@ -0,0 +1,6 @@ +// PA1 parse field decl fail +class id { + void int x; +} + + diff --git a/miniJava/tests/pa1_tests/fail144.java b/miniJava/tests/pa1_tests/fail144.java new file mode 100644 index 0000000..643af02 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail144.java @@ -0,0 +1,6 @@ +// PA1 parse field decl fail +class id { + public [] String x; +} + + diff --git a/miniJava/tests/pa1_tests/fail145.java b/miniJava/tests/pa1_tests/fail145.java new file mode 100644 index 0000000..4101c57 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail145.java @@ -0,0 +1,6 @@ +// PA1 parse field decl fail +class id { + public void [] x; +} + + diff --git a/miniJava/tests/pa1_tests/fail146.java b/miniJava/tests/pa1_tests/fail146.java new file mode 100644 index 0000000..827f6a8 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail146.java @@ -0,0 +1,8 @@ +// PA1 parse local decl fail +class id { + void foo() { + Nonesuch x[2] = 3; + } +} + + diff --git a/miniJava/tests/pa1_tests/fail147.java b/miniJava/tests/pa1_tests/fail147.java new file mode 100644 index 0000000..eddf6f3 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail147.java @@ -0,0 +1,8 @@ +// PA1 parse local decl fail +class id { + public void f(){ + Ref [] x(33); + } +} + + diff --git a/miniJava/tests/pa1_tests/fail148.java b/miniJava/tests/pa1_tests/fail148.java new file mode 100644 index 0000000..3089be4 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail148.java @@ -0,0 +1,8 @@ +// PA1 parse local decl fail +class id { + public void f(){ + int x; + } +} + + diff --git a/miniJava/tests/pa1_tests/fail149.java b/miniJava/tests/pa1_tests/fail149.java new file mode 100644 index 0000000..709f8a4 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail149.java @@ -0,0 +1,8 @@ +// PA1 parse local decl fail +class id { + public void f(){ + Foo x; + } +} + + diff --git a/miniJava/tests/pa1_tests/fail150.java b/miniJava/tests/pa1_tests/fail150.java new file mode 100644 index 0000000..bab8c4a --- /dev/null +++ b/miniJava/tests/pa1_tests/fail150.java @@ -0,0 +1,6 @@ +// PA1 parse local decl fail +class idfail { + public void foo () { + int [] x[3] = null; + } +} diff --git a/miniJava/tests/pa1_tests/fail151.java b/miniJava/tests/pa1_tests/fail151.java new file mode 100644 index 0000000..a4a41e9 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail151.java @@ -0,0 +1,6 @@ +// PA1 parse local decl fail +class LValueFail { + void foo () { + true = false; + } +} diff --git a/miniJava/tests/pa1_tests/fail152.java b/miniJava/tests/pa1_tests/fail152.java new file mode 100644 index 0000000..7c1edb6 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail152.java @@ -0,0 +1,6 @@ +// PA1 parse expr fail +class NonTokens{ + int main () { + return a++b; + } +} diff --git a/miniJava/tests/pa1_tests/fail153.java b/miniJava/tests/pa1_tests/fail153.java new file mode 100644 index 0000000..f67de82 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail153.java @@ -0,0 +1,6 @@ +// PA1 parse expr fail +class NonTokens{ + int main () { + return; + } +} diff --git a/miniJava/tests/pa1_tests/fail154.java b/miniJava/tests/pa1_tests/fail154.java new file mode 100644 index 0000000..5dd2152 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail154.java @@ -0,0 +1,6 @@ +// PA1 parse expr fail +class IllegalExpressions { + void main () { + z = a+!=b; + } +} diff --git a/miniJava/tests/pa1_tests/fail155.java b/miniJava/tests/pa1_tests/fail155.java new file mode 100644 index 0000000..dc85175 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail155.java @@ -0,0 +1,6 @@ +// PA1 parse stmt fail +class IllegalStmt { + void main () { + this; + } +} diff --git a/miniJava/tests/pa1_tests/fail156.java b/miniJava/tests/pa1_tests/fail156.java new file mode 100644 index 0000000..4fbab10 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail156.java @@ -0,0 +1,8 @@ +// PA1 parse expr fail +class IllegalExpressions { + static void foo (int a) { + if (a = a) { + a = a; + } + } +} diff --git a/miniJava/tests/pa1_tests/fail157.java b/miniJava/tests/pa1_tests/fail157.java new file mode 100644 index 0000000..d6e7d61 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail157.java @@ -0,0 +1,6 @@ +// PA1 parse unop fail +class IllegalExpressions { + void foo() { + z = a!b; + } +} diff --git a/miniJava/tests/pa1_tests/fail158.java b/miniJava/tests/pa1_tests/fail158.java new file mode 100644 index 0000000..bf2a79f --- /dev/null +++ b/miniJava/tests/pa1_tests/fail158.java @@ -0,0 +1,6 @@ +// PA1 parse ref fail +class IllegalExpressions { + void foo () { + a [b] [c] = d; // not ok + } +} diff --git a/miniJava/tests/pa1_tests/fail159.java b/miniJava/tests/pa1_tests/fail159.java new file mode 100644 index 0000000..a97db05 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail159.java @@ -0,0 +1,8 @@ +// PA1 parse method fail +class IllegalExpressions { + void foo () { + if (x != 0) + return x; + return y; + } +} diff --git a/miniJava/tests/pa1_tests/fail160.java b/miniJava/tests/pa1_tests/fail160.java new file mode 100644 index 0000000..89bb1cd --- /dev/null +++ b/miniJava/tests/pa1_tests/fail160.java @@ -0,0 +1,8 @@ +// PA1 parse refs fail +class Test { + + void p() { + A a [17] = 23; + } +} + diff --git a/miniJava/tests/pa1_tests/fail161.java b/miniJava/tests/pa1_tests/fail161.java new file mode 100644 index 0000000..22416ab --- /dev/null +++ b/miniJava/tests/pa1_tests/fail161.java @@ -0,0 +1,8 @@ +// PA1 parse decl fail +class Test { + + void p() { + boolean [] a = b; + } +} + diff --git a/miniJava/tests/pa1_tests/fail162.java b/miniJava/tests/pa1_tests/fail162.java new file mode 100644 index 0000000..f4bc9f8 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail162.java @@ -0,0 +1,8 @@ +// PA1 parse call fail +class Test { + + void p(int a, boolean b) { + int p(a,b); + } +} + diff --git a/miniJava/tests/pa1_tests/fail163.java b/miniJava/tests/pa1_tests/fail163.java new file mode 100644 index 0000000..1d8c0ee --- /dev/null +++ b/miniJava/tests/pa1_tests/fail163.java @@ -0,0 +1,8 @@ +// PA1 parse decl fail +class Test { + + void p(int a) { + Test [ ] x.y = a; + } +} + diff --git a/miniJava/tests/pa1_tests/fail164.java b/miniJava/tests/pa1_tests/fail164.java new file mode 100644 index 0000000..80a6bf1 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail164.java @@ -0,0 +1,8 @@ +// PA1 parse assign fail +class Test { + + void p(int a) { + Test [ ] = a * 3; + } +} + diff --git a/miniJava/tests/pa1_tests/fail165.java b/miniJava/tests/pa1_tests/fail165.java new file mode 100644 index 0000000..037c17c --- /dev/null +++ b/miniJava/tests/pa1_tests/fail165.java @@ -0,0 +1,8 @@ +// PA1 parse call fail +class Test { + + void p(int a) { + c.p(2,3)[3] = 4; + } +} + diff --git a/miniJava/tests/pa1_tests/fail166.java b/miniJava/tests/pa1_tests/fail166.java new file mode 100644 index 0000000..6ca0d07 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail166.java @@ -0,0 +1,8 @@ +// PA1 parse assign fail +class Test { + + void p(int a) { + that.this = 4; + } +} + diff --git a/miniJava/tests/pa1_tests/fail167.java b/miniJava/tests/pa1_tests/fail167.java new file mode 100644 index 0000000..fd5425d --- /dev/null +++ b/miniJava/tests/pa1_tests/fail167.java @@ -0,0 +1,8 @@ +// PA1 parse assign fail +class Test { + + void p() { + x.y() = z; + } +} + diff --git a/miniJava/tests/pa1_tests/fail168.java b/miniJava/tests/pa1_tests/fail168.java new file mode 100644 index 0000000..2320941 --- /dev/null +++ b/miniJava/tests/pa1_tests/fail168.java @@ -0,0 +1,8 @@ +// PA1 parse decl fail +class Test { + + void p() { + c [] d b = new int[4]; + } +} + diff --git a/miniJava/tests/pa1_tests/fail169.java b/miniJava/tests/pa1_tests/fail169.java new file mode 100644 index 0000000..069c05f --- /dev/null +++ b/miniJava/tests/pa1_tests/fail169.java @@ -0,0 +1,8 @@ +// PA1 parse new fail +class Test { + + void p() { + x = new Foo(10); + } +} + diff --git a/miniJava/tests/pa1_tests/pass100.java b/miniJava/tests/pa1_tests/pass100.java new file mode 100644 index 0000000..8ecff32 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass100.java @@ -0,0 +1,2 @@ +class id {} + diff --git a/miniJava/tests/pa1_tests/pass101.java b/miniJava/tests/pa1_tests/pass101.java new file mode 100644 index 0000000..0a0a702 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass101.java @@ -0,0 +1,3 @@ +// PA1 lex id pass +class id {} + diff --git a/miniJava/tests/pa1_tests/pass102.java b/miniJava/tests/pa1_tests/pass102.java new file mode 100644 index 0000000..95a31f8 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass102.java @@ -0,0 +1,3 @@ +// PA1 lex id pass +class id_ {} + diff --git a/miniJava/tests/pa1_tests/pass103.java b/miniJava/tests/pa1_tests/pass103.java new file mode 100644 index 0000000..69023da --- /dev/null +++ b/miniJava/tests/pa1_tests/pass103.java @@ -0,0 +1,3 @@ +// PA1 lex id pass +class id_0_1__{} + diff --git a/miniJava/tests/pa1_tests/pass105.java b/miniJava/tests/pa1_tests/pass105.java new file mode 100644 index 0000000..ce66e25 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass105.java @@ -0,0 +1,3 @@ +// PA1 lex id pass +class Class{} + diff --git a/miniJava/tests/pa1_tests/pass110.java b/miniJava/tests/pa1_tests/pass110.java new file mode 100644 index 0000000..111e200 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass110.java @@ -0,0 +1,3 @@ +// PA1 lex comment pass +class // comment $$ followed by \r\n +id {} diff --git a/miniJava/tests/pa1_tests/pass113.java b/miniJava/tests/pa1_tests/pass113.java new file mode 100644 index 0000000..0e9fe63 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass113.java @@ -0,0 +1,2 @@ +// PA1 lex comment pass +class id {} // trailing comment terminated by \r\n diff --git a/miniJava/tests/pa1_tests/pass117.java b/miniJava/tests/pa1_tests/pass117.java new file mode 100644 index 0000000..bf6f9c0 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass117.java @@ -0,0 +1,3 @@ +// PA1 lex comment pass +class /* comment */ id {} + diff --git a/miniJava/tests/pa1_tests/pass118.java b/miniJava/tests/pa1_tests/pass118.java new file mode 100644 index 0000000..2b581d5 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass118.java @@ -0,0 +1,3 @@ +// PA1 lex comment pass +class /**/ id {} + diff --git a/miniJava/tests/pa1_tests/pass119.java b/miniJava/tests/pa1_tests/pass119.java new file mode 100644 index 0000000..8fb0ea7 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass119.java @@ -0,0 +1,3 @@ +// PA1 lex comment pass +class /*/**/ id {} + diff --git a/miniJava/tests/pa1_tests/pass120.java b/miniJava/tests/pa1_tests/pass120.java new file mode 100644 index 0000000..3fb77d1 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass120.java @@ -0,0 +1,3 @@ +// PA1 lex comment pass +class /*/$*/ id {} + diff --git a/miniJava/tests/pa1_tests/pass121.java b/miniJava/tests/pa1_tests/pass121.java new file mode 100644 index 0000000..c813852 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass121.java @@ -0,0 +1,8 @@ +// PA1 lex unop pass +class id { + void p(){ + int x = - b; + boolean y = !y; + } +} + diff --git a/miniJava/tests/pa1_tests/pass123.java b/miniJava/tests/pa1_tests/pass123.java new file mode 100644 index 0000000..73598f3 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass123.java @@ -0,0 +1,7 @@ +// PA1 lex unop pass +class id { + void p(){ + boolean x = !!!!!b; + } +} + diff --git a/miniJava/tests/pa1_tests/pass124.java b/miniJava/tests/pa1_tests/pass124.java new file mode 100644 index 0000000..33c7981 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass124.java @@ -0,0 +1,7 @@ +// PA1 lex unop pass +class id { + void p(){ + boolean x = 10 >- b; + } +} + diff --git a/miniJava/tests/pa1_tests/pass125.java b/miniJava/tests/pa1_tests/pass125.java new file mode 100644 index 0000000..6286286 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass125.java @@ -0,0 +1,7 @@ +// PA1 lex binop pass +class id { + void p(){ + int x = 1 + 2 * 3 / 4 > 5 >= 6 < 7 <= 8 != 9 && 0 || 1; + } +} + diff --git a/miniJava/tests/pa1_tests/pass126.java b/miniJava/tests/pa1_tests/pass126.java new file mode 100644 index 0000000..3708ab8 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass126.java @@ -0,0 +1,7 @@ +// PA1 lex binop pass +class id { + void p(){ + boolean x = true && false || x; + } +} + diff --git a/miniJava/tests/pa1_tests/pass127.java b/miniJava/tests/pa1_tests/pass127.java new file mode 100644 index 0000000..e4c2983 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass127.java @@ -0,0 +1,7 @@ +// PA1 lex unop pass +class id { + void p(){ + int y = --y; + } +} + diff --git a/miniJava/tests/pa1_tests/pass128.java b/miniJava/tests/pa1_tests/pass128.java new file mode 100644 index 0000000..f21b331 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass128.java @@ -0,0 +1,7 @@ +// PA1 lex unop pass +class id { + void p(){ + int x = b - - b; + } +} + diff --git a/miniJava/tests/pa1_tests/pass129.java b/miniJava/tests/pa1_tests/pass129.java new file mode 100644 index 0000000..fabfd63 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass129.java @@ -0,0 +1,7 @@ +// PA1 lex unop pass +class id { + void p(){ + int x = b - - - -b; + } +} + diff --git a/miniJava/tests/pa1_tests/pass130.java b/miniJava/tests/pa1_tests/pass130.java new file mode 100644 index 0000000..e69de29 diff --git a/miniJava/tests/pa1_tests/pass131.java b/miniJava/tests/pa1_tests/pass131.java new file mode 100644 index 0000000..4acb6dc --- /dev/null +++ b/miniJava/tests/pa1_tests/pass131.java @@ -0,0 +1,12 @@ +// PA1 lex whitespace including tab +class Test { + /* multiple comments between + */ + + // tokens + + /**//* is OK */ + + +} + diff --git a/miniJava/tests/pa1_tests/pass132.java b/miniJava/tests/pa1_tests/pass132.java new file mode 100644 index 0000000..89408eb --- /dev/null +++ b/miniJava/tests/pa1_tests/pass132.java @@ -0,0 +1,3 @@ +// PA1 lex comment pass +class // comment followed by \n only +id {} diff --git a/miniJava/tests/pa1_tests/pass133.java b/miniJava/tests/pa1_tests/pass133.java new file mode 100644 index 0000000..287861f --- /dev/null +++ b/miniJava/tests/pa1_tests/pass133.java @@ -0,0 +1,3 @@ +// PA1 lex comment pass +class // comment followed by \r only + id {} \ No newline at end of file diff --git a/miniJava/tests/pa1_tests/pass134.java b/miniJava/tests/pa1_tests/pass134.java new file mode 100644 index 0000000..83a0c2a --- /dev/null +++ b/miniJava/tests/pa1_tests/pass134.java @@ -0,0 +1,2 @@ +// PA1 lex comment pass +class id {} // trailing comment terminated by \r \ No newline at end of file diff --git a/miniJava/tests/pa1_tests/pass135.java b/miniJava/tests/pa1_tests/pass135.java new file mode 100644 index 0000000..60c3f1d --- /dev/null +++ b/miniJava/tests/pa1_tests/pass135.java @@ -0,0 +1,2 @@ +// PA1 lex comment pass +class id {} // trailing comment terminated by \n diff --git a/miniJava/tests/pa1_tests/pass136.java b/miniJava/tests/pa1_tests/pass136.java new file mode 100644 index 0000000..216cd0c --- /dev/null +++ b/miniJava/tests/pa1_tests/pass136.java @@ -0,0 +1,2 @@ +// PA1 lex comment pass +class id {} // unterminated comment - no trailing \r\n \ No newline at end of file diff --git a/miniJava/tests/pa1_tests/pass137.java b/miniJava/tests/pa1_tests/pass137.java new file mode 100644 index 0000000..20cc7a7 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass137.java @@ -0,0 +1,2 @@ +// PA1 lex comment pass +class id {} /* no trailing \r\n */ \ No newline at end of file diff --git a/miniJava/tests/pa1_tests/pass140.java b/miniJava/tests/pa1_tests/pass140.java new file mode 100644 index 0000000..3ff1b0f --- /dev/null +++ b/miniJava/tests/pa1_tests/pass140.java @@ -0,0 +1,5 @@ +// PA1 parse field decl pass +class id { + public static Type x; +} + diff --git a/miniJava/tests/pa1_tests/pass141.java b/miniJava/tests/pa1_tests/pass141.java new file mode 100644 index 0000000..88a514b --- /dev/null +++ b/miniJava/tests/pa1_tests/pass141.java @@ -0,0 +1,5 @@ +// PA1 parse field decl pass +class id { + private static Type x; +} + diff --git a/miniJava/tests/pa1_tests/pass142.java b/miniJava/tests/pa1_tests/pass142.java new file mode 100644 index 0000000..396053c --- /dev/null +++ b/miniJava/tests/pa1_tests/pass142.java @@ -0,0 +1,5 @@ +// PA1 parse field decl pass +class id { + static Type x; +} + diff --git a/miniJava/tests/pa1_tests/pass143.java b/miniJava/tests/pa1_tests/pass143.java new file mode 100644 index 0000000..c9845b8 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass143.java @@ -0,0 +1,5 @@ +// PA1 parse field decl pass +class id { + Type x; +} + diff --git a/miniJava/tests/pa1_tests/pass144.java b/miniJava/tests/pa1_tests/pass144.java new file mode 100644 index 0000000..e86d303 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass144.java @@ -0,0 +1,5 @@ +// PA1 parse field decl pass +class id { + int x; +} + diff --git a/miniJava/tests/pa1_tests/pass145.java b/miniJava/tests/pa1_tests/pass145.java new file mode 100644 index 0000000..ab3e569 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass145.java @@ -0,0 +1,5 @@ +// PA1 parse field decl pass +class id { + int[] x; +} + diff --git a/miniJava/tests/pa1_tests/pass146.java b/miniJava/tests/pa1_tests/pass146.java new file mode 100644 index 0000000..50645d1 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass146.java @@ -0,0 +1,5 @@ +// PA1 parse field decl pass +class id { + static void x; +} + diff --git a/miniJava/tests/pa1_tests/pass147.java b/miniJava/tests/pa1_tests/pass147.java new file mode 100644 index 0000000..ce969d7 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass147.java @@ -0,0 +1,5 @@ +// PA1 parse method decl pass +class id { + public static void main(String[] args){} +} + diff --git a/miniJava/tests/pa1_tests/pass148.java b/miniJava/tests/pa1_tests/pass148.java new file mode 100644 index 0000000..a8a1967 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass148.java @@ -0,0 +1,5 @@ +// PA1 parse method decl pass +class id { + private int f(int x, boolean b) {return 3;} +} + diff --git a/miniJava/tests/pa1_tests/pass150.java b/miniJava/tests/pa1_tests/pass150.java new file mode 100644 index 0000000..6fa11df --- /dev/null +++ b/miniJava/tests/pa1_tests/pass150.java @@ -0,0 +1,9 @@ +// PA1 parse classdecls pass +class MainClass { + public static void main (String [] args) {} +} + +class OfItsOwn { + int A_01; +} // class OfItsOwn + diff --git a/miniJava/tests/pa1_tests/pass151.java b/miniJava/tests/pa1_tests/pass151.java new file mode 100644 index 0000000..3bf67e0 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass151.java @@ -0,0 +1,20 @@ +// PA1 parse identifiers pass +class Keywords { + + // minijava keywords are lower case only + void p() { + int format = while_1; + int Int = New; + For = Class; + FOR = RETURN; + } + + public int declare () { + boolean iF = true; + boolean Then = false; + boolean else1 = false; + + if (true == false) { else1 = iF == Then; } + } +} + diff --git a/miniJava/tests/pa1_tests/pass152.java b/miniJava/tests/pa1_tests/pass152.java new file mode 100644 index 0000000..858bbbd --- /dev/null +++ b/miniJava/tests/pa1_tests/pass152.java @@ -0,0 +1,8 @@ +// PA1 parse new pass +class MainClass { + public static void main (String [] args) { + SecondSubClass newobj = new SecondSubClass (); + } +} + + diff --git a/miniJava/tests/pa1_tests/pass153.java b/miniJava/tests/pa1_tests/pass153.java new file mode 100644 index 0000000..91330f4 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass153.java @@ -0,0 +1,8 @@ +// PA1 parse new pass +class Foo { + void bar() { + int[] newarr = new int[20]; + } +} + + diff --git a/miniJava/tests/pa1_tests/pass154.java b/miniJava/tests/pa1_tests/pass154.java new file mode 100644 index 0000000..3328ef7 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass154.java @@ -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; + } +} diff --git a/miniJava/tests/pa1_tests/pass155.java b/miniJava/tests/pa1_tests/pass155.java new file mode 100644 index 0000000..3453fc6 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass155.java @@ -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 + diff --git a/miniJava/tests/pa1_tests/pass158.java b/miniJava/tests/pa1_tests/pass158.java new file mode 100644 index 0000000..be52ebf --- /dev/null +++ b/miniJava/tests/pa1_tests/pass158.java @@ -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); + } +} + diff --git a/miniJava/tests/pa1_tests/pass159.java b/miniJava/tests/pa1_tests/pass159.java new file mode 100644 index 0000000..9d6a140 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass159.java @@ -0,0 +1,11 @@ +// PA1 parse decl pass +class Test { + + int [] a; + Test [] t; + + void p() { + void x = this.t[3].a[4].p(); + } +} + diff --git a/miniJava/tests/pa1_tests/pass160.java b/miniJava/tests/pa1_tests/pass160.java new file mode 100644 index 0000000..82d7f6b --- /dev/null +++ b/miniJava/tests/pa1_tests/pass160.java @@ -0,0 +1,9 @@ +// PA1 parse refs pass +class Test { + + void p() { + A a = 23; + boolean b = c; + } +} + diff --git a/miniJava/tests/pa1_tests/pass161.java b/miniJava/tests/pa1_tests/pass161.java new file mode 100644 index 0000000..654e776 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass161.java @@ -0,0 +1,8 @@ +// PA1 parse assign pass +class Test { + + void p() { + a = b; + } +} + diff --git a/miniJava/tests/pa1_tests/pass162.java b/miniJava/tests/pa1_tests/pass162.java new file mode 100644 index 0000000..77d1a46 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass162.java @@ -0,0 +1,8 @@ +// PA1 parse call pass +class Test { + + void p(int a, boolean b) { + p(a,b); + } +} + diff --git a/miniJava/tests/pa1_tests/pass163.java b/miniJava/tests/pa1_tests/pass163.java new file mode 100644 index 0000000..402f02b --- /dev/null +++ b/miniJava/tests/pa1_tests/pass163.java @@ -0,0 +1,8 @@ +// PA1 parse decl pass +class Test { + + void p(int a) { + Test [ ] v = a; + } +} + diff --git a/miniJava/tests/pa1_tests/pass164.java b/miniJava/tests/pa1_tests/pass164.java new file mode 100644 index 0000000..3ef2c2b --- /dev/null +++ b/miniJava/tests/pa1_tests/pass164.java @@ -0,0 +1,8 @@ +// PA1 parse assign pass +class Test { + + void p(int a) { + Test [ a + 1] = a * 3; + } +} + diff --git a/miniJava/tests/pa1_tests/pass165.java b/miniJava/tests/pa1_tests/pass165.java new file mode 100644 index 0000000..e95b29c --- /dev/null +++ b/miniJava/tests/pa1_tests/pass165.java @@ -0,0 +1,9 @@ +// PA1 parse call pass +class Test { + + void p(int a) { + C c = new C(); + c.p(2,3); + } +} + diff --git a/miniJava/tests/pa1_tests/pass166.java b/miniJava/tests/pa1_tests/pass166.java new file mode 100644 index 0000000..ed777be --- /dev/null +++ b/miniJava/tests/pa1_tests/pass166.java @@ -0,0 +1,9 @@ +// PA1 parse assign pass +class Test { + + void p(int a) { + this.p(2,3); + a.v[3] = 4; + } +} + diff --git a/miniJava/tests/pa1_tests/pass167.java b/miniJava/tests/pa1_tests/pass167.java new file mode 100644 index 0000000..8da8f55 --- /dev/null +++ b/miniJava/tests/pa1_tests/pass167.java @@ -0,0 +1,8 @@ +// PA1 parse assign pass +class Test { + + void p() { + x.y = z; + } +} + diff --git a/miniJava/tests/pa1_tests/pass168.java b/miniJava/tests/pa1_tests/pass168.java new file mode 100644 index 0000000..716d68c --- /dev/null +++ b/miniJava/tests/pa1_tests/pass168.java @@ -0,0 +1,9 @@ +// PA1 parse decl pass +class Test { + + void p() { + int a = 3; + int [] b = new int[4]; + } +} + diff --git a/miniJava/tests/pa1_tests/pass169.java b/miniJava/tests/pa1_tests/pass169.java new file mode 100644 index 0000000..37fafdd --- /dev/null +++ b/miniJava/tests/pa1_tests/pass169.java @@ -0,0 +1,8 @@ +// PA1 parse new pass +class Test { + + void p() { + Foo [] foo = new Foo [10]; + } +} + diff --git a/miniJava/tests/src/tester/Checkpoint1.java b/miniJava/tests/src/tester/Checkpoint1.java new file mode 100644 index 0000000..ffa95d6 --- /dev/null +++ b/miniJava/tests/src/tester/Checkpoint1.java @@ -0,0 +1,71 @@ +package tester; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Scanner; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/* Automated regression tester for Checkpoint 1 tests + * Created by Max Beckman-Harned + * Put your tests in "tests/pa1_tests" folder in your Eclipse workspace directory + */ +public class Checkpoint1 { + + static ExecutorService threadPool = Executors.newCachedThreadPool(); + + public static void main(String[] args) throws IOException, InterruptedException { + File testDir = new File(System.getProperty("java.class.path") + "/../tests/pa1_tests"); + System.out.println(System.getProperty("java.class.path")); + int failures = 0; + for (File x : testDir.listFiles()) { + int returnCode = runTest(x); + if (x.getName().indexOf("pass") != -1) { + if (returnCode == 0) + System.out.println(x.getName() + " passed successfully!"); + else { + failures++; + System.err.println(x.getName() + + " failed but should have passed!"); + } + } 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 int runTest(File x) throws IOException, InterruptedException { + ProcessBuilder pb = new ProcessBuilder("java", "miniJava.Compiler", x.getPath()).directory(new File(System.getProperty("java.class.path"))); + Process p = pb.start(); + threadPool.execute(new ProcessOutputter(p.getInputStream(), false)); + p.waitFor(); + return p.exitValue(); + } + + static class ProcessOutputter implements Runnable { + private Scanner processOutput; + private boolean output; + + public ProcessOutputter(InputStream _processStream, boolean _output) { + processOutput = new Scanner(_processStream); + output = _output; + } + @Override + public void run() { + while(processOutput.hasNextLine()) { + String line = processOutput.nextLine(); + if (output) + System.out.println(line); + } + } + + + } +} diff --git a/miniJava/tests/test.java b/miniJava/tests/test.java new file mode 100644 index 0000000..33c7981 --- /dev/null +++ b/miniJava/tests/test.java @@ -0,0 +1,7 @@ +// PA1 lex unop pass +class id { + void p(){ + boolean x = 10 >- b; + } +} +