From 5c82d7c869ea62c2a4107a94bcda5e3109d9d8e9 Mon Sep 17 00:00:00 2001 From: IamMaxim Date: Sat, 25 Jun 2022 10:11:59 +0000 Subject: [PATCH] Changed Java build version to 11 --- .gitignore | 6 + build.gradle.kts | 6 +- src/main/java/lexer/Scanner.java | 227 ++++++++++-------- src/main/java/main/Main.java | 1 - .../Declaration/ParameterDeclaration.java | 1 - .../Expression/Primary/ArrayCreation.java | 2 - .../Expression/Primary/InstanceCreation.java | 3 - src/main/java/tree/Type/PrimitiveType.java | 1 - src/main/java/tree/Type/TypeArgument.java | 7 +- src/main/java/tree/Type/TypeName.java | 1 - 10 files changed, 137 insertions(+), 118 deletions(-) diff --git a/.gitignore b/.gitignore index ed8274e..da2c367 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,9 @@ build .idea .gradle out + +.vscode +bin/main + +# JVM error dumps +hs_err* \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 50c4c42..c76c4b6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "org.polystat" -version = "0.0.2" +version = "0.0.3" val mvnUsername: String? by project @@ -31,8 +31,8 @@ val latestGrammarMD5FilePath = "out/latestGrammarMD5" java { - sourceCompatibility = JavaVersion.VERSION_15 - targetCompatibility = JavaVersion.VERSION_15 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 withSourcesJar() } diff --git a/src/main/java/lexer/Scanner.java b/src/main/java/lexer/Scanner.java index a5fcf9b..f5b141c 100644 --- a/src/main/java/lexer/Scanner.java +++ b/src/main/java/lexer/Scanner.java @@ -268,24 +268,27 @@ private Token getToken() { forgetChar(); ch = getChar(); switch (ch) { - case '=' -> { + case '=': { forgetChar(); code = TokenCode.SlashAssign; image = "/="; + break; } - case '/' -> { + case '/': { forgetChar(); code = TokenCode.ShortComment; image = "//" + scanShortComment(); + break; } - case '*' -> { + case '*': { forgetChar(); code = TokenCode.LongComment; image = "/*" + scanLongComment(); } - default -> { + default: { code = TokenCode.Slash; image = "/"; + break; } } break; @@ -305,19 +308,22 @@ private Token getToken() { forgetChar(); ch = getChar(); switch (ch) { - case '+' -> { + case '+': { forgetChar(); code = TokenCode.PlusPlus; image = "++"; + break; } - case '=' -> { + case '=': { forgetChar(); code = TokenCode.PlusAssign; image = "+="; + break; } - default -> { + default: { code = TokenCode.Plus; image = "+"; + break; } } break; @@ -325,24 +331,28 @@ private Token getToken() { forgetChar(); ch = getChar(); switch (ch) { - case '=' -> { + case '=': { forgetChar(); code = TokenCode.MinusAssign; image = "-="; + break; } - case '-' -> { + case '-': { forgetChar(); code = TokenCode.MinusMinus; image = "--"; + break; } - case '>' -> { + case '>': { forgetChar(); code = TokenCode.Arrow; image = "->"; + break; } - default -> { + default: { code = TokenCode.Minus; image = "-"; + break; } } break; @@ -369,7 +379,7 @@ private Token getToken() { forgetChar(); ch = getChar(); switch (ch) { - case '<' -> { + case '<': { forgetChar(); ch = getChar(); if (ch == '=') { @@ -380,15 +390,18 @@ private Token getToken() { code = TokenCode.LeftShift; image = "<<"; } + break; } - case '=' -> { + case '=': { forgetChar(); code = TokenCode.LessEqual; image = "<="; + break; } - default -> { + default: { code = TokenCode.Less; image = "<"; + break; } } break; @@ -396,16 +409,17 @@ private Token getToken() { forgetChar(); ch = getChar(); switch (ch) { - case '=' -> { + case '=': { forgetChar(); code = TokenCode.GreaterEqual; image = ">="; + break; } - case '>' -> { + case '>': { forgetChar(); ch = getChar(); switch (ch) { - case '>' -> { + case '>': { forgetChar(); ch = getChar(); if (ch == '=') { @@ -416,21 +430,26 @@ private Token getToken() { code = TokenCode.ArithmRightShift; image = ">>>"; } + break; } - case '=' -> { + case '=': { forgetChar(); code = TokenCode.RightShiftAssign; image = ">>="; + break; } - default -> { + default: { code = TokenCode.RightShift; image = ">>"; + break; } } + break; } - default -> { + default: { code = TokenCode.Greater; image = ">"; + break; } } break; @@ -439,19 +458,22 @@ private Token getToken() { forgetChar(); ch = getChar(); switch (ch) { - case '|' -> { + case '|': { forgetChar(); code = TokenCode.DoubleVertical; image = "||"; + break; } - case '=' -> { + case '=': { forgetChar(); code = TokenCode.VerticalAssign; image = "|="; + break; } - default -> { + default: { code = TokenCode.Vertical; image = "|"; + break; } } break; @@ -460,19 +482,22 @@ private Token getToken() { forgetChar(); ch = getChar(); switch (ch) { - case '&' -> { + case '&': { forgetChar(); code = TokenCode.DoubleAmpersand; image = "&&"; + break; } - case '=' -> { + case '=': { forgetChar(); code = TokenCode.AmpersandAssign; image = "&="; + break; } - default -> { + default: { code = TokenCode.Ampersand; image = "&"; + break; } } break; @@ -703,81 +728,79 @@ private String scanLongComment() { } private TokenCode detectKeyword(String identifier) { - return switch (identifier) { - case "abstract" -> TokenCode.Abstract; - case "assert" -> TokenCode.Assert; - case "boolean" -> TokenCode.Boolean; - case "break" -> TokenCode.Break; - case "byte" -> TokenCode.Byte; - case "catch" -> TokenCode.Catch; - case "case" -> TokenCode.Case; - case "char" -> TokenCode.Char; - case "class" -> TokenCode.Class; - // case "const" -> TokenCode.Const; // not actually used - case "continue" -> TokenCode.Continue; - case "default" -> TokenCode.Default; - case "do" -> TokenCode.Do; - case "double" -> TokenCode.Double; - case "else" -> TokenCode.Else; - case "enum" -> TokenCode.Enum; - case "extends" -> TokenCode.Extends; - case "final" -> TokenCode.Final; - case "finally" -> TokenCode.Finally; - case "float" -> TokenCode.Float; - case "for" -> TokenCode.For; - // case "goto" -> TokenCode.Goto; // not actually used - case "if" -> TokenCode.If; - case "implements" -> TokenCode.Implements; - case "import" -> TokenCode.Import; - case "instanceof" -> TokenCode.Instanceof; - case "int" -> TokenCode.Int; - case "interface" -> TokenCode.Interface; - case "long" -> TokenCode.Long; - case "native" -> TokenCode.Native; - case "new" -> TokenCode.New; - case "package" -> TokenCode.Package; - case "private" -> TokenCode.Private; - case "protected" -> TokenCode.Protected; - case "public" -> TokenCode.Public; - case "return" -> TokenCode.Return; - case "short" -> TokenCode.Short; - case "static" -> TokenCode.Static; - case "strictfp" -> TokenCode.Strictfp; - case "super" -> TokenCode.Super; - case "synchronized" -> TokenCode.Synchronized; - case "switch" -> TokenCode.Switch; - case "this" -> TokenCode.This; - case "throw" -> TokenCode.Throw; - case "throws" -> TokenCode.Throws; - case "transient" -> TokenCode.Transient; - case "try" -> TokenCode.Try; - case "void" -> TokenCode.Void; - case "volatile" -> TokenCode.Volatile; - case "while" -> TokenCode.While; - case "true" -> TokenCode.True; - case "false" -> TokenCode.False; - case "null" -> TokenCode.Null; - case "var" -> TokenCode.Var; - case "yield" -> TokenCode.Yield; - case "record" -> TokenCode.Record; - - /* - open, - module, - requires, - transitive, - exports, - opens, - to, - uses, - provides, - with, - - Yield, - Record, - */ - - default -> TokenCode.Identifier; - }; + if (identifier.equals("abstract")) return TokenCode.Abstract; + if (identifier.equals("assert")) return TokenCode.Assert; + if (identifier.equals("boolean")) return TokenCode.Boolean; + if (identifier.equals("break")) return TokenCode.Break; + if (identifier.equals("byte")) return TokenCode.Byte; + if (identifier.equals("catch")) return TokenCode.Catch; + if (identifier.equals("case")) return TokenCode.Case; + if (identifier.equals("char")) return TokenCode.Char; + if (identifier.equals("class")) return TokenCode.Class; +// if (identifier.equals("const")) return TokenCode.Const; // not actually used + if (identifier.equals("continue")) return TokenCode.Continue; + if (identifier.equals("default")) return TokenCode.Default; + if (identifier.equals("do")) return TokenCode.Do; + if (identifier.equals("double")) return TokenCode.Double; + if (identifier.equals("else")) return TokenCode.Else; + if (identifier.equals("enum")) return TokenCode.Enum; + if (identifier.equals("extends")) return TokenCode.Extends; + if (identifier.equals("final")) return TokenCode.Final; + if (identifier.equals("finally")) return TokenCode.Finally; + if (identifier.equals("float")) return TokenCode.Float; + if (identifier.equals("for")) return TokenCode.For; +// if (identifier.equals("goto")) return TokenCode.Goto; // not actually used + if (identifier.equals("if")) return TokenCode.If; + if (identifier.equals("implements")) return TokenCode.Implements; + if (identifier.equals("import")) return TokenCode.Import; + if (identifier.equals("instanceof")) return TokenCode.Instanceof; + if (identifier.equals("int")) return TokenCode.Int; + if (identifier.equals("interface")) return TokenCode.Interface; + if (identifier.equals("long")) return TokenCode.Long; + if (identifier.equals("native")) return TokenCode.Native; + if (identifier.equals("new")) return TokenCode.New; + if (identifier.equals("package")) return TokenCode.Package; + if (identifier.equals("private")) return TokenCode.Private; + if (identifier.equals("protected")) return TokenCode.Protected; + if (identifier.equals("public")) return TokenCode.Public; + if (identifier.equals("return")) return TokenCode.Return; + if (identifier.equals("short")) return TokenCode.Short; + if (identifier.equals("static")) return TokenCode.Static; + if (identifier.equals("strictfp")) return TokenCode.Strictfp; + if (identifier.equals("super")) return TokenCode.Super; + if (identifier.equals("synchronized")) return TokenCode.Synchronized; + if (identifier.equals("switch")) return TokenCode.Switch; + if (identifier.equals("this")) return TokenCode.This; + if (identifier.equals("throw")) return TokenCode.Throw; + if (identifier.equals("throws")) return TokenCode.Throws; + if (identifier.equals("transient")) return TokenCode.Transient; + if (identifier.equals("try")) return TokenCode.Try; + if (identifier.equals("void")) return TokenCode.Void; + if (identifier.equals("volatile")) return TokenCode.Volatile; + if (identifier.equals("while")) return TokenCode.While; + if (identifier.equals("true")) return TokenCode.True; + if (identifier.equals("false")) return TokenCode.False; + if (identifier.equals("null")) return TokenCode.Null; + if (identifier.equals("var")) return TokenCode.Var; + if (identifier.equals("yield")) return TokenCode.Yield; + if (identifier.equals("record")) return TokenCode.Record; + + /* + open, + module, + requires, + transitive, + exports, + opens, + to, + uses, + provides, + with, + + Yield, + Record, + */ + + return TokenCode.Identifier; } } diff --git a/src/main/java/main/Main.java b/src/main/java/main/Main.java index ab9e2ac..c698561 100644 --- a/src/main/java/main/Main.java +++ b/src/main/java/main/Main.java @@ -8,7 +8,6 @@ import java.io.File; import java.io.FileNotFoundException; -import java.io.PrintWriter; import java.util.Map; public class Main { diff --git a/src/main/java/tree/Declaration/ParameterDeclaration.java b/src/main/java/tree/Declaration/ParameterDeclaration.java index 03aad34..a746093 100644 --- a/src/main/java/tree/Declaration/ParameterDeclaration.java +++ b/src/main/java/tree/Declaration/ParameterDeclaration.java @@ -1,6 +1,5 @@ package tree.Declaration; -import com.sun.source.tree.EmptyStatementTree; import lexer.Token; import tree.*; import tree.Modifiers; diff --git a/src/main/java/tree/Expression/Primary/ArrayCreation.java b/src/main/java/tree/Expression/Primary/ArrayCreation.java index fa3e559..ced9650 100644 --- a/src/main/java/tree/Expression/Primary/ArrayCreation.java +++ b/src/main/java/tree/Expression/Primary/ArrayCreation.java @@ -1,7 +1,5 @@ package tree.Expression.Primary; -import tree.DimExprs; -import tree.Dims; import tree.Entity; import tree.InitializerArray; import tree.Type.Type; diff --git a/src/main/java/tree/Expression/Primary/InstanceCreation.java b/src/main/java/tree/Expression/Primary/InstanceCreation.java index a218c3a..f277854 100644 --- a/src/main/java/tree/Expression/Primary/InstanceCreation.java +++ b/src/main/java/tree/Expression/Primary/InstanceCreation.java @@ -1,14 +1,11 @@ package tree.Expression.Primary; -import tree.CompoundNameAnnotated; import tree.Declaration.Declarations; import tree.Entity; import tree.Expression.ArgumentList; import tree.Type.*; import tree.Type.TypeArguments; -import java.util.ArrayList; - // Primary // : ... // | ClassInstanceCreationExpression diff --git a/src/main/java/tree/Type/PrimitiveType.java b/src/main/java/tree/Type/PrimitiveType.java index 63b2cf7..feb56a4 100644 --- a/src/main/java/tree/Type/PrimitiveType.java +++ b/src/main/java/tree/Type/PrimitiveType.java @@ -3,7 +3,6 @@ import lexer.Token; import lexer.TokenCode; import tree.Entity; -import tree.*; // PrimitiveType // // NumericType -- IntegralType diff --git a/src/main/java/tree/Type/TypeArgument.java b/src/main/java/tree/Type/TypeArgument.java index 5b0e7cd..bdf0d98 100644 --- a/src/main/java/tree/Type/TypeArgument.java +++ b/src/main/java/tree/Type/TypeArgument.java @@ -27,10 +27,9 @@ public TypeArgument(Type t, int sign, Annotations anns) signExtends = false; signSuper = false; switch (sign) { - case 1 -> signExtends = true; - case 2 -> signSuper = true; - default -> { - } + case 1: signExtends = true; break; + case 2: signSuper = true; break; + default: break; } this.annotations = anns; diff --git a/src/main/java/tree/Type/TypeName.java b/src/main/java/tree/Type/TypeName.java index 02746a7..8b45097 100644 --- a/src/main/java/tree/Type/TypeName.java +++ b/src/main/java/tree/Type/TypeName.java @@ -2,7 +2,6 @@ import tree.CompoundName; import tree.Entity; -import tree.*; // UnannotatedType // : ...