summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-06-30 13:45:57 +0200
committerGitHub <noreply@github.com>2024-06-30 13:45:57 +0200
commit8aa8b5834953cab15c0687608f4fafea2e6c61be (patch)
tree1835ae7c789136b4a6c44c12efd4247a0b96d893
parent7125bb27fedaafd5a56b5122e4251b182448ddac (diff)
parent06d7c8dee25c065b1a569337f34d3cd5e892a31d (diff)
Merge pull request #10 from boozec/check-semantics
Co-Authored-By: geno <gabriele.genovese2@studio.unibo.it> Co-Authored-By: L0P0P <grassoemanuele@live.com>
-rw-r--r--.gitignore3
-rw-r--r--src/Main.java26
-rw-r--r--src/ParseAll.java90
-rw-r--r--src/ast/Python3VisitorImpl.java274
-rw-r--r--src/ast/nodes/ArglistNode.java34
-rw-r--r--src/ast/nodes/AssignmentNode.java33
-rw-r--r--src/ast/nodes/AtomNode.java70
-rw-r--r--src/ast/nodes/AugassignNode.java5
-rw-r--r--src/ast/nodes/BlockNode.java32
-rw-r--r--src/ast/nodes/CompForNode.java58
-rw-r--r--src/ast/nodes/CompIterNode.java50
-rw-r--r--src/ast/nodes/CompNode.java5
-rw-r--r--src/ast/nodes/CompoundNode.java14
-rw-r--r--src/ast/nodes/DottedNameNode.java9
-rw-r--r--src/ast/nodes/ExprListNode.java68
-rw-r--r--src/ast/nodes/ExprNode.java97
-rw-r--r--src/ast/nodes/ForStmtNode.java40
-rw-r--r--src/ast/nodes/FuncdefNode.java33
-rw-r--r--src/ast/nodes/IfNode.java22
-rw-r--r--src/ast/nodes/ImportNode.java33
-rw-r--r--src/ast/nodes/Node.java85
-rw-r--r--src/ast/nodes/ParamdefNode.java20
-rw-r--r--src/ast/nodes/ParamlistNode.java12
-rw-r--r--src/ast/nodes/ReturnStmtNode.java8
-rw-r--r--src/ast/nodes/RootNode.java42
-rw-r--r--src/ast/nodes/SimpleStmtNode.java14
-rw-r--r--src/ast/nodes/SimpleStmtsNode.java8
-rw-r--r--src/ast/nodes/TestlistCompNode.java82
-rw-r--r--src/ast/nodes/TrailerNode.java29
-rw-r--r--src/ast/nodes/WhileStmtNode.java10
-rw-r--r--src/ast/types/AtomType.java3
-rw-r--r--src/ast/types/BoolType.java2
-rw-r--r--src/ast/types/ErrorType.java2
-rw-r--r--src/ast/types/FunctionType.java29
-rw-r--r--src/ast/types/ImportType.java12
-rw-r--r--src/ast/types/IntType.java2
-rw-r--r--src/ast/types/NoneType.java17
-rw-r--r--src/ast/types/ReservedWordsType.java12
-rw-r--r--src/ast/types/Type.java11
-rw-r--r--src/ast/types/VoidType.java7
-rw-r--r--src/parser/.antlr/Python3Lexer.interp253
-rw-r--r--src/parser/.antlr/Python3Lexer.java574
-rw-r--r--src/parser/.antlr/Python3Lexer.tokens142
-rw-r--r--src/semanticanalysis/STentry.java13
-rw-r--r--src/semanticanalysis/SemanticError.java4
-rw-r--r--src/semanticanalysis/Share.java58
-rw-r--r--src/semanticanalysis/SymbolTable.java44
-rw-r--r--test/1a.py8
-rw-r--r--test/1b.py6
-rw-r--r--test/1c.py5
-rw-r--r--test/trailers.py13
51 files changed, 1180 insertions, 1343 deletions
diff --git a/.gitignore b/.gitignore
index 29ba4ac..2b49698 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
out/
trees/
.project
-.vscode/ \ No newline at end of file
+.vscode/
+src/parser/.antlr/ \ No newline at end of file
diff --git a/src/Main.java b/src/Main.java
index afad5b1..f53b410 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,6 +1,4 @@
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
+
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.*;
@@ -11,6 +9,7 @@ import ast.*;
import ast.nodes.*;
import parser.*;
import semanticanalysis.*;
+import semanticanalysis.Share;
public class Main {
@@ -25,7 +24,7 @@ public class Main {
try {
String fileStr = args[0];
System.out.println(fileStr);
- System.out.println(readFile(fileStr));
+ System.out.println(Share.readFile(fileStr));
CharStream cs = CharStreams.fromFileName(fileStr);
Python3Lexer lexer = new Python3Lexer(cs);
CommonTokenStream tokens = new CommonTokenStream(lexer);
@@ -36,7 +35,7 @@ public class Main {
JPanel panel = new JPanel();
TreeViewer viewer = new TreeViewer(Arrays.asList(parser.getRuleNames()),
tree);
- viewer.setScale(1.5);
+ viewer.setScale(1); // Zoom factor
panel.add(viewer);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -53,9 +52,10 @@ public class Main {
Python3VisitorImpl visitor = new Python3VisitorImpl();
SymbolTable ST = new SymbolTable();
Node ast = visitor.visit(tree);
- ArrayList<SemanticError> errors = ast.checkSemantics(ST, 0);
- if (errors.size() > 0) {
- System.out.println("You had: " + errors.size() + " errors:");
+ ArrayList<SemanticError> errorsWithDup = ast.checkSemantics(ST, 0);
+ ArrayList<SemanticError> errors = Share.removeDuplicates(errorsWithDup);
+ if (!errors.isEmpty()) {
+ System.out.println("You had " + errors.size() + " errors:");
for (SemanticError e : errors) {
System.out.println("\t" + e);
}
@@ -68,14 +68,4 @@ public class Main {
}
}
- private static String readFile(String filePath) throws IOException {
- StringBuilder content = new StringBuilder();
- try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
- String line;
- while ((line = reader.readLine()) != null) {
- content.append(line).append("\n");
- }
- }
- return content.toString();
- }
}
diff --git a/src/ParseAll.java b/src/ParseAll.java
index 3e5d868..7def6f4 100644
--- a/src/ParseAll.java
+++ b/src/ParseAll.java
@@ -1,16 +1,19 @@
-import java.io.BufferedReader;
+
import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Arrays;
+import java.util.ArrayList;
import java.util.Objects;
-import javax.swing.*;
-import org.antlr.v4.gui.TreeViewer;
import org.antlr.v4.runtime.*;
-import parser.*;
+import ast.Python3VisitorImpl;
+import ast.nodes.*;
+import parser.Python3Lexer;
+import parser.Python3Parser;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
+import semanticanalysis.Share;
public class ParseAll {
+
@SuppressWarnings("unused")
public static void main(String[] args) {
new File("./trees/").mkdirs();
@@ -19,15 +22,11 @@ public class ParseAll {
// fileStr = "./progs/wrong.py";
try {
- if (!file.isFile() || !getExtension(file.getName()).equals("py")) {
+ if (!file.isFile() || !Share.getExtension(file.getName()).equals("py")) {
System.err.println("Wont parse: " + fileStr);
continue;
- } else {
- System.out.println(fileStr);
}
- // System.out.println(readFile(fileStr));
-
CharStream cs = CharStreams.fromFileName(fileStr);
Python3Lexer lexer = new Python3Lexer(cs);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
@@ -37,11 +36,18 @@ public class ParseAll {
String treeStr = tree.toStringTree();
// System.out.println(treeStr);
- TreeViewer viewer = new TreeViewer(Arrays.asList(parser.getRuleNames()), tree);
- viewer.setScale(1.5);
- saveTree(viewer, "./trees/" + removeExtension(file.getName()) + ".png");
- if (parser.getNumberOfSyntaxErrors() != 0) {
- System.err.println("Parse errors: " + fileStr);
+ Python3VisitorImpl visitor = new Python3VisitorImpl();
+ SymbolTable ST = new SymbolTable();
+ Node ast = visitor.visit(tree);
+ ArrayList<SemanticError> errorsWithDup = ast.checkSemantics(ST, 0);
+ ArrayList<SemanticError> errors = Share.removeDuplicates(errorsWithDup);
+ if (!errors.isEmpty()) {
+ System.out.println();
+ System.out.println(fileStr);
+ System.out.println("You had " + errors.size() + " errors:");
+ for (SemanticError e : errors) {
+ System.out.println("\t" + e);
+ }
}
} catch (Exception e) {
@@ -50,54 +56,4 @@ public class ParseAll {
}
}
}
-
- @SuppressWarnings("unused")
- private static String readFile(String filePath) throws IOException {
- StringBuilder content = new StringBuilder();
- try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
- String line;
- while ((line = reader.readLine()) != null) {
- content.append(line).append("\n");
- }
- }
- return content.toString();
- }
-
- @SuppressWarnings("unused")
- private static void showTree(TreeViewer viewer) {
- JFrame frame = new JFrame("Parse Tree");
- JPanel panel = new JPanel();
- panel.add(viewer);
- frame.add(panel);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(800, 600);
- frame.setVisible(true);
- }
-
- private static void saveTree(TreeViewer viewer, String name) {
- try {
- viewer.save(name);
- } catch (Exception e) {
- System.err.println(name);
- e.printStackTrace();
- }
- }
-
- public static String removeExtension(String fileName) {
- int extensionIndex = fileName.lastIndexOf('.');
- if (extensionIndex == -1) {
- return fileName;
- } else {
- return fileName.substring(0, extensionIndex);
- }
- }
-
- public static String getExtension(String fileName) {
- int extensionIndex = fileName.lastIndexOf('.');
- if (extensionIndex == -1) {
- return fileName;
- } else {
- return fileName.substring(extensionIndex + 1);
- }
- }
}
diff --git a/src/ast/Python3VisitorImpl.java b/src/ast/Python3VisitorImpl.java
index 604c8d2..1cf15b7 100644
--- a/src/ast/Python3VisitorImpl.java
+++ b/src/ast/Python3VisitorImpl.java
@@ -12,34 +12,33 @@ import org.antlr.v4.runtime.tree.TerminalNode;
* Overrides each `visitNODE` method from the base class.
*/
public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
+
/**
* Since a root can be a simple_stmts or a compound_stmt, this method
* returns a new `RootNode` with a list of them.
*
- * ```
- * root : NEWLINE* (simple_stmts | compound_stmt)* EOF;
- * ```
+ * ``` root : NEWLINE* (simple_stmts | compound_stmt)* EOF; ```
*/
public Node visitRoot(RootContext ctx) {
- ArrayList<Node> stmts = new ArrayList<Node>();
- ArrayList<Node> compStmts = new ArrayList<Node>();
+ ArrayList<Node> childs = new ArrayList<Node>();
- for (Simple_stmtsContext stm : ctx.simple_stmts()) {
- stmts.add(visit(stm));
- }
- for (Compound_stmtContext stm : ctx.compound_stmt()) {
- compStmts.add(visit(stm));
+ for (int i = 0; i < ctx.getChildCount(); i++) {
+ var child = ctx.getChild(i);
+
+ if (child instanceof Simple_stmtsContext) {
+ childs.add(visit((Simple_stmtsContext) child));
+ } else if (child instanceof Compound_stmtContext) {
+ childs.add(visit((Compound_stmtContext) child));
+ }
}
- return new RootNode(stmts, compStmts);
+ return new RootNode(childs);
}
/**
* Returns a `SimpleStmtsNode`, made by an array of SimpleStmtNode
*
- * ```
- * simple_stmts : simple_stmt (';' simple_stmt)* ';'? NEWLINE ;
- * ```
+ * ``` simple_stmts : simple_stmt (';' simple_stmt)* ';'? NEWLINE ; ```
*/
public Node visitSimple_stmts(Simple_stmtsContext ctx) {
ArrayList<Node> stmts = new ArrayList<Node>();
@@ -55,9 +54,7 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
* Returns a `CompoundNode`. It can be built by a different kind of
* statements, so only one of theme won't be null.
*
- * ```
- * compound_stmt : if_stmt | while_stmt | for_stmt | funcdef ;
- * ```
+ * ``` compound_stmt : if_stmt | while_stmt | for_stmt | funcdef ; ```
*/
public Node visitCompound_stmt(Compound_stmtContext ctx) {
Node ifStmt = null;
@@ -88,9 +85,7 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
* Returns a `SimpleStmtNode`. It can be built by a different kind of
* statements, so only one of theme won't be null.
*
- * ```
- * simple_stmt : assignment | expr | return_stmt | import_stm ;
- * ```
+ * ``` simple_stmt : assignment | expr | return_stmt | import_stm ; ```
*/
public Node visitSimple_stmt(Simple_stmtContext ctx) {
Node assignment = null;
@@ -120,10 +115,8 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
/**
* Returns an `AssignmentNode`. It's made by left side, an assignment and a
* right side.
- *
- * ```
- * assignment : exprlist augassign exprlist ;
- * ```
+ *
+ * ``` assignment : exprlist augassign exprlist ; ```
*/
public Node visitAssignment(AssignmentContext ctx) {
Node lhr = visit(ctx.exprlist(0));
@@ -136,9 +129,7 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
/**
* Returns a `ReturnStmtNode`. The returned exprlist can be null.
*
- * ```
- * return_stmt : 'return' exprlist? ;
- * ```
+ * ``` return_stmt : 'return' exprlist? ; ```
*/
public Node visitReturn_stmt(Return_stmtContext ctx) {
Node exprList = null;
@@ -153,10 +144,8 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
* Returns a `ImportNode`. An import can be made in different ways so we
* check the way in a module is imported (by from, by alias or by star).
*
- * ```
- * import_stm : 'import' dotted_name ('as' NAME)?
- * | 'from' dotted_name 'import' (NAME (',' NAME)* | '*') ;
- * ```
+ * ``` import_stm : 'import' dotted_name ('as' NAME)? | 'from' dotted_name
+ * 'import' (NAME (',' NAME)* | '*') ; ```
*/
public Node visitImport_stm(Import_stmContext ctx) {
boolean isFrom = ctx.FROM() != null;
@@ -177,9 +166,7 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
/**
* Returns a `DottedNameNode` used in `import_stm`.
*
- * ```
- * dotted_name : NAME ('.' NAME)* ;
- * ```
+ * ``` dotted_name : NAME ('.' NAME)* ; ```
*/
public Node visitDotted_name(Dotted_nameContext ctx) {
ArrayList<TerminalNode> names = new ArrayList<TerminalNode>();
@@ -194,9 +181,7 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
/**
* Returns a `FuncdefNode`. A paramlist can be null.
*
- * ```
- * funcdef : 'def' NAME '(' paramlist? ')' ':' block ;
- * ```
+ * ``` funcdef : 'def' NAME '(' paramlist? ')' ':' block ; ```
*/
public Node visitFuncdef(FuncdefContext ctx) {
Node paramlist = null;
@@ -214,9 +199,8 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
* Returns a `ParamlistNode`. We ignore the paramdef with default values
* (eg: is_used=False) because there is no test which uses this feature.
*
- * ```
- * paramlist : paramdef ('=' expr)? (',' paramdef ('=' expr)?)* ;
- *
+ * ``` paramlist : paramdef ('=' expr)? (',' paramdef ('=' expr)?)* ;
+ *
* ```
*/
public Node visitParamlist(ParamlistContext ctx) {
@@ -233,9 +217,7 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
* Returns a `ParamdefNode`. We ignore the paramdef with type annotation
* (eg: x : int) because there is no test which uses this feature.
*
- * ```
- * paramdef : NAME (':' expr)? ;
- * ```
+ * ``` paramdef : NAME (':' expr)? ; ```
*/
public Node visitParamdef(ParamdefContext ctx) {
return new ParamdefNode(ctx.NAME().toString());
@@ -245,11 +227,8 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
* Returns an `AugassignNode`. We don't provide all kinds of assignment
* below.
*
- * ```
- * augassign : '=' | '+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' |
- * '^=' | '<<=' | '>>=' | '**=' | '//='
- * ;
- * ```
+ * ``` augassign : '=' | '+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' |
+ * '|=' | '^=' | '<<=' | '>>=' | '**=' | '//=' ; ```
*/
public Node visitAugassign(AugassignContext ctx) {
Node x = null;
@@ -262,20 +241,36 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
x = new AugassignNode(ctx.SUB_ASSIGN());
} else if (ctx.MULT_ASSIGN() != null) {
x = new AugassignNode(ctx.MULT_ASSIGN());
+ } else if (ctx.AT_ASSIGN() != null) {
+ x = new AugassignNode(ctx.AT_ASSIGN());
} else if (ctx.DIV_ASSIGN() != null) {
x = new AugassignNode(ctx.DIV_ASSIGN());
+ } else if (ctx.MOD_ASSIGN() != null) {
+ x = new AugassignNode(ctx.MOD_ASSIGN());
+ } else if (ctx.AND_ASSIGN() != null) {
+ x = new AugassignNode(ctx.AND_ASSIGN());
+ } else if (ctx.OR_ASSIGN() != null) {
+ x = new AugassignNode(ctx.OR_ASSIGN());
+ } else if (ctx.XOR_ASSIGN() != null) {
+ x = new AugassignNode(ctx.XOR_ASSIGN());
+ } else if (ctx.LEFT_SHIFT_ASSIGN() != null) {
+ x = new AugassignNode(ctx.LEFT_SHIFT_ASSIGN());
+ } else if (ctx.RIGHT_SHIFT_ASSIGN() != null) {
+ x = new AugassignNode(ctx.RIGHT_SHIFT_ASSIGN());
+ } else if (ctx.POWER_ASSIGN() != null) {
+ x = new AugassignNode(ctx.POWER_ASSIGN());
+ } else if (ctx.IDIV_ASSIGN() != null) {
+ x = new AugassignNode(ctx.IDIV_ASSIGN());
}
return x;
}
/**
- * Returns a `IfNode`.
- * FIXME: add support for elif statement.
+ * Returns a `IfNode`. FIXME: add support for elif statement.
*
- * ```
- * if_stmt : 'if' expr ':' block ('elif' expr ':' block)* ('else' ':' block)? ;
- * ```
+ * ``` if_stmt : 'if' expr ':' block ('elif' expr ':' block)* ('else' ':'
+ * block)? ; ```
*/
public Node visitIf_stmt(If_stmtContext ctx) {
var blocks = ctx.block();
@@ -292,9 +287,7 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
/**
* Returns a `WhileStmtNode`. We do not provide 'else' branch.
*
- * ```
- * while_stmt : 'while' expr ':' block ('else' ':' block)? ;
- * ```
+ * ``` while_stmt : 'while' expr ':' block ('else' ':' block)? ; ```
*/
public Node visitWhile_stmt(While_stmtContext ctx) {
Node expr = visit(ctx.expr());
@@ -308,9 +301,7 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
/**
* Returns a `ForSmtNode`. We do not provide 'else' branch.
*
- * ```
- * for_stmt : 'for' exprlist ':' block ('else' ':' block)? ;
- * ```
+ * ``` for_stmt : 'for' exprlist ':' block ('else' ':' block)? ; ```
*/
public Node visitFor_stmt(For_stmtContext ctx) {
Node exprList = visit(ctx.exprlist());
@@ -325,32 +316,30 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
* Returns a `BlockNode`. A block can be be a simple_stmts or a list of
* simple_stms and/or compound_stmt, so we just use a list for each kind.
*
- * ```
- * block : simple_stmts
- * | NEWLINE INDENT (simple_stmts | compound_stmt)+ DEDENT ;
- * ```
+ * ``` block : simple_stmts | NEWLINE INDENT (simple_stmts | compound_stmt)+
+ * DEDENT ; ```
*/
public Node visitBlock(BlockContext ctx) {
- ArrayList<Node> stmts = new ArrayList<Node>();
- ArrayList<Node> compStmts = new ArrayList<Node>();
+ ArrayList<Node> childs = new ArrayList<Node>();
- for (Simple_stmtsContext s : ctx.simple_stmts()) {
- stmts.add(visit(s));
- }
- for (Compound_stmtContext s : ctx.compound_stmt()) {
- compStmts.add(visit(s));
+ for (int i = 0; i < ctx.getChildCount(); i++) {
+ var child = ctx.getChild(i);
+
+ if (child instanceof Simple_stmtsContext) {
+ childs.add(visit((Simple_stmtsContext) child));
+ } else if (child instanceof Compound_stmtContext) {
+ childs.add(visit((Compound_stmtContext) child));
+ }
}
- return new BlockNode(stmts, compStmts);
+ return new BlockNode(childs);
}
/**
* Returns a `CompNode`. It should never be null.
*
- * ```
- * comp_op : '<' | '>' | '==' | '>=' | '<=' | '<>' | '!=' | 'in' | 'not' 'in' |
- * 'is' | 'is' 'not' ;
- * ```
+ * ``` comp_op : '<' | '>' | '==' | '>=' | '<=' | '<>' | '!=' | 'in' | 'not'
+ * 'in' | 'is' | 'is' 'not' ; ```
*/
public Node visitComp_op(Comp_opContext ctx) {
Node comp = null;
@@ -382,13 +371,11 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
* Returns an `ExprNode`. An expession can be a different kind of
* sub-expression. We do not provide all kinds of expr(s).
*
- * ```
- * expr : atom trailer* | expr '**' expr | ('+' | '-' | '~')+ expr | expr ('*' |
- * '@' | '/' | '%' | '//') expr | expr ('+' | '-') expr | expr ('<<' | '>>')
- * expr | expr '&' expr | expr '^' expr | expr '|' expr | 'not' expr | expr
- * comp_op expr | expr 'and' expr | expr 'or' expr | expr 'if' expr 'else' expr
- * ;
- * ```
+ * ``` expr : atom trailer* | expr '**' expr | ('+' | '-' | '~')+ expr |
+ * expr ('*' | '@' | '/' | '%' | '//') expr | expr ('+' | '-') expr | expr
+ * ('<<' | '>>') expr | expr '&' expr | expr '^' expr | expr '|' expr |
+ * 'not' expr | expr comp_op expr | expr 'and' expr | expr 'or' expr | expr
+ * 'if' expr 'else' expr ; ```
*/
public Node visitExpr(ExprContext ctx) {
Node atom = null;
@@ -438,41 +425,57 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
/**
* Returns an `AtomNode`.
- * FIXME: add support for testlist_comp
*
- * ```
- * atom : '(' testlist_comp? ')' | '[' testlist_comp? ']' | '{' testlist_comp?
- * '}' | NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False' ;
- * ```
+ * ``` atom : '(' testlist_comp? ')' | '[' testlist_comp? ']' | '{'
+ * testlist_comp? '}' | NAME | NUMBER | STRING+ | '...' | 'None' | 'True' |
+ * 'False' ; ```
*/
public Node visitAtom(AtomContext ctx) {
+ Testlist_compContext tlc = ctx.testlist_comp();
if (ctx.NUMBER() != null) {
- return new AtomNode(ctx.NUMBER().toString());
+ return new AtomNode(ctx.NUMBER().toString(), null);
+ } else if (ctx.NONE() != null) {
+ return new AtomNode(ctx.NONE().toString(), null);
} else if (ctx.TRUE() != null) {
- return new AtomNode(ctx.TRUE().toString());
+ return new AtomNode(ctx.TRUE().toString(), null);
} else if (ctx.FALSE() != null) {
- return new AtomNode(ctx.FALSE().toString());
+ return new AtomNode(ctx.FALSE().toString(), null);
} else if (ctx.NAME() != null) {
- return new AtomNode(ctx.NAME().toString());
- } else if (ctx.STRING() != null) {
-
+ return new AtomNode(ctx.NAME().toString(), null);
+ } else if (!ctx.STRING().isEmpty()) {
var varName = "";
for (var x : ctx.STRING()) {
varName += x;
}
+ return new AtomNode(varName, null);
+ } else if (ctx.OPEN_BRACE() != null && ctx.CLOSE_BRACE() != null) {
+ return manageCompListContext(tlc);
+ } else if (ctx.OPEN_BRACK() != null && ctx.CLOSE_BRACK() != null) {
+ return manageCompListContext(tlc);
+ } else if (ctx.OPEN_PAREN() != null && ctx.CLOSE_PAREN() != null) {
+ return manageCompListContext(tlc);
+ }
+ return new AtomNode(null, null);
+ }
- return new AtomNode(varName);
+ /**
+ * Supporting function for `visitAtom`. Returns an `AtomNode` with
+ * `testlist_comp` set if the context is not null. Otherwise, returns an
+ * `AtomNode` with nulls.
+ */
+ public AtomNode manageCompListContext(Testlist_compContext tlc) {
+ if (tlc != null) {
+ Node testlist_comp = visit(tlc);
+ return new AtomNode(null, testlist_comp);
}
- return new AtomNode(ctx.NONE().toString());
+ return new AtomNode(null, null);
}
/**
* Returns an `TrailerNode`.
*
- * ```
- * trailer : '(' arglist? ')' | '[' expr (',' expr)* ','? ']' | '.' NAME | '['
- * expr? ':' expr? (':' expr? )? ']' ;
- * ```
+ * ``` trailer : '(' arglist? ')' | '[' expr (',' expr)* ','? ']' | '.' NAME
+ * | '[' expr? ':' expr? (':' expr? )? ']' ; ```
*/
public Node visitTrailer(TrailerContext ctx) {
Node arglist = null;
@@ -491,29 +494,28 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
methodCall = ctx.NAME();
}
- return new TrailerNode(arglist, exprs, methodCall);
+ return new TrailerNode(arglist, exprs, methodCall, ctx.OPEN_PAREN() != null);
}
/**
- * Returns a `Node`.
- * FIXME: what to do in case of list??
+ * Returns a `Node`. FIXME: what to do in case of list??
*
- * ```
- * exprlist : expr (',' expr )* ','? ;
- * ```
+ * ``` exprlist : expr (',' expr )* ','? ; ```
*/
public Node visitExprlist(ExprlistContext ctx) {
- Node exp = visit(ctx.expr(0));
+ ArrayList<Node> exprlist = new ArrayList<Node>();
+
+ for (ExprContext c : ctx.expr()) {
+ exprlist.add(visit(c));
+ }
- return exp;
+ return new ExprListNode(exprlist);
}
/**
* Returns a `ArglistNode`.
*
- * ```
- * arglist : argument (',' argument)* ','? ;
- * ```
+ * ``` arglist : argument (',' argument)* ','? ; ```
*/
public Node visitArglist(ArglistContext ctx) {
ArrayList<Node> arguments = new ArrayList<Node>();
@@ -524,4 +526,56 @@ public class Python3VisitorImpl extends Python3ParserBaseVisitor<Node> {
return new ArglistNode(arguments);
}
+
+ /**
+ * Returns a `TestlistCompNode`.
+ *
+ * ``` testlist_comp : expr (comp_for | (',' expr)* ','?) ; ```
+ */
+ public Node visitTestlist_comp(Testlist_compContext ctx) {
+ ArrayList<Node> exprlist = new ArrayList<Node>();
+
+ for (ExprContext c : ctx.expr()) {
+ exprlist.add(visit(c));
+ }
+ Comp_forContext cfc = ctx.comp_for();
+ Node comp = null;
+ if (cfc != null) {
+ comp = visit(ctx.comp_for());
+ }
+ return new TestlistCompNode(exprlist, comp);
+ }
+
+ /**
+ * Returns a `CompForNode`.
+ *
+ * ``` comp_for : 'for' exprlist 'in' expr comp_iter? ;```
+ */
+ public Node visitComp_for(Comp_forContext ctx) {
+ Node exprlist = visit(ctx.exprlist());
+ Node expr = visit(ctx.expr());
+ Comp_iterContext cic = ctx.comp_iter();
+
+ if (cic != null) {
+ Node comp = visit(ctx.comp_iter());
+ return new CompForNode(exprlist, expr, comp);
+ }
+ return new CompForNode(exprlist, expr, null);
+ }
+
+ /**
+ * Returns a `CompIterNode`.
+ *
+ * ``` comp_iter : comp_for | comp_if ; ;```
+ */
+ public Node visitComp_iter(Comp_iterContext ctx) {
+ // TODO: Implement comp_if
+ // Node iter = visit(ctx.comp_if());
+ Comp_forContext cfc = ctx.comp_for();
+ Node forNode = null;
+ if (cfc != null) {
+ forNode = visit(ctx.comp_for());
+ }
+ return new CompIterNode(forNode);
+ }
}
diff --git a/src/ast/nodes/ArglistNode.java b/src/ast/nodes/ArglistNode.java
index f0c33e1..425e4c6 100644
--- a/src/ast/nodes/ArglistNode.java
+++ b/src/ast/nodes/ArglistNode.java
@@ -1,15 +1,16 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
+import java.util.Arrays;
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `arglist` statement of the grammar.
*/
public class ArglistNode implements Node {
+
protected ArrayList<Node> arguments;
public ArglistNode(ArrayList<Node> arguments) {
@@ -18,15 +19,40 @@ public class ArglistNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
for (var arg : arguments) {
- errors.addAll(arg.checkSemantics(ST, _nesting));
+ if (arg instanceof ExprNode) {
+ ExprNode argExpr = (ExprNode) arg;
+ String argName = argExpr.getId();
+
+ // TODO: check fucking IntType for params
+ // TODO: remove fucking comments
+ if (argName != null) {
+ if (Arrays.asList(bif).contains(argName)) {
+ continue;
+ }
+
+ if (ST.lookup(argName) != null && ST.lookup(argName).getType() instanceof ImportType) {
+ continue;
+ }
+
+ if (ST.nslookup(argName) < 0 && argExpr.typeCheck() instanceof AtomType) {
+ errors.add(new SemanticError("name '" + argName + "' is not defined."));
+ }
+ } else {
+ errors.addAll(arg.checkSemantics(ST, _nesting));
+ }
+ }
}
return errors;
}
+ public int getArgumentNumber() {
+ return arguments.size();
+ }
+
@Override
public Type typeCheck() {
return new VoidType();
diff --git a/src/ast/nodes/AssignmentNode.java b/src/ast/nodes/AssignmentNode.java
index 627e842..558e392 100644
--- a/src/ast/nodes/AssignmentNode.java
+++ b/src/ast/nodes/AssignmentNode.java
@@ -1,33 +1,48 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `assignment` statement of the grammar.
*/
public class AssignmentNode implements Node {
- private Node lhr;
- private Node assign;
- private Node rhr;
+
+ private final ExprListNode lhr;
+ private final Node assign;
+ private final ExprListNode rhr;
public AssignmentNode(Node lhr, Node assign, Node rhr) {
- this.lhr = lhr;
+ this.lhr = (ExprListNode) lhr;
this.assign = assign;
- this.rhr = rhr;
+ this.rhr = (ExprListNode) rhr;
}
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
- errors.addAll(lhr.checkSemantics(ST, _nesting));
+ // errors.addAll(lhr.checkSemantics(ST, _nesting));
errors.addAll(assign.checkSemantics(ST, _nesting));
errors.addAll(rhr.checkSemantics(ST, _nesting));
+ int lsize = lhr.getSize();
+
+ // FIXME: unused variable
+ // int rsize = rhr.getSize();
+ // if (lsize == rsize) {
+ for (int i = 0; i < lsize; i++) {
+ ExprNode latom = (ExprNode) lhr.getElem(i);
+ ST.insert(latom.getId(), new AtomType(), _nesting, "");
+ // ExprNode ratom = (ExprNode) rhr.getElem(i);
+ }
+ // } else {
+ // FIX: sgravata da più problemi che altro
+ // errors.add(new SemanticError("ValueError: different size of left or right side assignment"));
+ // }
+
return errors;
}
diff --git a/src/ast/nodes/AtomNode.java b/src/ast/nodes/AtomNode.java
index 4dcb926..47a15d7 100644
--- a/src/ast/nodes/AtomNode.java
+++ b/src/ast/nodes/AtomNode.java
@@ -1,30 +1,87 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `atom` statement of the grammar.
*/
public class AtomNode implements Node {
+
protected String val;
+ protected TestlistCompNode exprlist;
- public AtomNode(String val) {
+ public AtomNode(String val, Node exprlist) {
this.val = val;
+ this.exprlist = (TestlistCompNode) exprlist;
+ }
+
+ /**
+ * Returns the identifier of the `AtomNode` if it's not `null`, otherwise
+ * returns `null`.
+ */
+ public String getId() {
+ return this.val;
}
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- return new ArrayList<SemanticError>();
+ var errors = new ArrayList();
+
+ if (val != null) {
+ if ((this.typeCheck() instanceof AtomType) && ST.nslookup(this.getId()) < 0) {
+ errors.add(new SemanticError("name '" + this.getId() + "' is not defined."));
+ } else {
+ // System.out.println("exist " + this.typeCheck());
+ }
+ }
+
+ if (exprlist != null) {
+ errors.addAll(exprlist.checkSemantics(ST, _nesting));
+ }
+
+ return errors;
}
- // FIXME: this type for atom
+ // ENHANCE: return more specific types
@Override
public Type typeCheck() {
- return new AtomType();
+ if (this.val == null) {
+ return new VoidType();
+ }
+
+ Pattern noneVariable = Pattern.compile("^(None)$");
+ Pattern booleanVariable = Pattern.compile("^(True|False)$");
+ Pattern reservedWords = Pattern.compile("^(continue|break|int|float)$");
+ // this regex should match every possible atom name written in this format: CHAR
+ // (CHAR | DIGIT)*
+ Pattern simpleVariable = Pattern.compile("^[a-zA-Z][a-zA-Z0-9]*$", Pattern.CASE_INSENSITIVE);
+
+ Matcher noneVariableMatcher = noneVariable.matcher(this.val);
+ Matcher booleanVariableMatcher = booleanVariable.matcher(this.val);
+ Matcher reservedWordsMatcher = reservedWords.matcher(this.val);
+ Matcher simpleVariableMatcher = simpleVariable.matcher(this.val);
+
+ boolean matchFoundNone = noneVariableMatcher.find();
+ boolean matchFoundBoolean = booleanVariableMatcher.find();
+ boolean matchFoundContinueBreak = reservedWordsMatcher.find();
+ boolean matchFoundSimpleVariable = simpleVariableMatcher.find();
+
+ if (matchFoundBoolean) {
+ return new BoolType();
+ } else if (matchFoundContinueBreak) {
+ return new ReservedWordsType();
+ } else if (matchFoundNone) {
+ return new NoneType();
+ } else if (matchFoundSimpleVariable) {
+ return new AtomType(); // could be a variable or a fuction
+ } else {
+ return new VoidType(); // could be any type of data
+ }
}
// TODO: add code generation for atom node
@@ -35,6 +92,7 @@ public class AtomNode implements Node {
@Override
public String toPrint(String prefix) {
+ // FIXME: can be a testlist_comp with two expr and two atoms
if (val != null) {
return prefix + "Atom(" + val + ")\n";
}
diff --git a/src/ast/nodes/AugassignNode.java b/src/ast/nodes/AugassignNode.java
index 629fbcd..7ced63e 100644
--- a/src/ast/nodes/AugassignNode.java
+++ b/src/ast/nodes/AugassignNode.java
@@ -12,7 +12,8 @@ import org.antlr.v4.runtime.tree.TerminalNode;
* Node for the `augassign` statement of the grammar.
*/
public class AugassignNode implements Node {
- private TerminalNode val;
+
+ private final TerminalNode val;
public AugassignNode(TerminalNode val) {
this.val = val;
@@ -20,7 +21,7 @@ public class AugassignNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- return new ArrayList<SemanticError>();
+ return new ArrayList();
}
// FIXME: use the right type
diff --git a/src/ast/nodes/BlockNode.java b/src/ast/nodes/BlockNode.java
index 6b07f49..d9a151d 100644
--- a/src/ast/nodes/BlockNode.java
+++ b/src/ast/nodes/BlockNode.java
@@ -1,16 +1,29 @@
package ast.nodes;
-import java.util.ArrayList;
-
import ast.types.*;
+import java.util.ArrayList;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
/**
- * Node for `block` statement of the grammar.
- * It extends the `RootNode`.
+ * Node for `block` statement of the grammar. It extends the `RootNode`.
*/
public class BlockNode extends RootNode {
- public BlockNode(ArrayList<Node> stmts, ArrayList<Node> compoundStmts) {
- super(stmts, compoundStmts);
+
+ public BlockNode(ArrayList<Node> childs) {
+ super(childs);
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ ArrayList<SemanticError> errors = new ArrayList();
+
+ // Check semantics for each child
+ for (Node child : childs) {
+ errors.addAll(child.checkSemantics(ST, _nesting));
+ }
+
+ return errors;
}
@Override
@@ -23,11 +36,8 @@ public class BlockNode extends RootNode {
String str = prefix + "Block\n";
prefix += " ";
- for (Node stmt : stmts) {
- str += stmt.toPrint(prefix);
- }
- for (Node stmt : compoundStmts) {
- str += stmt.toPrint(prefix);
+ for (Node child : childs) {
+ str += child.toPrint(prefix);
}
return str;
diff --git a/src/ast/nodes/CompForNode.java b/src/ast/nodes/CompForNode.java
new file mode 100644
index 0000000..b7c6924
--- /dev/null
+++ b/src/ast/nodes/CompForNode.java
@@ -0,0 +1,58 @@
+package ast.nodes;
+
+import ast.types.*;
+import java.util.ArrayList;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
+
+/**
+ * Node for the `comp_for` statement of the grammar. 'for' exprlist 'in' expr
+ * comp_iter?
+ */
+public class CompForNode implements Node {
+
+ protected ExprListNode exprlist;
+ protected ExprNode single_expr;
+ protected CompIterNode comp_iter;
+
+ public CompForNode(Node exprlist, Node single_expr, Node comp_iter) {
+ this.exprlist = (ExprListNode) exprlist;
+ this.single_expr = (ExprNode) single_expr;
+ this.comp_iter = (CompIterNode) comp_iter;
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ ArrayList<SemanticError> errors = new ArrayList();
+
+ errors.addAll(exprlist.checkSemantics(ST, _nesting));
+ errors.addAll(single_expr.checkSemantics(ST, _nesting));
+ if (comp_iter != null) {
+ errors.addAll(comp_iter.checkSemantics(ST, _nesting));
+ }
+ return errors;
+ }
+
+ @Override
+ public Type typeCheck() {
+ return new VoidType();
+ }
+
+ // TODO: add code generation for arglist node
+ @Override
+ public String codeGeneration() {
+ return "";
+ }
+
+ @Override
+ public String toPrint(String prefix) {
+ String str = prefix + "CompForNode\n";
+
+ prefix += " ";
+ str += exprlist.toPrint(prefix);
+ str += single_expr.toPrint(prefix);
+ str += comp_iter.toPrint(prefix);
+ return str;
+ }
+
+}
diff --git a/src/ast/nodes/CompIterNode.java b/src/ast/nodes/CompIterNode.java
new file mode 100644
index 0000000..8de9f2f
--- /dev/null
+++ b/src/ast/nodes/CompIterNode.java
@@ -0,0 +1,50 @@
+package ast.nodes;
+
+import ast.types.*;
+import java.util.ArrayList;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
+
+/**
+ * Node for the `comp_iter` statement of the grammar.
+ */
+public class CompIterNode implements Node {
+
+ protected CompForNode comp_for;
+ // protected CompIfNode compIfNode;
+
+ public CompIterNode(Node comp_for) {
+ this.comp_for = (CompForNode) comp_for;
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ ArrayList<SemanticError> errors = new ArrayList();
+
+ if (comp_for != null) {
+ errors.addAll(comp_for.checkSemantics(ST, _nesting));
+ }
+ return errors;
+ }
+
+ @Override
+ public Type typeCheck() {
+ return new VoidType();
+ }
+
+ // TODO: add code generation for arglist node
+ @Override
+ public String codeGeneration() {
+ return "";
+ }
+
+ @Override
+ public String toPrint(String prefix) {
+ String str = prefix + "CompIterNode\n";
+
+ prefix += " ";
+ str += comp_for.toPrint(prefix);
+ return str;
+ }
+
+}
diff --git a/src/ast/nodes/CompNode.java b/src/ast/nodes/CompNode.java
index 33976bf..22906df 100644
--- a/src/ast/nodes/CompNode.java
+++ b/src/ast/nodes/CompNode.java
@@ -11,7 +11,8 @@ import org.antlr.v4.runtime.tree.TerminalNode;
* Node for the `comp_op` statement of the grammar.
*/
public class CompNode implements Node {
- private TerminalNode op;
+
+ private final TerminalNode op;
public CompNode(TerminalNode op) {
this.op = op;
@@ -19,7 +20,7 @@ public class CompNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- return new ArrayList<SemanticError>();
+ return new ArrayList();
}
// TODO: it should be boolean, right?
diff --git a/src/ast/nodes/CompoundNode.java b/src/ast/nodes/CompoundNode.java
index e64be9e..845f05e 100644
--- a/src/ast/nodes/CompoundNode.java
+++ b/src/ast/nodes/CompoundNode.java
@@ -1,19 +1,19 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `compound_node` statement of the grammar.
*/
public class CompoundNode implements Node {
- private Node ifNode;
- private Node funcDef;
- private Node forStmt;
- private Node whileStmt;
+
+ private final Node ifNode;
+ private final Node funcDef;
+ private final Node forStmt;
+ private final Node whileStmt;
public CompoundNode(Node ifNode, Node funcDef, Node forStmt, Node whileStmt) {
this.ifNode = ifNode;
@@ -24,7 +24,7 @@ public class CompoundNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
if (ifNode != null) {
errors.addAll(ifNode.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/DottedNameNode.java b/src/ast/nodes/DottedNameNode.java
index 46d1b61..23f14c1 100644
--- a/src/ast/nodes/DottedNameNode.java
+++ b/src/ast/nodes/DottedNameNode.java
@@ -11,6 +11,7 @@ import org.antlr.v4.runtime.tree.TerminalNode;
* Node for the `dooted_name` statement of the grammar.
*/
public class DottedNameNode implements Node {
+
protected ArrayList<TerminalNode> names;
public DottedNameNode(ArrayList<TerminalNode> names) {
@@ -19,14 +20,18 @@ public class DottedNameNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
+
+ for (int i = 0; i < names.size(); ++i) {
+ ST.insert(names.get(i).toString(), this.typeCheck(), _nesting, null);
+ }
return errors;
}
@Override
public Type typeCheck() {
- return new VoidType();
+ return new ImportType();
}
// NOTE: we do not provide code generation for this node in the same way
diff --git a/src/ast/nodes/ExprListNode.java b/src/ast/nodes/ExprListNode.java
new file mode 100644
index 0000000..4760db8
--- /dev/null
+++ b/src/ast/nodes/ExprListNode.java
@@ -0,0 +1,68 @@
+package ast.nodes;
+
+import ast.types.*;
+import java.util.ArrayList;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
+
+/**
+ * Node for the `expr_list` statement of the grammar.
+ */
+public class ExprListNode implements Node {
+
+ private final ArrayList<Node> exprs;
+
+ public ExprListNode(ArrayList<Node> exprs) {
+ this.exprs = exprs;
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ ArrayList<SemanticError> errors = new ArrayList<>();
+
+ for (var expr : exprs) {
+ errors.addAll(expr.checkSemantics(ST, _nesting));
+ }
+
+ return errors;
+ }
+
+ public int getSize() {
+ return exprs.size();
+ }
+
+ /**
+ * Returns the i-th expressions of `exprs` field. If the index is greater or
+ * equals than the size return `null`.
+ */
+ public Node getElem(int i) {
+ if (i >= this.exprs.size()) {
+ return null;
+ }
+ return exprs.get(i);
+ }
+
+ @Override
+ public Type typeCheck() {
+ return new VoidType();
+ }
+
+ // TODO: code generation for expr list
+ @Override
+ public String codeGeneration() {
+ return "";
+ }
+
+ @Override
+ public String toPrint(String prefix) {
+ String str = prefix + "ExprList\n";
+
+ prefix += " ";
+ for (var param : exprs) {
+ str += param.toPrint(prefix);
+ }
+
+ return str;
+ }
+
+}
diff --git a/src/ast/nodes/ExprNode.java b/src/ast/nodes/ExprNode.java
index 25c2016..873d537 100644
--- a/src/ast/nodes/ExprNode.java
+++ b/src/ast/nodes/ExprNode.java
@@ -1,34 +1,97 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
+import java.util.Arrays;
+import semanticanalysis.STentry;
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `expr` statement of the grammar.
*/
public class ExprNode implements Node {
- private Node atom;
- private Node compOp;
- private String op;
- private ArrayList<Node> exprs;
- private ArrayList<Node> trailers;
+
+ private final AtomNode atom;
+ private final Node compOp;
+ private final String op;
+ private final ArrayList<Node> exprs;
+ private final ArrayList<Node> trailers;
public ExprNode(Node atom, Node compOp, ArrayList<Node> exprs, String op, ArrayList<Node> trailers) {
- this.atom = atom;
+ this.atom = (AtomNode) atom;
this.compOp = compOp;
this.exprs = exprs;
this.op = op;
this.trailers = trailers;
}
- @Override
- public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ /**
+ * Returns the i-th expressions of `exprs` field. If the index is greater or
+ * equals than the size return `null`.
+ */
+ public Node getExpr(int i) {
+ if (i >= this.exprs.size()) {
+ return null;
+ }
+ return this.exprs.get(i);
+ }
+
+ /**
+ * Returns the identifier of the `AtomNode` if it's not `null`, otherwise
+ * returns `null`.
+ */
+ public String getId() {
if (atom != null) {
+ return ((AtomNode) this.atom).getId();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ ArrayList<SemanticError> errors = new ArrayList();
+
+ // check if the atom is a function
+ if (atom != null && !trailers.isEmpty()) {
+
+ // check if the atom is not a built-in function
+ if (!Arrays.asList(bif).contains(atom.getId())) {
+
+ errors.addAll(atom.checkSemantics(ST, _nesting));
+
+ TrailerNode trailer = (TrailerNode) trailers.get(0);
+ String funName = atom.getId();
+
+ // TODO: it isnt a function, it could be a variable
+ STentry fun = ST.lookup(funName);
+
+ if (fun != null && !(fun.getType() instanceof ImportType)) {
+ if (!(fun.getType() instanceof FunctionType)) {
+ for (var t : trailers) {
+ errors.addAll(t.checkSemantics(ST, _nesting));
+ }
+
+ } else {
+ FunctionType ft = (FunctionType) fun.getType();
+ int paramNumber = ft.getParamNumber();
+ int argNumber = trailer.getArgumentNumber();
+
+ if (paramNumber != argNumber) {
+ errors.add(new SemanticError(funName + "() takes " + String.valueOf(paramNumber)
+ + " positional arguments but " + String.valueOf(argNumber) + " were given."));
+ }
+ }
+ }
+ } else {
+ for (var trailer : trailers) {
+ errors.addAll(trailer.checkSemantics(ST, _nesting));
+ }
+
+ }
+ } else if (atom != null) {
errors.addAll(atom.checkSemantics(ST, _nesting));
}
@@ -40,16 +103,16 @@ public class ExprNode implements Node {
errors.addAll(expr.checkSemantics(ST, _nesting));
}
- for (var trailer : trailers) {
- errors.addAll(trailer.checkSemantics(ST, _nesting));
- }
-
return errors;
}
// FIXME: type for the expr
@Override
public Type typeCheck() {
+ if (this.atom != null) {
+ return this.atom.typeCheck();
+ }
+
return new VoidType();
}
@@ -73,11 +136,11 @@ public class ExprNode implements Node {
}
for (var expr : exprs) {
- str += expr.toPrint(prefix);
+ str = expr.toPrint(prefix);
}
for (var trailer : trailers) {
- str += trailer.toPrint(prefix);
+ str = trailer.toPrint(prefix);
}
if (op != null) {
diff --git a/src/ast/nodes/ForStmtNode.java b/src/ast/nodes/ForStmtNode.java
index 6d94bb2..74c6ffc 100644
--- a/src/ast/nodes/ForStmtNode.java
+++ b/src/ast/nodes/ForStmtNode.java
@@ -1,26 +1,56 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `for_stmt` statement of the grammar.
*/
public class ForStmtNode implements Node {
- private Node exprList;
- private Node block;
+
+ private final Node exprList;
+ private final Node block;
public ForStmtNode(Node exprList, Node block) {
this.exprList = exprList;
this.block = block;
}
+ /**
+ * This methods check the semantics of the operation `for i in list: block`.
+ *
+ * After the `for` keyword, it's parsed as a list of expression. We verified
+ * that the last expression is always gonna be `expr comp_op expr`. We
+ * comp_op must be the `in` keyword. `i` could be of any lenght (e.g. `a, b,
+ * c`).
+ *
+ * In this function we define the following approch: we save in the
+ * SymbolTable every atom until the last expression in the expression's
+ * list. For the last element, we know that is in the `expr comp_op expr`
+ * format, so we take the left element and save it in the SymbolicTable as
+ * an atom.
+ */
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
+
+ // Save every atom in the expression's list, except the last one
+ var l = (ExprListNode) exprList;
+ for (int i = 0; i < l.getSize() - 1; ++i) {
+ var e = (ExprNode) l.getElem(i);
+ ST.insert(e.getId(), e.typeCheck(), _nesting, "");
+ }
+
+ // Manage the last expression of expression's list
+ // Get the ExprNode
+ var left = (ExprNode) l.getElem(l.getSize() - 1);
+ // Get the left side expression of the operation, that
+ // corresponds to the first element of the expression list.
+ var atomLeft = (ExprNode) left.getExpr(0);
+ // ENHANCE: check that the comp_op is the `in` keyword
+ ST.insert(atomLeft.getId(), atomLeft.typeCheck(), _nesting, "");
errors.addAll(exprList.checkSemantics(ST, _nesting));
errors.addAll(block.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/FuncdefNode.java b/src/ast/nodes/FuncdefNode.java
index 67bc772..c4f5846 100644
--- a/src/ast/nodes/FuncdefNode.java
+++ b/src/ast/nodes/FuncdefNode.java
@@ -1,7 +1,9 @@
package ast.nodes;
import java.util.ArrayList;
+import java.util.HashMap;
+import semanticanalysis.STentry;
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
import ast.types.*;
@@ -11,9 +13,10 @@ import org.antlr.v4.runtime.tree.TerminalNode;
* Node for the `funcdef` statement of the grammar.
*/
public class FuncdefNode implements Node {
- private TerminalNode name;
- private Node paramlist;
- private Node block;
+
+ private final TerminalNode name;
+ private final Node paramlist;
+ private final Node block;
public FuncdefNode(TerminalNode name, Node paramlist, Node block) {
this.name = name;
@@ -23,13 +26,30 @@ public class FuncdefNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
+ int paramNumber = ((ParamlistNode) paramlist).getParamNumber();
+ Type returnType = this.block.typeCheck();
+ FunctionType ft = new FunctionType(paramNumber, returnType);
+
+ ST.insert(this.name.toString(), ft, _nesting, "");
+
+ HashMap<String, STentry> HM = new HashMap();
+
+ ST.add(HM);
+
+ ST.insert(this.name.toString(), ft, _nesting + 1, "");
if (paramlist != null) {
- errors.addAll(paramlist.checkSemantics(ST, _nesting));
+ errors.addAll(paramlist.checkSemantics(ST, _nesting + 1));
}
- errors.addAll(block.checkSemantics(ST, _nesting));
+ // TODO: think to the fucking offset
+ // Offset is increased for the possible return value
+ ST.increaseoffset();
+
+ errors.addAll(block.checkSemantics(ST, _nesting + 1));
+
+ ST.remove();
return errors;
}
@@ -46,6 +66,7 @@ public class FuncdefNode implements Node {
return "";
}
+ @Override
public String toPrint(String prefix) {
String str = prefix + "Funcdef(" + name + ")\n";
diff --git a/src/ast/nodes/IfNode.java b/src/ast/nodes/IfNode.java
index 50dde4a..b0e1ddb 100644
--- a/src/ast/nodes/IfNode.java
+++ b/src/ast/nodes/IfNode.java
@@ -1,18 +1,18 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `if` statement of the grammar.
*/
public class IfNode implements Node {
- private Node guard;
- private Node thenbranch;
- private Node elsebranch;
+
+ private final Node guard;
+ private final Node thenbranch;
+ private final Node elsebranch;
public IfNode(Node guard, Node thenbranch, Node elsebranch) {
this.guard = guard;
@@ -22,7 +22,7 @@ public class IfNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
errors.addAll(guard.checkSemantics(ST, _nesting));
errors.addAll(thenbranch.checkSemantics(ST, _nesting));
@@ -39,14 +39,14 @@ public class IfNode implements Node {
if (guard.typeCheck() instanceof BoolType) {
Type thenexp = thenbranch.typeCheck();
Type elseexp = elsebranch.typeCheck();
- if (thenexp.getClass().equals(elseexp.getClass()))
- return thenexp;
- else {
- System.out.println("Type Error: incompatible types in then and else branches");
+ if (thenexp.getClass().equals(elseexp.getClass())) {
+ return thenexp;
+ }else {
+ System.out.println("Type Error: incompatible types in then and else branches.");
return new ErrorType();
}
} else {
- System.out.println("Type Error: non boolean condition in if");
+ System.out.println("Type Error: non boolean condition in if.");
return new ErrorType();
}
}
diff --git a/src/ast/nodes/ImportNode.java b/src/ast/nodes/ImportNode.java
index e264c99..7e95ee3 100644
--- a/src/ast/nodes/ImportNode.java
+++ b/src/ast/nodes/ImportNode.java
@@ -1,20 +1,20 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `import_stmt` statement of the grammar.
*/
public class ImportNode implements Node {
- private Node dottedName;
- private boolean isFrom;
- private boolean importAs;
- private boolean importAll;
- private ArrayList<String> names;
+
+ private final Node dottedName;
+ private final boolean isFrom;
+ private final boolean importAs;
+ private final boolean importAll;
+ private final ArrayList<String> names;
public ImportNode(Node dottedName, boolean isFrom, boolean importAs, boolean importAll,
ArrayList<String> names) {
@@ -27,14 +27,26 @@ public class ImportNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
+
+ if (isFrom) {
+ for (int i = 0; i < names.size(); ++i) {
+ ST.insert(names.get(i), this.typeCheck(), _nesting, null);
+ }
+ } else {
+ errors.addAll(dottedName.checkSemantics(ST, _nesting));
+ }
+
+ if (importAs) {
+ ST.insert(names.get(names.size() - 1), this.typeCheck(), _nesting, null);
+ }
return errors;
}
@Override
public Type typeCheck() {
- return new VoidType();
+ return new ImportType();
}
// NOTE: we do not want to provide a code generation for this statement
@@ -63,8 +75,9 @@ public class ImportNode implements Node {
}
for (int i = 0; i < names.size(); ++i) {
- if (i == 0 && importAs)
+ if (i == 0 && importAs) {
continue;
+ }
str += prefix + names.get(i) + "\n";
}
diff --git a/src/ast/nodes/Node.java b/src/ast/nodes/Node.java
index 949531e..9fb58b8 100644
--- a/src/ast/nodes/Node.java
+++ b/src/ast/nodes/Node.java
@@ -1,19 +1,92 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Base interface for a Node.
*/
public interface Node {
+
+ static final String[] bif = {
+ "abs",
+ "aiter",
+ "all",
+ "anext",
+ "any",
+ "ascii",
+ "bin",
+ "bool",
+ "breakpoint",
+ "bytearray",
+ "bytes",
+ "callable",
+ "chr",
+ "classmethod",
+ "compile",
+ "complex",
+ "delattr",
+ "dict",
+ "dir",
+ "divmod",
+ "enumerate",
+ "eval",
+ "exec",
+ "exit",
+ "filter",
+ "float",
+ "format",
+ "frozenset",
+ "getattr",
+ "globals",
+ "hasattr",
+ "hash",
+ "help",
+ "hex",
+ "id",
+ "input",
+ "int",
+ "isinstance",
+ "issubclass",
+ "iter",
+ "len",
+ "list",
+ "locals",
+ "map",
+ "max",
+ "memoryview",
+ "min",
+ "next",
+ "object",
+ "oct",
+ "open",
+ "ord",
+ "pow",
+ "print",
+ "property",
+ "range",
+ "repr",
+ "reversed",
+ "round",
+ "set",
+ "setattr",
+ "slice",
+ "sorted",
+ "staticmethod",
+ "str",
+ "sum",
+ "super",
+ "tuple",
+ "type",
+ "vars",
+ "zip",
+ "__import__"};
+
/**
* Checks semantics for a given node for a SymbolTable ST and a level of
- * nesting.
- * Returns a list of `SemanticError`.
+ * nesting. Returns a list of `SemanticError`.
*/
ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting);
@@ -29,8 +102,8 @@ public interface Node {
String codeGeneration();
/**
- * Returns a string for a given node with a prefix.
- * It used when an AST wants to be visualized on screen.
+ * Returns a string for a given node with a prefix. It used when an AST
+ * wants to be visualized on screen.
*/
String toPrint(String prefix);
}
diff --git a/src/ast/nodes/ParamdefNode.java b/src/ast/nodes/ParamdefNode.java
index 481282e..6cdb2d0 100644
--- a/src/ast/nodes/ParamdefNode.java
+++ b/src/ast/nodes/ParamdefNode.java
@@ -1,14 +1,32 @@
package ast.nodes;
import ast.types.*;
+import java.util.ArrayList;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
/**
* Node for the `paramdef` statement of the grammar. Extends the `AtomNode`
* class.
*/
public class ParamdefNode extends AtomNode {
+
public ParamdefNode(String val) {
- super(val);
+ super(val, null);
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ var errors = new ArrayList();
+ String paramName = this.getId();
+
+ if (!ST.top_lookup(paramName)) {
+ ST.insert(paramName, this.typeCheck(), _nesting, "");
+ } else {
+ errors.add(new SemanticError("Duplicate argument '" + paramName + "' in function definition."));
+ }
+
+ return errors;
}
// FIXME: it should returns the param' type
diff --git a/src/ast/nodes/ParamlistNode.java b/src/ast/nodes/ParamlistNode.java
index 144eb13..cf75d08 100644
--- a/src/ast/nodes/ParamlistNode.java
+++ b/src/ast/nodes/ParamlistNode.java
@@ -1,16 +1,16 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `param_list` statement of the grammar.
*/
public class ParamlistNode implements Node {
- private ArrayList<Node> params;
+
+ private final ArrayList<Node> params;
public ParamlistNode(ArrayList<Node> _params) {
params = _params;
@@ -18,7 +18,7 @@ public class ParamlistNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
for (var param : params) {
errors.addAll(param.checkSemantics(ST, _nesting));
@@ -27,6 +27,10 @@ public class ParamlistNode implements Node {
return errors;
}
+ public int getParamNumber() {
+ return params.size();
+ }
+
@Override
public Type typeCheck() {
return new VoidType();
diff --git a/src/ast/nodes/ReturnStmtNode.java b/src/ast/nodes/ReturnStmtNode.java
index 0f2dd74..8e34813 100644
--- a/src/ast/nodes/ReturnStmtNode.java
+++ b/src/ast/nodes/ReturnStmtNode.java
@@ -1,16 +1,16 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `return_stmt` statement of the grammar.
*/
public class ReturnStmtNode implements Node {
- private Node exprList;
+
+ private final Node exprList;
public ReturnStmtNode(Node exprList) {
this.exprList = exprList;
@@ -18,7 +18,7 @@ public class ReturnStmtNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
if (this.exprList != null) {
errors.addAll(this.exprList.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/RootNode.java b/src/ast/nodes/RootNode.java
index e0989e8..5bbce8c 100644
--- a/src/ast/nodes/RootNode.java
+++ b/src/ast/nodes/RootNode.java
@@ -1,36 +1,41 @@
package ast.nodes;
-import java.util.ArrayList;
-
-import semanticanalysis.SemanticError;
-import semanticanalysis.SymbolTable;
import ast.types.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import semanticanalysis.*;
/**
* Node for the `root` statement of the grammar.
*/
public class RootNode implements Node {
+
// stms and compundStmts are protected because they are reused for a
// BlockNode
- protected ArrayList<Node> stmts;
- protected ArrayList<Node> compoundStmts;
+ protected ArrayList<Node> childs;
- public RootNode(ArrayList<Node> stmts, ArrayList<Node> compoundStmts) {
- this.stmts = stmts;
- this.compoundStmts = compoundStmts;
+ public RootNode(ArrayList<Node> childs) {
+ this.childs = childs;
}
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
- for (Node stmt : stmts) {
- errors.addAll(stmt.checkSemantics(ST, _nesting));
- }
- for (Node stmt : compoundStmts) {
- errors.addAll(stmt.checkSemantics(ST, _nesting));
+ // Create a new HashMap for the current scope
+ HashMap<String, STentry> HM = new HashMap();
+
+ // Add the HashMap to the SymbolTable
+ ST.add(HM);
+
+ // Check semantics for each child
+ for (Node child : childs) {
+ errors.addAll(child.checkSemantics(ST, _nesting));
}
+ // Remove the HashMap from the SymbolTable
+ ST.remove();
+
return errors;
}
@@ -51,11 +56,8 @@ public class RootNode implements Node {
prefix += " ";
- for (Node stmt : stmts) {
- str += stmt.toPrint(prefix);
- }
- for (Node stmt : compoundStmts) {
- str += stmt.toPrint(prefix);
+ for (Node child : childs) {
+ str += child.toPrint(prefix);
}
return str;
diff --git a/src/ast/nodes/SimpleStmtNode.java b/src/ast/nodes/SimpleStmtNode.java
index 5f844cb..b2bc880 100644
--- a/src/ast/nodes/SimpleStmtNode.java
+++ b/src/ast/nodes/SimpleStmtNode.java
@@ -1,19 +1,19 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `simple_stmt` statement of the grammar.
*/
public class SimpleStmtNode implements Node {
- private Node assignment;
- private Node expr;
- private Node returnStmt;
- private Node importStmt;
+
+ private final Node assignment;
+ private final Node expr;
+ private final Node returnStmt;
+ private final Node importStmt;
public SimpleStmtNode(Node assignment, Node expr, Node returnStmt, Node importStmt) {
this.assignment = assignment;
@@ -24,7 +24,7 @@ public class SimpleStmtNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
if (assignment != null) {
errors.addAll(assignment.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/SimpleStmtsNode.java b/src/ast/nodes/SimpleStmtsNode.java
index 66c8e2c..ae1044b 100644
--- a/src/ast/nodes/SimpleStmtsNode.java
+++ b/src/ast/nodes/SimpleStmtsNode.java
@@ -1,16 +1,16 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `simple_stmts` statement of the grammar.
*/
public class SimpleStmtsNode implements Node {
- private ArrayList<Node> stmts;
+
+ private final ArrayList<Node> stmts;
public SimpleStmtsNode(ArrayList<Node> stmts) {
this.stmts = stmts;
@@ -18,7 +18,7 @@ public class SimpleStmtsNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
for (Node stmt : stmts) {
errors.addAll(stmt.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/TestlistCompNode.java b/src/ast/nodes/TestlistCompNode.java
new file mode 100644
index 0000000..32049f5
--- /dev/null
+++ b/src/ast/nodes/TestlistCompNode.java
@@ -0,0 +1,82 @@
+package ast.nodes;
+
+import ast.types.*;
+import java.util.ArrayList;
+import semanticanalysis.SemanticError;
+import semanticanalysis.SymbolTable;
+
+/**
+ * Node for the `testlist_comp` statement of the grammar.
+ */
+public class TestlistCompNode implements Node {
+
+ private final ArrayList<Node> exprs;
+ private final CompForNode comp;
+
+ public TestlistCompNode(ArrayList<Node> exprs, Node comp) {
+ this.exprs = exprs;
+ this.comp = (CompForNode) comp;
+ }
+
+ @Override
+ public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
+ ArrayList<SemanticError> errors = new ArrayList<>();
+
+ if (comp != null) {
+ // if comp is set, then we save the atom in the ST (we assume the first expr is
+ // an atom)
+ String id = ((ExprNode) exprs.get(0)).getId();
+ Type t = ((ExprNode) exprs.get(0)).typeCheck();
+ ST.insert(id, t, _nesting, "");
+ // errors.addAll(comp.checkSemantics(ST, _nesting));
+ } else {
+ // if comp is not set, then exprs is a list of 1 or more element
+ for (var param : exprs) {
+ var exp = (ExprNode) param;
+ ST.insert(exp.getId(), exp.typeCheck(), _nesting, "");
+ errors.addAll(param.checkSemantics(ST, _nesting));
+ }
+ }
+
+ return errors;
+ }
+
+ public int getSize() {
+ return exprs.size();
+ }
+
+ /**
+ * Returns the i-th expressions of `exprs` field. If the index is greater or
+ * equals than the size return `null`.
+ */
+ public Node getElem(int i) {
+ if (i >= this.exprs.size()) {
+ return null;
+ }
+ return exprs.get(i);
+ }
+
+ @Override
+ public Type typeCheck() {
+ return new VoidType();
+ }
+
+ // TODO: code generation for expr list
+ @Override
+ public String codeGeneration() {
+ return "";
+ }
+
+ @Override
+ public String toPrint(String prefix) {
+ String str = prefix + "Testlist_comp\n";
+
+ prefix += " ";
+ for (var param : exprs) {
+ str += param.toPrint(prefix);
+ }
+
+ return str;
+ }
+
+}
diff --git a/src/ast/nodes/TrailerNode.java b/src/ast/nodes/TrailerNode.java
index b0a0ee7..aaa72f3 100644
--- a/src/ast/nodes/TrailerNode.java
+++ b/src/ast/nodes/TrailerNode.java
@@ -11,22 +11,25 @@ import org.antlr.v4.runtime.tree.TerminalNode;
* Node for the `trailer` statement of the grammar.
*/
public class TrailerNode implements Node {
- private Node arglist;
- private ArrayList<Node> exprs;
- private TerminalNode methodCall;
- private boolean isEmpty;
- public TrailerNode(Node arglist, ArrayList<Node> exprs, TerminalNode methodCall) {
+ private final Node arglist;
+ private final ArrayList<Node> exprs;
+ private final TerminalNode methodCall;
+ private final boolean isParenthesis;
+ private final boolean isEmpty;
+
+ public TrailerNode(Node arglist, ArrayList<Node> exprs, TerminalNode methodCall, boolean isParenthesis) {
this.arglist = arglist;
this.exprs = exprs;
this.methodCall = methodCall;
+ this.isParenthesis = isParenthesis;
- this.isEmpty = (this.arglist == null && this.exprs.size() == 0 && this.methodCall == null);
+ this.isEmpty = (this.arglist == null && this.exprs.isEmpty() && this.methodCall == null);
}
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
if (arglist != null) {
errors.addAll(arglist.checkSemantics(ST, _nesting));
@@ -39,6 +42,18 @@ public class TrailerNode implements Node {
return errors;
}
+ public int getArgumentNumber() {
+ if (arglist == null) {
+ return 0;
+ }
+
+ return ((ArglistNode) arglist).getArgumentNumber();
+ }
+
+ public boolean isParenthesis() {
+ return this.isParenthesis;
+ }
+
@Override
public Type typeCheck() {
return new VoidType();
diff --git a/src/ast/nodes/WhileStmtNode.java b/src/ast/nodes/WhileStmtNode.java
index 6353ec1..1db01ea 100644
--- a/src/ast/nodes/WhileStmtNode.java
+++ b/src/ast/nodes/WhileStmtNode.java
@@ -1,17 +1,17 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `while_stmt` statement of the grammar.
*/
public class WhileStmtNode implements Node {
- private Node expr;
- private Node block;
+
+ private final Node expr;
+ private final Node block;
public WhileStmtNode(Node expr, Node block) {
this.expr = expr;
@@ -20,7 +20,7 @@ public class WhileStmtNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
errors.addAll(expr.checkSemantics(ST, _nesting));
errors.addAll(block.checkSemantics(ST, _nesting));
diff --git a/src/ast/types/AtomType.java b/src/ast/types/AtomType.java
index 0387ec1..fc1c69e 100644
--- a/src/ast/types/AtomType.java
+++ b/src/ast/types/AtomType.java
@@ -2,9 +2,10 @@ package ast.types;
/**
* An tom type.
- * TODO: do I need to use this one?
*/
public class AtomType extends Type {
+
+ @Override
public String toPrint(String prefix) {
return prefix + "Atom\n";
}
diff --git a/src/ast/types/BoolType.java b/src/ast/types/BoolType.java
index 20c2750..01e2cd5 100644
--- a/src/ast/types/BoolType.java
+++ b/src/ast/types/BoolType.java
@@ -4,6 +4,8 @@ package ast.types;
* A boolean type. A bool is True or False.
*/
public class BoolType extends Type {
+
+ @Override
public String toPrint(String prefix) {
return prefix + "Bool\n";
}
diff --git a/src/ast/types/ErrorType.java b/src/ast/types/ErrorType.java
index 4a7a0cf..71176d1 100644
--- a/src/ast/types/ErrorType.java
+++ b/src/ast/types/ErrorType.java
@@ -4,6 +4,8 @@ package ast.types;
* Error type.
*/
public class ErrorType extends Type {
+
+ @Override
public String toPrint(String prefix) {
return prefix + "Error\n";
}
diff --git a/src/ast/types/FunctionType.java b/src/ast/types/FunctionType.java
new file mode 100644
index 0000000..5e6adaa
--- /dev/null
+++ b/src/ast/types/FunctionType.java
@@ -0,0 +1,29 @@
+package ast.types;
+
+/**
+ * A Function type.
+ */
+public class FunctionType extends Type {
+
+ private final int paramNumber;
+ private final Type returnType;
+
+ public FunctionType(int paramNumber, Type returnType) {
+ this.paramNumber = paramNumber;
+ this.returnType = returnType;
+ }
+
+ // Return the length of the parameters
+ public int getParamNumber() {
+ return paramNumber;
+ }
+
+ public Type getReturnType() {
+ return returnType;
+ }
+
+ @Override
+ public String toPrint(String prefix) {
+ return prefix + "Function\n";
+ }
+}
diff --git a/src/ast/types/ImportType.java b/src/ast/types/ImportType.java
new file mode 100644
index 0000000..892de10
--- /dev/null
+++ b/src/ast/types/ImportType.java
@@ -0,0 +1,12 @@
+package ast.types;
+
+/**
+ * A type for the imported names.
+ */
+public class ImportType extends Type {
+
+ @Override
+ public String toPrint(String prefix) {
+ return prefix + "Import\n";
+ }
+}
diff --git a/src/ast/types/IntType.java b/src/ast/types/IntType.java
index a29518b..6483d93 100644
--- a/src/ast/types/IntType.java
+++ b/src/ast/types/IntType.java
@@ -4,6 +4,8 @@ package ast.types;
* An integer type.
*/
public class IntType extends Type {
+
+ @Override
public String toPrint(String prefix) {
return prefix + "Int\n";
}
diff --git a/src/ast/types/NoneType.java b/src/ast/types/NoneType.java
new file mode 100644
index 0000000..730add9
--- /dev/null
+++ b/src/ast/types/NoneType.java
@@ -0,0 +1,17 @@
+package ast.types;
+
+/**
+ * A none type. None return unit.
+ */
+public class NoneType extends Type {
+
+ @Override
+ public String toPrint(String prefix) {
+ return prefix + "None\n";
+ }
+
+ @Override
+ public String toString() {
+ return "None";
+ }
+}
diff --git a/src/ast/types/ReservedWordsType.java b/src/ast/types/ReservedWordsType.java
new file mode 100644
index 0000000..da72890
--- /dev/null
+++ b/src/ast/types/ReservedWordsType.java
@@ -0,0 +1,12 @@
+package ast.types;
+
+/**
+ * A type for the continue and break statements.
+ */
+public class ReservedWordsType extends Type {
+
+ @Override
+ public String toPrint(String prefix) {
+ return prefix + "ReservedWords\n";
+ }
+}
diff --git a/src/ast/types/Type.java b/src/ast/types/Type.java
index 6bff8b9..6190106 100644
--- a/src/ast/types/Type.java
+++ b/src/ast/types/Type.java
@@ -1,26 +1,25 @@
package ast.types;
+import ast.nodes.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.nodes.*;
/**
* A node which represents a type class.
*/
public class Type implements Node {
+
public boolean isEqual(Type A, Type B) {
- if (A.getClass().equals(B.getClass()))
- return true;
- else
- return false;
+ return A.getClass().equals(B.getClass());
}
+ @Override
public String toPrint(String s) {
return s;
}
+ @Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
// It is never invoked
return null;
diff --git a/src/ast/types/VoidType.java b/src/ast/types/VoidType.java
index d15933f..2d21da6 100644
--- a/src/ast/types/VoidType.java
+++ b/src/ast/types/VoidType.java
@@ -4,7 +4,14 @@ package ast.types;
* A void type. Voids return nothing.
*/
public class VoidType extends Type {
+
+ @Override
public String toPrint(String prefix) {
return prefix + "Void\n";
}
+
+ @Override
+ public String toString() {
+ return "Void";
+ }
}
diff --git a/src/parser/.antlr/Python3Lexer.interp b/src/parser/.antlr/Python3Lexer.interp
deleted file mode 100644
index 1f4208b..0000000
--- a/src/parser/.antlr/Python3Lexer.interp
+++ /dev/null
@@ -1,253 +0,0 @@
-token literal names:
-null
-null
-null
-null
-null
-'and'
-'as'
-'def'
-'elif'
-'else'
-'False'
-'for'
-'from'
-'if'
-'import'
-'in'
-'is'
-'None'
-'not'
-'or'
-'return'
-'True'
-'_'
-'while'
-null
-null
-null
-null
-'.'
-'...'
-'*'
-'('
-')'
-','
-':'
-';'
-'**'
-'='
-'['
-']'
-'|'
-'^'
-'&'
-'<<'
-'>>'
-'+'
-'-'
-'/'
-'%'
-'//'
-'~'
-'{'
-'}'
-'<'
-'>'
-'=='
-'>='
-'<='
-'<>'
-'!='
-'@'
-'->'
-'+='
-'-='
-'*='
-'@='
-'/='
-'%='
-'&='
-'|='
-'^='
-'<<='
-'>>='
-'**='
-'//='
-null
-null
-
-token symbolic names:
-null
-INDENT
-DEDENT
-STRING
-NUMBER
-AND
-AS
-DEF
-ELIF
-ELSE
-FALSE
-FOR
-FROM
-IF
-IMPORT
-IN
-IS
-NONE
-NOT
-OR
-RETURN
-TRUE
-UNDERSCORE
-WHILE
-NEWLINE
-NAME
-DECIMAL_INTEGER
-FLOAT_NUMBER
-DOT
-ELLIPSIS
-STAR
-OPEN_PAREN
-CLOSE_PAREN
-COMMA
-COLON
-SEMI_COLON
-POWER
-ASSIGN
-OPEN_BRACK
-CLOSE_BRACK
-OR_OP
-XOR
-AND_OP
-LEFT_SHIFT
-RIGHT_SHIFT
-ADD
-MINUS
-DIV
-MOD
-IDIV
-NOT_OP
-OPEN_BRACE
-CLOSE_BRACE
-LESS_THAN
-GREATER_THAN
-EQUALS
-GT_EQ
-LT_EQ
-NOT_EQ_1
-NOT_EQ_2
-AT
-ARROW
-ADD_ASSIGN
-SUB_ASSIGN
-MULT_ASSIGN
-AT_ASSIGN
-DIV_ASSIGN
-MOD_ASSIGN
-AND_ASSIGN
-OR_ASSIGN
-XOR_ASSIGN
-LEFT_SHIFT_ASSIGN
-RIGHT_SHIFT_ASSIGN
-POWER_ASSIGN
-IDIV_ASSIGN
-SKIP_
-UNKNOWN_CHAR
-
-rule names:
-STRING
-NUMBER
-AND
-AS
-DEF
-ELIF
-ELSE
-FALSE
-FOR
-FROM
-IF
-IMPORT
-IN
-IS
-NONE
-NOT
-OR
-RETURN
-TRUE
-UNDERSCORE
-WHILE
-NEWLINE
-NAME
-DECIMAL_INTEGER
-FLOAT_NUMBER
-DOT
-ELLIPSIS
-STAR
-OPEN_PAREN
-CLOSE_PAREN
-COMMA
-COLON
-SEMI_COLON
-POWER
-ASSIGN
-OPEN_BRACK
-CLOSE_BRACK
-OR_OP
-XOR
-AND_OP
-LEFT_SHIFT
-RIGHT_SHIFT
-ADD
-MINUS
-DIV
-MOD
-IDIV
-NOT_OP
-OPEN_BRACE
-CLOSE_BRACE
-LESS_THAN
-GREATER_THAN
-EQUALS
-GT_EQ
-LT_EQ
-NOT_EQ_1
-NOT_EQ_2
-AT
-ARROW
-ADD_ASSIGN
-SUB_ASSIGN
-MULT_ASSIGN
-AT_ASSIGN
-DIV_ASSIGN
-MOD_ASSIGN
-AND_ASSIGN
-OR_ASSIGN
-XOR_ASSIGN
-LEFT_SHIFT_ASSIGN
-RIGHT_SHIFT_ASSIGN
-POWER_ASSIGN
-IDIV_ASSIGN
-SKIP_
-UNKNOWN_CHAR
-STRING_ESCAPE_SEQ
-NON_ZERO_DIGIT
-DIGIT
-POINT_FLOAT
-EXPONENT_FLOAT
-INT_PART
-EXPONENT
-SPACES
-COMMENT
-LINE_JOINING
-
-channel names:
-DEFAULT_TOKEN_CHANNEL
-HIDDEN
-
-mode names:
-DEFAULT_MODE
-
-atn:
-[4, 0, 76, 523, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 2, 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, 2, 47, 7, 47, 2, 48, 7, 48, 2, 49, 7, 49, 2, 50, 7, 50, 2, 51, 7, 51, 2, 52, 7, 52, 2, 53, 7, 53, 2, 54, 7, 54, 2, 55, 7, 55, 2, 56, 7, 56, 2, 57, 7, 57, 2, 58, 7, 58, 2, 59, 7, 59, 2, 60, 7, 60, 2, 61, 7, 61, 2, 62, 7, 62, 2, 63, 7, 63, 2, 64, 7, 64, 2, 65, 7, 65, 2, 66, 7, 66, 2, 67, 7, 67, 2, 68, 7, 68, 2, 69, 7, 69, 2, 70, 7, 70, 2, 71, 7, 71, 2, 72, 7, 72, 2, 73, 7, 73, 2, 74, 7, 74, 2, 75, 7, 75, 2, 76, 7, 76, 2, 77, 7, 77, 2, 78, 7, 78, 2, 79, 7, 79, 2, 80, 7, 80, 2, 81, 7, 81, 2, 82, 7, 82, 2, 83, 7, 83, 1, 0, 1, 0, 1, 0, 5, 0, 173, 8, 0, 10, 0, 12, 0, 176, 9, 0, 1, 0, 1, 0, 1, 0, 1, 0, 5, 0, 182, 8, 0, 10, 0, 12, 0, 185, 9, 0, 1, 0, 3, 0, 188, 8, 0, 1, 1, 1, 1, 3, 1, 192, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 3, 21, 281, 8, 21, 1, 21, 1, 21, 3, 21, 285, 8, 21, 1, 21, 3, 21, 288, 8, 21, 3, 21, 290, 8, 21, 1, 21, 1, 21, 1, 22, 1, 22, 5, 22, 296, 8, 22, 10, 22, 12, 22, 299, 9, 22, 1, 23, 1, 23, 5, 23, 303, 8, 23, 10, 23, 12, 23, 306, 9, 23, 1, 23, 4, 23, 309, 8, 23, 11, 23, 12, 23, 310, 3, 23, 313, 8, 23, 1, 24, 1, 24, 3, 24, 317, 8, 24, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, 1, 26, 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 29, 1, 29, 1, 29, 1, 30, 1, 30, 1, 31, 1, 31, 1, 32, 1, 32, 1, 33, 1, 33, 1, 33, 1, 34, 1, 34, 1, 35, 1, 35, 1, 35, 1, 36, 1, 36, 1, 36, 1, 37, 1, 37, 1, 38, 1, 38, 1, 39, 1, 39, 1, 40, 1, 40, 1, 40, 1, 41, 1, 41, 1, 41, 1, 42, 1, 42, 1, 43, 1, 43, 1, 44, 1, 44, 1, 45, 1, 45, 1, 46, 1, 46, 1, 46, 1, 47, 1, 47, 1, 48, 1, 48, 1, 48, 1, 49, 1, 49, 1, 49, 1, 50, 1, 50, 1, 51, 1, 51, 1, 52, 1, 52, 1, 52, 1, 53, 1, 53, 1, 53, 1, 54, 1, 54, 1, 54, 1, 55, 1, 55, 1, 55, 1, 56, 1, 56, 1, 56, 1, 57, 1, 57, 1, 58, 1, 58, 1, 58, 1, 59, 1, 59, 1, 59, 1, 60, 1, 60, 1, 60, 1, 61, 1, 61, 1, 61, 1, 62, 1, 62, 1, 62, 1, 63, 1, 63, 1, 63, 1, 64, 1, 64, 1, 64, 1, 65, 1, 65, 1, 65, 1, 66, 1, 66, 1, 66, 1, 67, 1, 67, 1, 67, 1, 68, 1, 68, 1, 68, 1, 68, 1, 69, 1, 69, 1, 69, 1, 69, 1, 70, 1, 70, 1, 70, 1, 70, 1, 71, 1, 71, 1, 71, 1, 71, 1, 72, 1, 72, 1, 72, 3, 72, 451, 8, 72, 1, 72, 1, 72, 1, 73, 1, 73, 1, 74, 1, 74, 1, 74, 1, 74, 3, 74, 461, 8, 74, 1, 75, 1, 75, 1, 76, 1, 76, 1, 77, 3, 77, 468, 8, 77, 1, 77, 1, 77, 4, 77, 472, 8, 77, 11, 77, 12, 77, 473, 1, 77, 1, 77, 1, 77, 3, 77, 479, 8, 77, 1, 78, 1, 78, 3, 78, 483, 8, 78, 1, 78, 1, 78, 1, 79, 4, 79, 488, 8, 79, 11, 79, 12, 79, 489, 1, 80, 1, 80, 3, 80, 494, 8, 80, 1, 80, 4, 80, 497, 8, 80, 11, 80, 12, 80, 498, 1, 81, 4, 81, 502, 8, 81, 11, 81, 12, 81, 503, 1, 82, 1, 82, 5, 82, 508, 8, 82, 10, 82, 12, 82, 511, 9, 82, 1, 83, 1, 83, 3, 83, 515, 8, 83, 1, 83, 3, 83, 518, 8, 83, 1, 83, 1, 83, 3, 83, 522, 8, 83, 0, 0, 84, 1, 3, 3, 4, 5, 5, 7, 6, 9, 7, 11, 8, 13, 9, 15, 10, 17, 11, 19, 12, 21, 13, 23, 14, 25, 15, 27, 16, 29, 17, 31, 18, 33, 19, 35, 20, 37, 21, 39, 22, 41, 23, 43, 24, 45, 25, 47, 26, 49, 27, 51, 28, 53, 29, 55, 30, 57, 31, 59, 32, 61, 33, 63, 34, 65, 35, 67, 36, 69, 37, 71, 38, 73, 39, 75, 40, 77, 41, 79, 42, 81, 43, 83, 44, 85, 45, 87, 46, 89, 47, 91, 48, 93, 49, 95, 50, 97, 51, 99, 52, 101, 53, 103, 54, 105, 55, 107, 56, 109, 57, 111, 58, 113, 59, 115, 60, 117, 61, 119, 62, 121, 63, 123, 64, 125, 65, 127, 66, 129, 67, 131, 68, 133, 69, 135, 70, 137, 71, 139, 72, 141, 73, 143, 74, 145, 75, 147, 76, 149, 0, 151, 0, 153, 0, 155, 0, 157, 0, 159, 0, 161, 0, 163, 0, 165, 0, 167, 0, 1, 0, 10, 4, 0, 10, 10, 12, 13, 39, 39, 92, 92, 4, 0, 10, 10, 12, 13, 34, 34, 92, 92, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 1, 0, 49, 57, 1, 0, 48, 57, 2, 0, 69, 69, 101, 101, 2, 0, 43, 43, 45, 45, 2, 0, 9, 9, 32, 32, 2, 0, 10, 10, 12, 13, 542, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 69, 1, 0, 0, 0, 0, 71, 1, 0, 0, 0, 0, 73, 1, 0, 0, 0, 0, 75, 1, 0, 0, 0, 0, 77, 1, 0, 0, 0, 0, 79, 1, 0, 0, 0, 0, 81, 1, 0, 0, 0, 0, 83, 1, 0, 0, 0, 0, 85, 1, 0, 0, 0, 0, 87, 1, 0, 0, 0, 0, 89, 1, 0, 0, 0, 0, 91, 1, 0, 0, 0, 0, 93, 1, 0, 0, 0, 0, 95, 1, 0, 0, 0, 0, 97, 1, 0, 0, 0, 0, 99, 1, 0, 0, 0, 0, 101, 1, 0, 0, 0, 0, 103, 1, 0, 0, 0, 0, 105, 1, 0, 0, 0, 0, 107, 1, 0, 0, 0, 0, 109, 1, 0, 0, 0, 0, 111, 1, 0, 0, 0, 0, 113, 1, 0, 0, 0, 0, 115, 1, 0, 0, 0, 0, 117, 1, 0, 0, 0, 0, 119, 1, 0, 0, 0, 0, 121, 1, 0, 0, 0, 0, 123, 1, 0, 0, 0, 0, 125, 1, 0, 0, 0, 0, 127, 1, 0, 0, 0, 0, 129, 1, 0, 0, 0, 0, 131, 1, 0, 0, 0, 0, 133, 1, 0, 0, 0, 0, 135, 1, 0, 0, 0, 0, 137, 1, 0, 0, 0, 0, 139, 1, 0, 0, 0, 0, 141, 1, 0, 0, 0, 0, 143, 1, 0, 0, 0, 0, 145, 1, 0, 0, 0, 0, 147, 1, 0, 0, 0, 1, 187, 1, 0, 0, 0, 3, 191, 1, 0, 0, 0, 5, 193, 1, 0, 0, 0, 7, 197, 1, 0, 0, 0, 9, 200, 1, 0, 0, 0, 11, 204, 1, 0, 0, 0, 13, 209, 1, 0, 0, 0, 15, 214, 1, 0, 0, 0, 17, 220, 1, 0, 0, 0, 19, 224, 1, 0, 0, 0, 21, 229, 1, 0, 0, 0, 23, 232, 1, 0, 0, 0, 25, 239, 1, 0, 0, 0, 27, 242, 1, 0, 0, 0, 29, 245, 1, 0, 0, 0, 31, 250, 1, 0, 0, 0, 33, 254, 1, 0, 0, 0, 35, 257, 1, 0, 0, 0, 37, 264, 1, 0, 0, 0, 39, 269, 1, 0, 0, 0, 41, 271, 1, 0, 0, 0, 43, 289, 1, 0, 0, 0, 45, 293, 1, 0, 0, 0, 47, 312, 1, 0, 0, 0, 49, 316, 1, 0, 0, 0, 51, 318, 1, 0, 0, 0, 53, 320, 1, 0, 0, 0, 55, 324, 1, 0, 0, 0, 57, 326, 1, 0, 0, 0, 59, 329, 1, 0, 0, 0, 61, 332, 1, 0, 0, 0, 63, 334, 1, 0, 0, 0, 65, 336, 1, 0, 0, 0, 67, 338, 1, 0, 0, 0, 69, 341, 1, 0, 0, 0, 71, 343, 1, 0, 0, 0, 73, 346, 1, 0, 0, 0, 75, 349, 1, 0, 0, 0, 77, 351, 1, 0, 0, 0, 79, 353, 1, 0, 0, 0, 81, 355, 1, 0, 0, 0, 83, 358, 1, 0, 0, 0, 85, 361, 1, 0, 0, 0, 87, 363, 1, 0, 0, 0, 89, 365, 1, 0, 0, 0, 91, 367, 1, 0, 0, 0, 93, 369, 1, 0, 0, 0, 95, 372, 1, 0, 0, 0, 97, 374, 1, 0, 0, 0, 99, 377, 1, 0, 0, 0, 101, 380, 1, 0, 0, 0, 103, 382, 1, 0, 0, 0, 105, 384, 1, 0, 0, 0, 107, 387, 1, 0, 0, 0, 109, 390, 1, 0, 0, 0, 111, 393, 1, 0, 0, 0, 113, 396, 1, 0, 0, 0, 115, 399, 1, 0, 0, 0, 117, 401, 1, 0, 0, 0, 119, 404, 1, 0, 0, 0, 121, 407, 1, 0, 0, 0, 123, 410, 1, 0, 0, 0, 125, 413, 1, 0, 0, 0, 127, 416, 1, 0, 0, 0, 129, 419, 1, 0, 0, 0, 131, 422, 1, 0, 0, 0, 133, 425, 1, 0, 0, 0, 135, 428, 1, 0, 0, 0, 137, 431, 1, 0, 0, 0, 139, 435, 1, 0, 0, 0, 141, 439, 1, 0, 0, 0, 143, 443, 1, 0, 0, 0, 145, 450, 1, 0, 0, 0, 147, 454, 1, 0, 0, 0, 149, 460, 1, 0, 0, 0, 151, 462, 1, 0, 0, 0, 153, 464, 1, 0, 0, 0, 155, 478, 1, 0, 0, 0, 157, 482, 1, 0, 0, 0, 159, 487, 1, 0, 0, 0, 161, 491, 1, 0, 0, 0, 163, 501, 1, 0, 0, 0, 165, 505, 1, 0, 0, 0, 167, 512, 1, 0, 0, 0, 169, 174, 5, 39, 0, 0, 170, 173, 3, 149, 74, 0, 171, 173, 8, 0, 0, 0, 172, 170, 1, 0, 0, 0, 172, 171, 1, 0, 0, 0, 173, 176, 1, 0, 0, 0, 174, 172, 1, 0, 0, 0, 174, 175, 1, 0, 0, 0, 175, 177, 1, 0, 0, 0, 176, 174, 1, 0, 0, 0, 177, 188, 5, 39, 0, 0, 178, 183, 5, 34, 0, 0, 179, 182, 3, 149, 74, 0, 180, 182, 8, 1, 0, 0, 181, 179, 1, 0, 0, 0, 181, 180, 1, 0, 0, 0, 182, 185, 1, 0, 0, 0, 183, 181, 1, 0, 0, 0, 183, 184, 1, 0, 0, 0, 184, 186, 1, 0, 0, 0, 185, 183, 1, 0, 0, 0, 186, 188, 5, 34, 0, 0, 187, 169, 1, 0, 0, 0, 187, 178, 1, 0, 0, 0, 188, 2, 1, 0, 0, 0, 189, 192, 3, 47, 23, 0, 190, 192, 3, 49, 24, 0, 191, 189, 1, 0, 0, 0, 191, 190, 1, 0, 0, 0, 192, 4, 1, 0, 0, 0, 193, 194, 5, 97, 0, 0, 194, 195, 5, 110, 0, 0, 195, 196, 5, 100, 0, 0, 196, 6, 1, 0, 0, 0, 197, 198, 5, 97, 0, 0, 198, 199, 5, 115, 0, 0, 199, 8, 1, 0, 0, 0, 200, 201, 5, 100, 0, 0, 201, 202, 5, 101, 0, 0, 202, 203, 5, 102, 0, 0, 203, 10, 1, 0, 0, 0, 204, 205, 5, 101, 0, 0, 205, 206, 5, 108, 0, 0, 206, 207, 5, 105, 0, 0, 207, 208, 5, 102, 0, 0, 208, 12, 1, 0, 0, 0, 209, 210, 5, 101, 0, 0, 210, 211, 5, 108, 0, 0, 211, 212, 5, 115, 0, 0, 212, 213, 5, 101, 0, 0, 213, 14, 1, 0, 0, 0, 214, 215, 5, 70, 0, 0, 215, 216, 5, 97, 0, 0, 216, 217, 5, 108, 0, 0, 217, 218, 5, 115, 0, 0, 218, 219, 5, 101, 0, 0, 219, 16, 1, 0, 0, 0, 220, 221, 5, 102, 0, 0, 221, 222, 5, 111, 0, 0, 222, 223, 5, 114, 0, 0, 223, 18, 1, 0, 0, 0, 224, 225, 5, 102, 0, 0, 225, 226, 5, 114, 0, 0, 226, 227, 5, 111, 0, 0, 227, 228, 5, 109, 0, 0, 228, 20, 1, 0, 0, 0, 229, 230, 5, 105, 0, 0, 230, 231, 5, 102, 0, 0, 231, 22, 1, 0, 0, 0, 232, 233, 5, 105, 0, 0, 233, 234, 5, 109, 0, 0, 234, 235, 5, 112, 0, 0, 235, 236, 5, 111, 0, 0, 236, 237, 5, 114, 0, 0, 237, 238, 5, 116, 0, 0, 238, 24, 1, 0, 0, 0, 239, 240, 5, 105, 0, 0, 240, 241, 5, 110, 0, 0, 241, 26, 1, 0, 0, 0, 242, 243, 5, 105, 0, 0, 243, 244, 5, 115, 0, 0, 244, 28, 1, 0, 0, 0, 245, 246, 5, 78, 0, 0, 246, 247, 5, 111, 0, 0, 247, 248, 5, 110, 0, 0, 248, 249, 5, 101, 0, 0, 249, 30, 1, 0, 0, 0, 250, 251, 5, 110, 0, 0, 251, 252, 5, 111, 0, 0, 252, 253, 5, 116, 0, 0, 253, 32, 1, 0, 0, 0, 254, 255, 5, 111, 0, 0, 255, 256, 5, 114, 0, 0, 256, 34, 1, 0, 0, 0, 257, 258, 5, 114, 0, 0, 258, 259, 5, 101, 0, 0, 259, 260, 5, 116, 0, 0, 260, 261, 5, 117, 0, 0, 261, 262, 5, 114, 0, 0, 262, 263, 5, 110, 0, 0, 263, 36, 1, 0, 0, 0, 264, 265, 5, 84, 0, 0, 265, 266, 5, 114, 0, 0, 266, 267, 5, 117, 0, 0, 267, 268, 5, 101, 0, 0, 268, 38, 1, 0, 0, 0, 269, 270, 5, 95, 0, 0, 270, 40, 1, 0, 0, 0, 271, 272, 5, 119, 0, 0, 272, 273, 5, 104, 0, 0, 273, 274, 5, 105, 0, 0, 274, 275, 5, 108, 0, 0, 275, 276, 5, 101, 0, 0, 276, 42, 1, 0, 0, 0, 277, 278, 4, 21, 0, 0, 278, 290, 3, 163, 81, 0, 279, 281, 5, 13, 0, 0, 280, 279, 1, 0, 0, 0, 280, 281, 1, 0, 0, 0, 281, 282, 1, 0, 0, 0, 282, 285, 5, 10, 0, 0, 283, 285, 2, 12, 13, 0, 284, 280, 1, 0, 0, 0, 284, 283, 1, 0, 0, 0, 285, 287, 1, 0, 0, 0, 286, 288, 3, 163, 81, 0, 287, 286, 1, 0, 0, 0, 287, 288, 1, 0, 0, 0, 288, 290, 1, 0, 0, 0, 289, 277, 1, 0, 0, 0, 289, 284, 1, 0, 0, 0, 290, 291, 1, 0, 0, 0, 291, 292, 6, 21, 0, 0, 292, 44, 1, 0, 0, 0, 293, 297, 7, 2, 0, 0, 294, 296, 7, 3, 0, 0, 295, 294, 1, 0, 0, 0, 296, 299, 1, 0, 0, 0, 297, 295, 1, 0, 0, 0, 297, 298, 1, 0, 0, 0, 298, 46, 1, 0, 0, 0, 299, 297, 1, 0, 0, 0, 300, 304, 3, 151, 75, 0, 301, 303, 3, 153, 76, 0, 302, 301, 1, 0, 0, 0, 303, 306, 1, 0, 0, 0, 304, 302, 1, 0, 0, 0, 304, 305, 1, 0, 0, 0, 305, 313, 1, 0, 0, 0, 306, 304, 1, 0, 0, 0, 307, 309, 5, 48, 0, 0, 308, 307, 1, 0, 0, 0, 309, 310, 1, 0, 0, 0, 310, 308, 1, 0, 0, 0, 310, 311, 1, 0, 0, 0, 311, 313, 1, 0, 0, 0, 312, 300, 1, 0, 0, 0, 312, 308, 1, 0, 0, 0, 313, 48, 1, 0, 0, 0, 314, 317, 3, 155, 77, 0, 315, 317, 3, 157, 78, 0, 316, 314, 1, 0, 0, 0, 316, 315, 1, 0, 0, 0, 317, 50, 1, 0, 0, 0, 318, 319, 5, 46, 0, 0, 319, 52, 1, 0, 0, 0, 320, 321, 5, 46, 0, 0, 321, 322, 5, 46, 0, 0, 322, 323, 5, 46, 0, 0, 323, 54, 1, 0, 0, 0, 324, 325, 5, 42, 0, 0, 325, 56, 1, 0, 0, 0, 326, 327, 5, 40, 0, 0, 327, 328, 6, 28, 1, 0, 328, 58, 1, 0, 0, 0, 329, 330, 5, 41, 0, 0, 330, 331, 6, 29, 2, 0, 331, 60, 1, 0, 0, 0, 332, 333, 5, 44, 0, 0, 333, 62, 1, 0, 0, 0, 334, 335, 5, 58, 0, 0, 335, 64, 1, 0, 0, 0, 336, 337, 5, 59, 0, 0, 337, 66, 1, 0, 0, 0, 338, 339, 5, 42, 0, 0, 339, 340, 5, 42, 0, 0, 340, 68, 1, 0, 0, 0, 341, 342, 5, 61, 0, 0, 342, 70, 1, 0, 0, 0, 343, 344, 5, 91, 0, 0, 344, 345, 6, 35, 3, 0, 345, 72, 1, 0, 0, 0, 346, 347, 5, 93, 0, 0, 347, 348, 6, 36, 4, 0, 348, 74, 1, 0, 0, 0, 349, 350, 5, 124, 0, 0, 350, 76, 1, 0, 0, 0, 351, 352, 5, 94, 0, 0, 352, 78, 1, 0, 0, 0, 353, 354, 5, 38, 0, 0, 354, 80, 1, 0, 0, 0, 355, 356, 5, 60, 0, 0, 356, 357, 5, 60, 0, 0, 357, 82, 1, 0, 0, 0, 358, 359, 5, 62, 0, 0, 359, 360, 5, 62, 0, 0, 360, 84, 1, 0, 0, 0, 361, 362, 5, 43, 0, 0, 362, 86, 1, 0, 0, 0, 363, 364, 5, 45, 0, 0, 364, 88, 1, 0, 0, 0, 365, 366, 5, 47, 0, 0, 366, 90, 1, 0, 0, 0, 367, 368, 5, 37, 0, 0, 368, 92, 1, 0, 0, 0, 369, 370, 5, 47, 0, 0, 370, 371, 5, 47, 0, 0, 371, 94, 1, 0, 0, 0, 372, 373, 5, 126, 0, 0, 373, 96, 1, 0, 0, 0, 374, 375, 5, 123, 0, 0, 375, 376, 6, 48, 5, 0, 376, 98, 1, 0, 0, 0, 377, 378, 5, 125, 0, 0, 378, 379, 6, 49, 6, 0, 379, 100, 1, 0, 0, 0, 380, 381, 5, 60, 0, 0, 381, 102, 1, 0, 0, 0, 382, 383, 5, 62, 0, 0, 383, 104, 1, 0, 0, 0, 384, 385, 5, 61, 0, 0, 385, 386, 5, 61, 0, 0, 386, 106, 1, 0, 0, 0, 387, 388, 5, 62, 0, 0, 388, 389, 5, 61, 0, 0, 389, 108, 1, 0, 0, 0, 390, 391, 5, 60, 0, 0, 391, 392, 5, 61, 0, 0, 392, 110, 1, 0, 0, 0, 393, 394, 5, 60, 0, 0, 394, 395, 5, 62, 0, 0, 395, 112, 1, 0, 0, 0, 396, 397, 5, 33, 0, 0, 397, 398, 5, 61, 0, 0, 398, 114, 1, 0, 0, 0, 399, 400, 5, 64, 0, 0, 400, 116, 1, 0, 0, 0, 401, 402, 5, 45, 0, 0, 402, 403, 5, 62, 0, 0, 403, 118, 1, 0, 0, 0, 404, 405, 5, 43, 0, 0, 405, 406, 5, 61, 0, 0, 406, 120, 1, 0, 0, 0, 407, 408, 5, 45, 0, 0, 408, 409, 5, 61, 0, 0, 409, 122, 1, 0, 0, 0, 410, 411, 5, 42, 0, 0, 411, 412, 5, 61, 0, 0, 412, 124, 1, 0, 0, 0, 413, 414, 5, 64, 0, 0, 414, 415, 5, 61, 0, 0, 415, 126, 1, 0, 0, 0, 416, 417, 5, 47, 0, 0, 417, 418, 5, 61, 0, 0, 418, 128, 1, 0, 0, 0, 419, 420, 5, 37, 0, 0, 420, 421, 5, 61, 0, 0, 421, 130, 1, 0, 0, 0, 422, 423, 5, 38, 0, 0, 423, 424, 5, 61, 0, 0, 424, 132, 1, 0, 0, 0, 425, 426, 5, 124, 0, 0, 426, 427, 5, 61, 0, 0, 427, 134, 1, 0, 0, 0, 428, 429, 5, 94, 0, 0, 429, 430, 5, 61, 0, 0, 430, 136, 1, 0, 0, 0, 431, 432, 5, 60, 0, 0, 432, 433, 5, 60, 0, 0, 433, 434, 5, 61, 0, 0, 434, 138, 1, 0, 0, 0, 435, 436, 5, 62, 0, 0, 436, 437, 5, 62, 0, 0, 437, 438, 5, 61, 0, 0, 438, 140, 1, 0, 0, 0, 439, 440, 5, 42, 0, 0, 440, 441, 5, 42, 0, 0, 441, 442, 5, 61, 0, 0, 442, 142, 1, 0, 0, 0, 443, 444, 5, 47, 0, 0, 444, 445, 5, 47, 0, 0, 445, 446, 5, 61, 0, 0, 446, 144, 1, 0, 0, 0, 447, 451, 3, 163, 81, 0, 448, 451, 3, 165, 82, 0, 449, 451, 3, 167, 83, 0, 450, 447, 1, 0, 0, 0, 450, 448, 1, 0, 0, 0, 450, 449, 1, 0, 0, 0, 451, 452, 1, 0, 0, 0, 452, 453, 6, 72, 7, 0, 453, 146, 1, 0, 0, 0, 454, 455, 9, 0, 0, 0, 455, 148, 1, 0, 0, 0, 456, 457, 5, 92, 0, 0, 457, 461, 9, 0, 0, 0, 458, 459, 5, 92, 0, 0, 459, 461, 3, 43, 21, 0, 460, 456, 1, 0, 0, 0, 460, 458, 1, 0, 0, 0, 461, 150, 1, 0, 0, 0, 462, 463, 7, 4, 0, 0, 463, 152, 1, 0, 0, 0, 464, 465, 7, 5, 0, 0, 465, 154, 1, 0, 0, 0, 466, 468, 3, 159, 79, 0, 467, 466, 1, 0, 0, 0, 467, 468, 1, 0, 0, 0, 468, 469, 1, 0, 0, 0, 469, 471, 5, 46, 0, 0, 470, 472, 3, 153, 76, 0, 471, 470, 1, 0, 0, 0, 472, 473, 1, 0, 0, 0, 473, 471, 1, 0, 0, 0, 473, 474, 1, 0, 0, 0, 474, 479, 1, 0, 0, 0, 475, 476, 3, 159, 79, 0, 476, 477, 5, 46, 0, 0, 477, 479, 1, 0, 0, 0, 478, 467, 1, 0, 0, 0, 478, 475, 1, 0, 0, 0, 479, 156, 1, 0, 0, 0, 480, 483, 3, 159, 79, 0, 481, 483, 3, 155, 77, 0, 482, 480, 1, 0, 0, 0, 482, 481, 1, 0, 0, 0, 483, 484, 1, 0, 0, 0, 484, 485, 3, 161, 80, 0, 485, 158, 1, 0, 0, 0, 486, 488, 3, 153, 76, 0, 487, 486, 1, 0, 0, 0, 488, 489, 1, 0, 0, 0, 489, 487, 1, 0, 0, 0, 489, 490, 1, 0, 0, 0, 490, 160, 1, 0, 0, 0, 491, 493, 7, 6, 0, 0, 492, 494, 7, 7, 0, 0, 493, 492, 1, 0, 0, 0, 493, 494, 1, 0, 0, 0, 494, 496, 1, 0, 0, 0, 495, 497, 3, 153, 76, 0, 496, 495, 1, 0, 0, 0, 497, 498, 1, 0, 0, 0, 498, 496, 1, 0, 0, 0, 498, 499, 1, 0, 0, 0, 499, 162, 1, 0, 0, 0, 500, 502, 7, 8, 0, 0, 501, 500, 1, 0, 0, 0, 502, 503, 1, 0, 0, 0, 503, 501, 1, 0, 0, 0, 503, 504, 1, 0, 0, 0, 504, 164, 1, 0, 0, 0, 505, 509, 5, 35, 0, 0, 506, 508, 8, 9, 0, 0, 507, 506, 1, 0, 0, 0, 508, 511, 1, 0, 0, 0, 509, 507, 1, 0, 0, 0, 509, 510, 1, 0, 0, 0, 510, 166, 1, 0, 0, 0, 511, 509, 1, 0, 0, 0, 512, 514, 5, 92, 0, 0, 513, 515, 3, 163, 81, 0, 514, 513, 1, 0, 0, 0, 514, 515, 1, 0, 0, 0, 515, 521, 1, 0, 0, 0, 516, 518, 5, 13, 0, 0, 517, 516, 1, 0, 0, 0, 517, 518, 1, 0, 0, 0, 518, 519, 1, 0, 0, 0, 519, 522, 5, 10, 0, 0, 520, 522, 2, 12, 13, 0, 521, 517, 1, 0, 0, 0, 521, 520, 1, 0, 0, 0, 522, 168, 1, 0, 0, 0, 30, 0, 172, 174, 181, 183, 187, 191, 280, 284, 287, 289, 297, 304, 310, 312, 316, 450, 460, 467, 473, 478, 482, 489, 493, 498, 503, 509, 514, 517, 521, 8, 1, 21, 0, 1, 28, 1, 1, 29, 2, 1, 35, 3, 1, 36, 4, 1, 48, 5, 1, 49, 6, 6, 0, 0] \ No newline at end of file
diff --git a/src/parser/.antlr/Python3Lexer.java b/src/parser/.antlr/Python3Lexer.java
deleted file mode 100644
index 5a11975..0000000
--- a/src/parser/.antlr/Python3Lexer.java
+++ /dev/null
@@ -1,574 +0,0 @@
-// Generated from /home/geno/Desktop/uni/clp/clp_project/src/parser/Python3Lexer.g4 by ANTLR 4.13.1
-import org.antlr.v4.runtime.Lexer;
-import org.antlr.v4.runtime.CharStream;
-import org.antlr.v4.runtime.Token;
-import org.antlr.v4.runtime.TokenStream;
-import org.antlr.v4.runtime.*;
-import org.antlr.v4.runtime.atn.*;
-import org.antlr.v4.runtime.dfa.DFA;
-import org.antlr.v4.runtime.misc.*;
-
-@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "this-escape"})
-public class Python3Lexer extends Python3LexerBase {
- static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); }
-
- protected static final DFA[] _decisionToDFA;
- protected static final PredictionContextCache _sharedContextCache =
- new PredictionContextCache();
- public static final int
- INDENT=1, DEDENT=2, STRING=3, NUMBER=4, AND=5, AS=6, DEF=7, ELIF=8, ELSE=9,
- FALSE=10, FOR=11, FROM=12, IF=13, IMPORT=14, IN=15, IS=16, NONE=17, NOT=18,
- OR=19, RETURN=20, TRUE=21, UNDERSCORE=22, WHILE=23, NEWLINE=24, NAME=25,
- DECIMAL_INTEGER=26, FLOAT_NUMBER=27, DOT=28, ELLIPSIS=29, STAR=30, OPEN_PAREN=31,
- CLOSE_PAREN=32, COMMA=33, COLON=34, SEMI_COLON=35, POWER=36, ASSIGN=37,
- OPEN_BRACK=38, CLOSE_BRACK=39, OR_OP=40, XOR=41, AND_OP=42, LEFT_SHIFT=43,
- RIGHT_SHIFT=44, ADD=45, MINUS=46, DIV=47, MOD=48, IDIV=49, NOT_OP=50,
- OPEN_BRACE=51, CLOSE_BRACE=52, LESS_THAN=53, GREATER_THAN=54, EQUALS=55,
- GT_EQ=56, LT_EQ=57, NOT_EQ_1=58, NOT_EQ_2=59, AT=60, ARROW=61, ADD_ASSIGN=62,
- SUB_ASSIGN=63, MULT_ASSIGN=64, AT_ASSIGN=65, DIV_ASSIGN=66, MOD_ASSIGN=67,
- AND_ASSIGN=68, OR_ASSIGN=69, XOR_ASSIGN=70, LEFT_SHIFT_ASSIGN=71, RIGHT_SHIFT_ASSIGN=72,
- POWER_ASSIGN=73, IDIV_ASSIGN=74, SKIP_=75, UNKNOWN_CHAR=76;
- public static String[] channelNames = {
- "DEFAULT_TOKEN_CHANNEL", "HIDDEN"
- };
-
- public static String[] modeNames = {
- "DEFAULT_MODE"
- };
-
- private static String[] makeRuleNames() {
- return new String[] {
- "STRING", "NUMBER", "AND", "AS", "DEF", "ELIF", "ELSE", "FALSE", "FOR",
- "FROM", "IF", "IMPORT", "IN", "IS", "NONE", "NOT", "OR", "RETURN", "TRUE",
- "UNDERSCORE", "WHILE", "NEWLINE", "NAME", "DECIMAL_INTEGER", "FLOAT_NUMBER",
- "DOT", "ELLIPSIS", "STAR", "OPEN_PAREN", "CLOSE_PAREN", "COMMA", "COLON",
- "SEMI_COLON", "POWER", "ASSIGN", "OPEN_BRACK", "CLOSE_BRACK", "OR_OP",
- "XOR", "AND_OP", "LEFT_SHIFT", "RIGHT_SHIFT", "ADD", "MINUS", "DIV",
- "MOD", "IDIV", "NOT_OP", "OPEN_BRACE", "CLOSE_BRACE", "LESS_THAN", "GREATER_THAN",
- "EQUALS", "GT_EQ", "LT_EQ", "NOT_EQ_1", "NOT_EQ_2", "AT", "ARROW", "ADD_ASSIGN",
- "SUB_ASSIGN", "MULT_ASSIGN", "AT_ASSIGN", "DIV_ASSIGN", "MOD_ASSIGN",
- "AND_ASSIGN", "OR_ASSIGN", "XOR_ASSIGN", "LEFT_SHIFT_ASSIGN", "RIGHT_SHIFT_ASSIGN",
- "POWER_ASSIGN", "IDIV_ASSIGN", "SKIP_", "UNKNOWN_CHAR", "STRING_ESCAPE_SEQ",
- "NON_ZERO_DIGIT", "DIGIT", "POINT_FLOAT", "EXPONENT_FLOAT", "INT_PART",
- "EXPONENT", "SPACES", "COMMENT", "LINE_JOINING"
- };
- }
- public static final String[] ruleNames = makeRuleNames();
-
- private static String[] makeLiteralNames() {
- return new String[] {
- null, null, null, null, null, "'and'", "'as'", "'def'", "'elif'", "'else'",
- "'False'", "'for'", "'from'", "'if'", "'import'", "'in'", "'is'", "'None'",
- "'not'", "'or'", "'return'", "'True'", "'_'", "'while'", null, null,
- null, null, "'.'", "'...'", "'*'", "'('", "')'", "','", "':'", "';'",
- "'**'", "'='", "'['", "']'", "'|'", "'^'", "'&'", "'<<'", "'>>'", "'+'",
- "'-'", "'/'", "'%'", "'//'", "'~'", "'{'", "'}'", "'<'", "'>'", "'=='",
- "'>='", "'<='", "'<>'", "'!='", "'@'", "'->'", "'+='", "'-='", "'*='",
- "'@='", "'/='", "'%='", "'&='", "'|='", "'^='", "'<<='", "'>>='", "'**='",
- "'//='"
- };
- }
- private static final String[] _LITERAL_NAMES = makeLiteralNames();
- private static String[] makeSymbolicNames() {
- return new String[] {
- null, "INDENT", "DEDENT", "STRING", "NUMBER", "AND", "AS", "DEF", "ELIF",
- "ELSE", "FALSE", "FOR", "FROM", "IF", "IMPORT", "IN", "IS", "NONE", "NOT",
- "OR", "RETURN", "TRUE", "UNDERSCORE", "WHILE", "NEWLINE", "NAME", "DECIMAL_INTEGER",
- "FLOAT_NUMBER", "DOT", "ELLIPSIS", "STAR", "OPEN_PAREN", "CLOSE_PAREN",
- "COMMA", "COLON", "SEMI_COLON", "POWER", "ASSIGN", "OPEN_BRACK", "CLOSE_BRACK",
- "OR_OP", "XOR", "AND_OP", "LEFT_SHIFT", "RIGHT_SHIFT", "ADD", "MINUS",
- "DIV", "MOD", "IDIV", "NOT_OP", "OPEN_BRACE", "CLOSE_BRACE", "LESS_THAN",
- "GREATER_THAN", "EQUALS", "GT_EQ", "LT_EQ", "NOT_EQ_1", "NOT_EQ_2", "AT",
- "ARROW", "ADD_ASSIGN", "SUB_ASSIGN", "MULT_ASSIGN", "AT_ASSIGN", "DIV_ASSIGN",
- "MOD_ASSIGN", "AND_ASSIGN", "OR_ASSIGN", "XOR_ASSIGN", "LEFT_SHIFT_ASSIGN",
- "RIGHT_SHIFT_ASSIGN", "POWER_ASSIGN", "IDIV_ASSIGN", "SKIP_", "UNKNOWN_CHAR"
- };
- }
- private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
- public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
-
- /**
- * @deprecated Use {@link #VOCABULARY} instead.
- */
- @Deprecated
- public static final String[] tokenNames;
- static {
- tokenNames = new String[_SYMBOLIC_NAMES.length];
- for (int i = 0; i < tokenNames.length; i++) {
- tokenNames[i] = VOCABULARY.getLiteralName(i);
- if (tokenNames[i] == null) {
- tokenNames[i] = VOCABULARY.getSymbolicName(i);
- }
-
- if (tokenNames[i] == null) {
- tokenNames[i] = "<INVALID>";
- }
- }
- }
-
- @Override
- @Deprecated
- public String[] getTokenNames() {
- return tokenNames;
- }
-
- @Override
-
- public Vocabulary getVocabulary() {
- return VOCABULARY;
- }
-
-
- public Python3Lexer(CharStream input) {
- super(input);
- _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
- }
-
- @Override
- public String getGrammarFileName() { return "Python3Lexer.g4"; }
-
- @Override
- public String[] getRuleNames() { return ruleNames; }
-
- @Override
- public String getSerializedATN() { return _serializedATN; }
-
- @Override
- public String[] getChannelNames() { return channelNames; }
-
- @Override
- public String[] getModeNames() { return modeNames; }
-
- @Override
- public ATN getATN() { return _ATN; }
-
- @Override
- public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
- switch (ruleIndex) {
- case 21:
- NEWLINE_action((RuleContext)_localctx, actionIndex);
- break;
- case 28:
- OPEN_PAREN_action((RuleContext)_localctx, actionIndex);
- break;
- case 29:
- CLOSE_PAREN_action((RuleContext)_localctx, actionIndex);
- break;
- case 35:
- OPEN_BRACK_action((RuleContext)_localctx, actionIndex);
- break;
- case 36:
- CLOSE_BRACK_action((RuleContext)_localctx, actionIndex);
- break;
- case 48:
- OPEN_BRACE_action((RuleContext)_localctx, actionIndex);
- break;
- case 49:
- CLOSE_BRACE_action((RuleContext)_localctx, actionIndex);
- break;
- }
- }
- private void NEWLINE_action(RuleContext _localctx, int actionIndex) {
- switch (actionIndex) {
- case 0:
- this.onNewLine();
- break;
- }
- }
- private void OPEN_PAREN_action(RuleContext _localctx, int actionIndex) {
- switch (actionIndex) {
- case 1:
- this.openBrace();
- break;
- }
- }
- private void CLOSE_PAREN_action(RuleContext _localctx, int actionIndex) {
- switch (actionIndex) {
- case 2:
- this.closeBrace();
- break;
- }
- }
- private void OPEN_BRACK_action(RuleContext _localctx, int actionIndex) {
- switch (actionIndex) {
- case 3:
- this.openBrace();
- break;
- }
- }
- private void CLOSE_BRACK_action(RuleContext _localctx, int actionIndex) {
- switch (actionIndex) {
- case 4:
- this.closeBrace();
- break;
- }
- }
- private void OPEN_BRACE_action(RuleContext _localctx, int actionIndex) {
- switch (actionIndex) {
- case 5:
- this.openBrace();
- break;
- }
- }
- private void CLOSE_BRACE_action(RuleContext _localctx, int actionIndex) {
- switch (actionIndex) {
- case 6:
- this.closeBrace();
- break;
- }
- }
- @Override
- public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
- switch (ruleIndex) {
- case 21:
- return NEWLINE_sempred((RuleContext)_localctx, predIndex);
- }
- return true;
- }
- private boolean NEWLINE_sempred(RuleContext _localctx, int predIndex) {
- switch (predIndex) {
- case 0:
- return this.atStartOfInput();
- }
- return true;
- }
-
- public static final String _serializedATN =
- "\u0004\u0000L\u020b\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+
- "\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004"+
- "\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007"+
- "\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b"+
- "\u0007\u000b\u0002\f\u0007\f\u0002\r\u0007\r\u0002\u000e\u0007\u000e\u0002"+
- "\u000f\u0007\u000f\u0002\u0010\u0007\u0010\u0002\u0011\u0007\u0011\u0002"+
- "\u0012\u0007\u0012\u0002\u0013\u0007\u0013\u0002\u0014\u0007\u0014\u0002"+
- "\u0015\u0007\u0015\u0002\u0016\u0007\u0016\u0002\u0017\u0007\u0017\u0002"+
- "\u0018\u0007\u0018\u0002\u0019\u0007\u0019\u0002\u001a\u0007\u001a\u0002"+
- "\u001b\u0007\u001b\u0002\u001c\u0007\u001c\u0002\u001d\u0007\u001d\u0002"+
- "\u001e\u0007\u001e\u0002\u001f\u0007\u001f\u0002 \u0007 \u0002!\u0007"+
- "!\u0002\"\u0007\"\u0002#\u0007#\u0002$\u0007$\u0002%\u0007%\u0002&\u0007"+
- "&\u0002\'\u0007\'\u0002(\u0007(\u0002)\u0007)\u0002*\u0007*\u0002+\u0007"+
- "+\u0002,\u0007,\u0002-\u0007-\u0002.\u0007.\u0002/\u0007/\u00020\u0007"+
- "0\u00021\u00071\u00022\u00072\u00023\u00073\u00024\u00074\u00025\u0007"+
- "5\u00026\u00076\u00027\u00077\u00028\u00078\u00029\u00079\u0002:\u0007"+
- ":\u0002;\u0007;\u0002<\u0007<\u0002=\u0007=\u0002>\u0007>\u0002?\u0007"+
- "?\u0002@\u0007@\u0002A\u0007A\u0002B\u0007B\u0002C\u0007C\u0002D\u0007"+
- "D\u0002E\u0007E\u0002F\u0007F\u0002G\u0007G\u0002H\u0007H\u0002I\u0007"+
- "I\u0002J\u0007J\u0002K\u0007K\u0002L\u0007L\u0002M\u0007M\u0002N\u0007"+
- "N\u0002O\u0007O\u0002P\u0007P\u0002Q\u0007Q\u0002R\u0007R\u0002S\u0007"+
- "S\u0001\u0000\u0001\u0000\u0001\u0000\u0005\u0000\u00ad\b\u0000\n\u0000"+
- "\f\u0000\u00b0\t\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000"+
- "\u0005\u0000\u00b6\b\u0000\n\u0000\f\u0000\u00b9\t\u0000\u0001\u0000\u0003"+
- "\u0000\u00bc\b\u0000\u0001\u0001\u0001\u0001\u0003\u0001\u00c0\b\u0001"+
- "\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0003\u0001\u0003"+
- "\u0001\u0003\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0005"+
- "\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0006\u0001\u0006"+
- "\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0007\u0001\u0007\u0001\u0007"+
- "\u0001\u0007\u0001\u0007\u0001\u0007\u0001\b\u0001\b\u0001\b\u0001\b\u0001"+
- "\t\u0001\t\u0001\t\u0001\t\u0001\t\u0001\n\u0001\n\u0001\n\u0001\u000b"+
- "\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b"+
- "\u0001\f\u0001\f\u0001\f\u0001\r\u0001\r\u0001\r\u0001\u000e\u0001\u000e"+
- "\u0001\u000e\u0001\u000e\u0001\u000e\u0001\u000f\u0001\u000f\u0001\u000f"+
- "\u0001\u000f\u0001\u0010\u0001\u0010\u0001\u0010\u0001\u0011\u0001\u0011"+
- "\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0012"+
- "\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0013\u0001\u0013"+
- "\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0014"+
- "\u0001\u0015\u0001\u0015\u0001\u0015\u0003\u0015\u0119\b\u0015\u0001\u0015"+
- "\u0001\u0015\u0003\u0015\u011d\b\u0015\u0001\u0015\u0003\u0015\u0120\b"+
- "\u0015\u0003\u0015\u0122\b\u0015\u0001\u0015\u0001\u0015\u0001\u0016\u0001"+
- "\u0016\u0005\u0016\u0128\b\u0016\n\u0016\f\u0016\u012b\t\u0016\u0001\u0017"+
- "\u0001\u0017\u0005\u0017\u012f\b\u0017\n\u0017\f\u0017\u0132\t\u0017\u0001"+
- "\u0017\u0004\u0017\u0135\b\u0017\u000b\u0017\f\u0017\u0136\u0003\u0017"+
- "\u0139\b\u0017\u0001\u0018\u0001\u0018\u0003\u0018\u013d\b\u0018\u0001"+
- "\u0019\u0001\u0019\u0001\u001a\u0001\u001a\u0001\u001a\u0001\u001a\u0001"+
- "\u001b\u0001\u001b\u0001\u001c\u0001\u001c\u0001\u001c\u0001\u001d\u0001"+
- "\u001d\u0001\u001d\u0001\u001e\u0001\u001e\u0001\u001f\u0001\u001f\u0001"+
- " \u0001 \u0001!\u0001!\u0001!\u0001\"\u0001\"\u0001#\u0001#\u0001#\u0001"+
- "$\u0001$\u0001$\u0001%\u0001%\u0001&\u0001&\u0001\'\u0001\'\u0001(\u0001"+
- "(\u0001(\u0001)\u0001)\u0001)\u0001*\u0001*\u0001+\u0001+\u0001,\u0001"+
- ",\u0001-\u0001-\u0001.\u0001.\u0001.\u0001/\u0001/\u00010\u00010\u0001"+
- "0\u00011\u00011\u00011\u00012\u00012\u00013\u00013\u00014\u00014\u0001"+
- "4\u00015\u00015\u00015\u00016\u00016\u00016\u00017\u00017\u00017\u0001"+
- "8\u00018\u00018\u00019\u00019\u0001:\u0001:\u0001:\u0001;\u0001;\u0001"+
- ";\u0001<\u0001<\u0001<\u0001=\u0001=\u0001=\u0001>\u0001>\u0001>\u0001"+
- "?\u0001?\u0001?\u0001@\u0001@\u0001@\u0001A\u0001A\u0001A\u0001B\u0001"+
- "B\u0001B\u0001C\u0001C\u0001C\u0001D\u0001D\u0001D\u0001D\u0001E\u0001"+
- "E\u0001E\u0001E\u0001F\u0001F\u0001F\u0001F\u0001G\u0001G\u0001G\u0001"+
- "G\u0001H\u0001H\u0001H\u0003H\u01c3\bH\u0001H\u0001H\u0001I\u0001I\u0001"+
- "J\u0001J\u0001J\u0001J\u0003J\u01cd\bJ\u0001K\u0001K\u0001L\u0001L\u0001"+
- "M\u0003M\u01d4\bM\u0001M\u0001M\u0004M\u01d8\bM\u000bM\fM\u01d9\u0001"+
- "M\u0001M\u0001M\u0003M\u01df\bM\u0001N\u0001N\u0003N\u01e3\bN\u0001N\u0001"+
- "N\u0001O\u0004O\u01e8\bO\u000bO\fO\u01e9\u0001P\u0001P\u0003P\u01ee\b"+
- "P\u0001P\u0004P\u01f1\bP\u000bP\fP\u01f2\u0001Q\u0004Q\u01f6\bQ\u000b"+
- "Q\fQ\u01f7\u0001R\u0001R\u0005R\u01fc\bR\nR\fR\u01ff\tR\u0001S\u0001S"+
- "\u0003S\u0203\bS\u0001S\u0003S\u0206\bS\u0001S\u0001S\u0003S\u020a\bS"+
- "\u0000\u0000T\u0001\u0003\u0003\u0004\u0005\u0005\u0007\u0006\t\u0007"+
- "\u000b\b\r\t\u000f\n\u0011\u000b\u0013\f\u0015\r\u0017\u000e\u0019\u000f"+
- "\u001b\u0010\u001d\u0011\u001f\u0012!\u0013#\u0014%\u0015\'\u0016)\u0017"+
- "+\u0018-\u0019/\u001a1\u001b3\u001c5\u001d7\u001e9\u001f; =!?\"A#C$E%"+
- "G&I\'K(M)O*Q+S,U-W.Y/[0]1_2a3c4e5g6i7k8m9o:q;s<u=w>y?{@}A\u007fB\u0081"+
- "C\u0083D\u0085E\u0087F\u0089G\u008bH\u008dI\u008fJ\u0091K\u0093L\u0095"+
- "\u0000\u0097\u0000\u0099\u0000\u009b\u0000\u009d\u0000\u009f\u0000\u00a1"+
- "\u0000\u00a3\u0000\u00a5\u0000\u00a7\u0000\u0001\u0000\n\u0004\u0000\n"+
- "\n\f\r\'\'\\\\\u0004\u0000\n\n\f\r\"\"\\\\\u0003\u0000AZ__az\u0004\u0000"+
- "09AZ__az\u0001\u000019\u0001\u000009\u0002\u0000EEee\u0002\u0000++--\u0002"+
- "\u0000\t\t \u0002\u0000\n\n\f\r\u021e\u0000\u0001\u0001\u0000\u0000\u0000"+
- "\u0000\u0003\u0001\u0000\u0000\u0000\u0000\u0005\u0001\u0000\u0000\u0000"+
- "\u0000\u0007\u0001\u0000\u0000\u0000\u0000\t\u0001\u0000\u0000\u0000\u0000"+
- "\u000b\u0001\u0000\u0000\u0000\u0000\r\u0001\u0000\u0000\u0000\u0000\u000f"+
- "\u0001\u0000\u0000\u0000\u0000\u0011\u0001\u0000\u0000\u0000\u0000\u0013"+
- "\u0001\u0000\u0000\u0000\u0000\u0015\u0001\u0000\u0000\u0000\u0000\u0017"+
- "\u0001\u0000\u0000\u0000\u0000\u0019\u0001\u0000\u0000\u0000\u0000\u001b"+
- "\u0001\u0000\u0000\u0000\u0000\u001d\u0001\u0000\u0000\u0000\u0000\u001f"+
- "\u0001\u0000\u0000\u0000\u0000!\u0001\u0000\u0000\u0000\u0000#\u0001\u0000"+
- "\u0000\u0000\u0000%\u0001\u0000\u0000\u0000\u0000\'\u0001\u0000\u0000"+
- "\u0000\u0000)\u0001\u0000\u0000\u0000\u0000+\u0001\u0000\u0000\u0000\u0000"+
- "-\u0001\u0000\u0000\u0000\u0000/\u0001\u0000\u0000\u0000\u00001\u0001"+
- "\u0000\u0000\u0000\u00003\u0001\u0000\u0000\u0000\u00005\u0001\u0000\u0000"+
- "\u0000\u00007\u0001\u0000\u0000\u0000\u00009\u0001\u0000\u0000\u0000\u0000"+
- ";\u0001\u0000\u0000\u0000\u0000=\u0001\u0000\u0000\u0000\u0000?\u0001"+
- "\u0000\u0000\u0000\u0000A\u0001\u0000\u0000\u0000\u0000C\u0001\u0000\u0000"+
- "\u0000\u0000E\u0001\u0000\u0000\u0000\u0000G\u0001\u0000\u0000\u0000\u0000"+
- "I\u0001\u0000\u0000\u0000\u0000K\u0001\u0000\u0000\u0000\u0000M\u0001"+
- "\u0000\u0000\u0000\u0000O\u0001\u0000\u0000\u0000\u0000Q\u0001\u0000\u0000"+
- "\u0000\u0000S\u0001\u0000\u0000\u0000\u0000U\u0001\u0000\u0000\u0000\u0000"+
- "W\u0001\u0000\u0000\u0000\u0000Y\u0001\u0000\u0000\u0000\u0000[\u0001"+
- "\u0000\u0000\u0000\u0000]\u0001\u0000\u0000\u0000\u0000_\u0001\u0000\u0000"+
- "\u0000\u0000a\u0001\u0000\u0000\u0000\u0000c\u0001\u0000\u0000\u0000\u0000"+
- "e\u0001\u0000\u0000\u0000\u0000g\u0001\u0000\u0000\u0000\u0000i\u0001"+
- "\u0000\u0000\u0000\u0000k\u0001\u0000\u0000\u0000\u0000m\u0001\u0000\u0000"+
- "\u0000\u0000o\u0001\u0000\u0000\u0000\u0000q\u0001\u0000\u0000\u0000\u0000"+
- "s\u0001\u0000\u0000\u0000\u0000u\u0001\u0000\u0000\u0000\u0000w\u0001"+
- "\u0000\u0000\u0000\u0000y\u0001\u0000\u0000\u0000\u0000{\u0001\u0000\u0000"+
- "\u0000\u0000}\u0001\u0000\u0000\u0000\u0000\u007f\u0001\u0000\u0000\u0000"+
- "\u0000\u0081\u0001\u0000\u0000\u0000\u0000\u0083\u0001\u0000\u0000\u0000"+
- "\u0000\u0085\u0001\u0000\u0000\u0000\u0000\u0087\u0001\u0000\u0000\u0000"+
- "\u0000\u0089\u0001\u0000\u0000\u0000\u0000\u008b\u0001\u0000\u0000\u0000"+
- "\u0000\u008d\u0001\u0000\u0000\u0000\u0000\u008f\u0001\u0000\u0000\u0000"+
- "\u0000\u0091\u0001\u0000\u0000\u0000\u0000\u0093\u0001\u0000\u0000\u0000"+
- "\u0001\u00bb\u0001\u0000\u0000\u0000\u0003\u00bf\u0001\u0000\u0000\u0000"+
- "\u0005\u00c1\u0001\u0000\u0000\u0000\u0007\u00c5\u0001\u0000\u0000\u0000"+
- "\t\u00c8\u0001\u0000\u0000\u0000\u000b\u00cc\u0001\u0000\u0000\u0000\r"+
- "\u00d1\u0001\u0000\u0000\u0000\u000f\u00d6\u0001\u0000\u0000\u0000\u0011"+
- "\u00dc\u0001\u0000\u0000\u0000\u0013\u00e0\u0001\u0000\u0000\u0000\u0015"+
- "\u00e5\u0001\u0000\u0000\u0000\u0017\u00e8\u0001\u0000\u0000\u0000\u0019"+
- "\u00ef\u0001\u0000\u0000\u0000\u001b\u00f2\u0001\u0000\u0000\u0000\u001d"+
- "\u00f5\u0001\u0000\u0000\u0000\u001f\u00fa\u0001\u0000\u0000\u0000!\u00fe"+
- "\u0001\u0000\u0000\u0000#\u0101\u0001\u0000\u0000\u0000%\u0108\u0001\u0000"+
- "\u0000\u0000\'\u010d\u0001\u0000\u0000\u0000)\u010f\u0001\u0000\u0000"+
- "\u0000+\u0121\u0001\u0000\u0000\u0000-\u0125\u0001\u0000\u0000\u0000/"+
- "\u0138\u0001\u0000\u0000\u00001\u013c\u0001\u0000\u0000\u00003\u013e\u0001"+
- "\u0000\u0000\u00005\u0140\u0001\u0000\u0000\u00007\u0144\u0001\u0000\u0000"+
- "\u00009\u0146\u0001\u0000\u0000\u0000;\u0149\u0001\u0000\u0000\u0000="+
- "\u014c\u0001\u0000\u0000\u0000?\u014e\u0001\u0000\u0000\u0000A\u0150\u0001"+
- "\u0000\u0000\u0000C\u0152\u0001\u0000\u0000\u0000E\u0155\u0001\u0000\u0000"+
- "\u0000G\u0157\u0001\u0000\u0000\u0000I\u015a\u0001\u0000\u0000\u0000K"+
- "\u015d\u0001\u0000\u0000\u0000M\u015f\u0001\u0000\u0000\u0000O\u0161\u0001"+
- "\u0000\u0000\u0000Q\u0163\u0001\u0000\u0000\u0000S\u0166\u0001\u0000\u0000"+
- "\u0000U\u0169\u0001\u0000\u0000\u0000W\u016b\u0001\u0000\u0000\u0000Y"+
- "\u016d\u0001\u0000\u0000\u0000[\u016f\u0001\u0000\u0000\u0000]\u0171\u0001"+
- "\u0000\u0000\u0000_\u0174\u0001\u0000\u0000\u0000a\u0176\u0001\u0000\u0000"+
- "\u0000c\u0179\u0001\u0000\u0000\u0000e\u017c\u0001\u0000\u0000\u0000g"+
- "\u017e\u0001\u0000\u0000\u0000i\u0180\u0001\u0000\u0000\u0000k\u0183\u0001"+
- "\u0000\u0000\u0000m\u0186\u0001\u0000\u0000\u0000o\u0189\u0001\u0000\u0000"+
- "\u0000q\u018c\u0001\u0000\u0000\u0000s\u018f\u0001\u0000\u0000\u0000u"+
- "\u0191\u0001\u0000\u0000\u0000w\u0194\u0001\u0000\u0000\u0000y\u0197\u0001"+
- "\u0000\u0000\u0000{\u019a\u0001\u0000\u0000\u0000}\u019d\u0001\u0000\u0000"+
- "\u0000\u007f\u01a0\u0001\u0000\u0000\u0000\u0081\u01a3\u0001\u0000\u0000"+
- "\u0000\u0083\u01a6\u0001\u0000\u0000\u0000\u0085\u01a9\u0001\u0000\u0000"+
- "\u0000\u0087\u01ac\u0001\u0000\u0000\u0000\u0089\u01af\u0001\u0000\u0000"+
- "\u0000\u008b\u01b3\u0001\u0000\u0000\u0000\u008d\u01b7\u0001\u0000\u0000"+
- "\u0000\u008f\u01bb\u0001\u0000\u0000\u0000\u0091\u01c2\u0001\u0000\u0000"+
- "\u0000\u0093\u01c6\u0001\u0000\u0000\u0000\u0095\u01cc\u0001\u0000\u0000"+
- "\u0000\u0097\u01ce\u0001\u0000\u0000\u0000\u0099\u01d0\u0001\u0000\u0000"+
- "\u0000\u009b\u01de\u0001\u0000\u0000\u0000\u009d\u01e2\u0001\u0000\u0000"+
- "\u0000\u009f\u01e7\u0001\u0000\u0000\u0000\u00a1\u01eb\u0001\u0000\u0000"+
- "\u0000\u00a3\u01f5\u0001\u0000\u0000\u0000\u00a5\u01f9\u0001\u0000\u0000"+
- "\u0000\u00a7\u0200\u0001\u0000\u0000\u0000\u00a9\u00ae\u0005\'\u0000\u0000"+
- "\u00aa\u00ad\u0003\u0095J\u0000\u00ab\u00ad\b\u0000\u0000\u0000\u00ac"+
- "\u00aa\u0001\u0000\u0000\u0000\u00ac\u00ab\u0001\u0000\u0000\u0000\u00ad"+
- "\u00b0\u0001\u0000\u0000\u0000\u00ae\u00ac\u0001\u0000\u0000\u0000\u00ae"+
- "\u00af\u0001\u0000\u0000\u0000\u00af\u00b1\u0001\u0000\u0000\u0000\u00b0"+
- "\u00ae\u0001\u0000\u0000\u0000\u00b1\u00bc\u0005\'\u0000\u0000\u00b2\u00b7"+
- "\u0005\"\u0000\u0000\u00b3\u00b6\u0003\u0095J\u0000\u00b4\u00b6\b\u0001"+
- "\u0000\u0000\u00b5\u00b3\u0001\u0000\u0000\u0000\u00b5\u00b4\u0001\u0000"+
- "\u0000\u0000\u00b6\u00b9\u0001\u0000\u0000\u0000\u00b7\u00b5\u0001\u0000"+
- "\u0000\u0000\u00b7\u00b8\u0001\u0000\u0000\u0000\u00b8\u00ba\u0001\u0000"+
- "\u0000\u0000\u00b9\u00b7\u0001\u0000\u0000\u0000\u00ba\u00bc\u0005\"\u0000"+
- "\u0000\u00bb\u00a9\u0001\u0000\u0000\u0000\u00bb\u00b2\u0001\u0000\u0000"+
- "\u0000\u00bc\u0002\u0001\u0000\u0000\u0000\u00bd\u00c0\u0003/\u0017\u0000"+
- "\u00be\u00c0\u00031\u0018\u0000\u00bf\u00bd\u0001\u0000\u0000\u0000\u00bf"+
- "\u00be\u0001\u0000\u0000\u0000\u00c0\u0004\u0001\u0000\u0000\u0000\u00c1"+
- "\u00c2\u0005a\u0000\u0000\u00c2\u00c3\u0005n\u0000\u0000\u00c3\u00c4\u0005"+
- "d\u0000\u0000\u00c4\u0006\u0001\u0000\u0000\u0000\u00c5\u00c6\u0005a\u0000"+
- "\u0000\u00c6\u00c7\u0005s\u0000\u0000\u00c7\b\u0001\u0000\u0000\u0000"+
- "\u00c8\u00c9\u0005d\u0000\u0000\u00c9\u00ca\u0005e\u0000\u0000\u00ca\u00cb"+
- "\u0005f\u0000\u0000\u00cb\n\u0001\u0000\u0000\u0000\u00cc\u00cd\u0005"+
- "e\u0000\u0000\u00cd\u00ce\u0005l\u0000\u0000\u00ce\u00cf\u0005i\u0000"+
- "\u0000\u00cf\u00d0\u0005f\u0000\u0000\u00d0\f\u0001\u0000\u0000\u0000"+
- "\u00d1\u00d2\u0005e\u0000\u0000\u00d2\u00d3\u0005l\u0000\u0000\u00d3\u00d4"+
- "\u0005s\u0000\u0000\u00d4\u00d5\u0005e\u0000\u0000\u00d5\u000e\u0001\u0000"+
- "\u0000\u0000\u00d6\u00d7\u0005F\u0000\u0000\u00d7\u00d8\u0005a\u0000\u0000"+
- "\u00d8\u00d9\u0005l\u0000\u0000\u00d9\u00da\u0005s\u0000\u0000\u00da\u00db"+
- "\u0005e\u0000\u0000\u00db\u0010\u0001\u0000\u0000\u0000\u00dc\u00dd\u0005"+
- "f\u0000\u0000\u00dd\u00de\u0005o\u0000\u0000\u00de\u00df\u0005r\u0000"+
- "\u0000\u00df\u0012\u0001\u0000\u0000\u0000\u00e0\u00e1\u0005f\u0000\u0000"+
- "\u00e1\u00e2\u0005r\u0000\u0000\u00e2\u00e3\u0005o\u0000\u0000\u00e3\u00e4"+
- "\u0005m\u0000\u0000\u00e4\u0014\u0001\u0000\u0000\u0000\u00e5\u00e6\u0005"+
- "i\u0000\u0000\u00e6\u00e7\u0005f\u0000\u0000\u00e7\u0016\u0001\u0000\u0000"+
- "\u0000\u00e8\u00e9\u0005i\u0000\u0000\u00e9\u00ea\u0005m\u0000\u0000\u00ea"+
- "\u00eb\u0005p\u0000\u0000\u00eb\u00ec\u0005o\u0000\u0000\u00ec\u00ed\u0005"+
- "r\u0000\u0000\u00ed\u00ee\u0005t\u0000\u0000\u00ee\u0018\u0001\u0000\u0000"+
- "\u0000\u00ef\u00f0\u0005i\u0000\u0000\u00f0\u00f1\u0005n\u0000\u0000\u00f1"+
- "\u001a\u0001\u0000\u0000\u0000\u00f2\u00f3\u0005i\u0000\u0000\u00f3\u00f4"+
- "\u0005s\u0000\u0000\u00f4\u001c\u0001\u0000\u0000\u0000\u00f5\u00f6\u0005"+
- "N\u0000\u0000\u00f6\u00f7\u0005o\u0000\u0000\u00f7\u00f8\u0005n\u0000"+
- "\u0000\u00f8\u00f9\u0005e\u0000\u0000\u00f9\u001e\u0001\u0000\u0000\u0000"+
- "\u00fa\u00fb\u0005n\u0000\u0000\u00fb\u00fc\u0005o\u0000\u0000\u00fc\u00fd"+
- "\u0005t\u0000\u0000\u00fd \u0001\u0000\u0000\u0000\u00fe\u00ff\u0005o"+
- "\u0000\u0000\u00ff\u0100\u0005r\u0000\u0000\u0100\"\u0001\u0000\u0000"+
- "\u0000\u0101\u0102\u0005r\u0000\u0000\u0102\u0103\u0005e\u0000\u0000\u0103"+
- "\u0104\u0005t\u0000\u0000\u0104\u0105\u0005u\u0000\u0000\u0105\u0106\u0005"+
- "r\u0000\u0000\u0106\u0107\u0005n\u0000\u0000\u0107$\u0001\u0000\u0000"+
- "\u0000\u0108\u0109\u0005T\u0000\u0000\u0109\u010a\u0005r\u0000\u0000\u010a"+
- "\u010b\u0005u\u0000\u0000\u010b\u010c\u0005e\u0000\u0000\u010c&\u0001"+
- "\u0000\u0000\u0000\u010d\u010e\u0005_\u0000\u0000\u010e(\u0001\u0000\u0000"+
- "\u0000\u010f\u0110\u0005w\u0000\u0000\u0110\u0111\u0005h\u0000\u0000\u0111"+
- "\u0112\u0005i\u0000\u0000\u0112\u0113\u0005l\u0000\u0000\u0113\u0114\u0005"+
- "e\u0000\u0000\u0114*\u0001\u0000\u0000\u0000\u0115\u0116\u0004\u0015\u0000"+
- "\u0000\u0116\u0122\u0003\u00a3Q\u0000\u0117\u0119\u0005\r\u0000\u0000"+
- "\u0118\u0117\u0001\u0000\u0000\u0000\u0118\u0119\u0001\u0000\u0000\u0000"+
- "\u0119\u011a\u0001\u0000\u0000\u0000\u011a\u011d\u0005\n\u0000\u0000\u011b"+
- "\u011d\u0002\f\r\u0000\u011c\u0118\u0001\u0000\u0000\u0000\u011c\u011b"+
- "\u0001\u0000\u0000\u0000\u011d\u011f\u0001\u0000\u0000\u0000\u011e\u0120"+
- "\u0003\u00a3Q\u0000\u011f\u011e\u0001\u0000\u0000\u0000\u011f\u0120\u0001"+
- "\u0000\u0000\u0000\u0120\u0122\u0001\u0000\u0000\u0000\u0121\u0115\u0001"+
- "\u0000\u0000\u0000\u0121\u011c\u0001\u0000\u0000\u0000\u0122\u0123\u0001"+
- "\u0000\u0000\u0000\u0123\u0124\u0006\u0015\u0000\u0000\u0124,\u0001\u0000"+
- "\u0000\u0000\u0125\u0129\u0007\u0002\u0000\u0000\u0126\u0128\u0007\u0003"+
- "\u0000\u0000\u0127\u0126\u0001\u0000\u0000\u0000\u0128\u012b\u0001\u0000"+
- "\u0000\u0000\u0129\u0127\u0001\u0000\u0000\u0000\u0129\u012a\u0001\u0000"+
- "\u0000\u0000\u012a.\u0001\u0000\u0000\u0000\u012b\u0129\u0001\u0000\u0000"+
- "\u0000\u012c\u0130\u0003\u0097K\u0000\u012d\u012f\u0003\u0099L\u0000\u012e"+
- "\u012d\u0001\u0000\u0000\u0000\u012f\u0132\u0001\u0000\u0000\u0000\u0130"+
- "\u012e\u0001\u0000\u0000\u0000\u0130\u0131\u0001\u0000\u0000\u0000\u0131"+
- "\u0139\u0001\u0000\u0000\u0000\u0132\u0130\u0001\u0000\u0000\u0000\u0133"+
- "\u0135\u00050\u0000\u0000\u0134\u0133\u0001\u0000\u0000\u0000\u0135\u0136"+
- "\u0001\u0000\u0000\u0000\u0136\u0134\u0001\u0000\u0000\u0000\u0136\u0137"+
- "\u0001\u0000\u0000\u0000\u0137\u0139\u0001\u0000\u0000\u0000\u0138\u012c"+
- "\u0001\u0000\u0000\u0000\u0138\u0134\u0001\u0000\u0000\u0000\u01390\u0001"+
- "\u0000\u0000\u0000\u013a\u013d\u0003\u009bM\u0000\u013b\u013d\u0003\u009d"+
- "N\u0000\u013c\u013a\u0001\u0000\u0000\u0000\u013c\u013b\u0001\u0000\u0000"+
- "\u0000\u013d2\u0001\u0000\u0000\u0000\u013e\u013f\u0005.\u0000\u0000\u013f"+
- "4\u0001\u0000\u0000\u0000\u0140\u0141\u0005.\u0000\u0000\u0141\u0142\u0005"+
- ".\u0000\u0000\u0142\u0143\u0005.\u0000\u0000\u01436\u0001\u0000\u0000"+
- "\u0000\u0144\u0145\u0005*\u0000\u0000\u01458\u0001\u0000\u0000\u0000\u0146"+
- "\u0147\u0005(\u0000\u0000\u0147\u0148\u0006\u001c\u0001\u0000\u0148:\u0001"+
- "\u0000\u0000\u0000\u0149\u014a\u0005)\u0000\u0000\u014a\u014b\u0006\u001d"+
- "\u0002\u0000\u014b<\u0001\u0000\u0000\u0000\u014c\u014d\u0005,\u0000\u0000"+
- "\u014d>\u0001\u0000\u0000\u0000\u014e\u014f\u0005:\u0000\u0000\u014f@"+
- "\u0001\u0000\u0000\u0000\u0150\u0151\u0005;\u0000\u0000\u0151B\u0001\u0000"+
- "\u0000\u0000\u0152\u0153\u0005*\u0000\u0000\u0153\u0154\u0005*\u0000\u0000"+
- "\u0154D\u0001\u0000\u0000\u0000\u0155\u0156\u0005=\u0000\u0000\u0156F"+
- "\u0001\u0000\u0000\u0000\u0157\u0158\u0005[\u0000\u0000\u0158\u0159\u0006"+
- "#\u0003\u0000\u0159H\u0001\u0000\u0000\u0000\u015a\u015b\u0005]\u0000"+
- "\u0000\u015b\u015c\u0006$\u0004\u0000\u015cJ\u0001\u0000\u0000\u0000\u015d"+
- "\u015e\u0005|\u0000\u0000\u015eL\u0001\u0000\u0000\u0000\u015f\u0160\u0005"+
- "^\u0000\u0000\u0160N\u0001\u0000\u0000\u0000\u0161\u0162\u0005&\u0000"+
- "\u0000\u0162P\u0001\u0000\u0000\u0000\u0163\u0164\u0005<\u0000\u0000\u0164"+
- "\u0165\u0005<\u0000\u0000\u0165R\u0001\u0000\u0000\u0000\u0166\u0167\u0005"+
- ">\u0000\u0000\u0167\u0168\u0005>\u0000\u0000\u0168T\u0001\u0000\u0000"+
- "\u0000\u0169\u016a\u0005+\u0000\u0000\u016aV\u0001\u0000\u0000\u0000\u016b"+
- "\u016c\u0005-\u0000\u0000\u016cX\u0001\u0000\u0000\u0000\u016d\u016e\u0005"+
- "/\u0000\u0000\u016eZ\u0001\u0000\u0000\u0000\u016f\u0170\u0005%\u0000"+
- "\u0000\u0170\\\u0001\u0000\u0000\u0000\u0171\u0172\u0005/\u0000\u0000"+
- "\u0172\u0173\u0005/\u0000\u0000\u0173^\u0001\u0000\u0000\u0000\u0174\u0175"+
- "\u0005~\u0000\u0000\u0175`\u0001\u0000\u0000\u0000\u0176\u0177\u0005{"+
- "\u0000\u0000\u0177\u0178\u00060\u0005\u0000\u0178b\u0001\u0000\u0000\u0000"+
- "\u0179\u017a\u0005}\u0000\u0000\u017a\u017b\u00061\u0006\u0000\u017bd"+
- "\u0001\u0000\u0000\u0000\u017c\u017d\u0005<\u0000\u0000\u017df\u0001\u0000"+
- "\u0000\u0000\u017e\u017f\u0005>\u0000\u0000\u017fh\u0001\u0000\u0000\u0000"+
- "\u0180\u0181\u0005=\u0000\u0000\u0181\u0182\u0005=\u0000\u0000\u0182j"+
- "\u0001\u0000\u0000\u0000\u0183\u0184\u0005>\u0000\u0000\u0184\u0185\u0005"+
- "=\u0000\u0000\u0185l\u0001\u0000\u0000\u0000\u0186\u0187\u0005<\u0000"+
- "\u0000\u0187\u0188\u0005=\u0000\u0000\u0188n\u0001\u0000\u0000\u0000\u0189"+
- "\u018a\u0005<\u0000\u0000\u018a\u018b\u0005>\u0000\u0000\u018bp\u0001"+
- "\u0000\u0000\u0000\u018c\u018d\u0005!\u0000\u0000\u018d\u018e\u0005=\u0000"+
- "\u0000\u018er\u0001\u0000\u0000\u0000\u018f\u0190\u0005@\u0000\u0000\u0190"+
- "t\u0001\u0000\u0000\u0000\u0191\u0192\u0005-\u0000\u0000\u0192\u0193\u0005"+
- ">\u0000\u0000\u0193v\u0001\u0000\u0000\u0000\u0194\u0195\u0005+\u0000"+
- "\u0000\u0195\u0196\u0005=\u0000\u0000\u0196x\u0001\u0000\u0000\u0000\u0197"+
- "\u0198\u0005-\u0000\u0000\u0198\u0199\u0005=\u0000\u0000\u0199z\u0001"+
- "\u0000\u0000\u0000\u019a\u019b\u0005*\u0000\u0000\u019b\u019c\u0005=\u0000"+
- "\u0000\u019c|\u0001\u0000\u0000\u0000\u019d\u019e\u0005@\u0000\u0000\u019e"+
- "\u019f\u0005=\u0000\u0000\u019f~\u0001\u0000\u0000\u0000\u01a0\u01a1\u0005"+
- "/\u0000\u0000\u01a1\u01a2\u0005=\u0000\u0000\u01a2\u0080\u0001\u0000\u0000"+
- "\u0000\u01a3\u01a4\u0005%\u0000\u0000\u01a4\u01a5\u0005=\u0000\u0000\u01a5"+
- "\u0082\u0001\u0000\u0000\u0000\u01a6\u01a7\u0005&\u0000\u0000\u01a7\u01a8"+
- "\u0005=\u0000\u0000\u01a8\u0084\u0001\u0000\u0000\u0000\u01a9\u01aa\u0005"+
- "|\u0000\u0000\u01aa\u01ab\u0005=\u0000\u0000\u01ab\u0086\u0001\u0000\u0000"+
- "\u0000\u01ac\u01ad\u0005^\u0000\u0000\u01ad\u01ae\u0005=\u0000\u0000\u01ae"+
- "\u0088\u0001\u0000\u0000\u0000\u01af\u01b0\u0005<\u0000\u0000\u01b0\u01b1"+
- "\u0005<\u0000\u0000\u01b1\u01b2\u0005=\u0000\u0000\u01b2\u008a\u0001\u0000"+
- "\u0000\u0000\u01b3\u01b4\u0005>\u0000\u0000\u01b4\u01b5\u0005>\u0000\u0000"+
- "\u01b5\u01b6\u0005=\u0000\u0000\u01b6\u008c\u0001\u0000\u0000\u0000\u01b7"+
- "\u01b8\u0005*\u0000\u0000\u01b8\u01b9\u0005*\u0000\u0000\u01b9\u01ba\u0005"+
- "=\u0000\u0000\u01ba\u008e\u0001\u0000\u0000\u0000\u01bb\u01bc\u0005/\u0000"+
- "\u0000\u01bc\u01bd\u0005/\u0000\u0000\u01bd\u01be\u0005=\u0000\u0000\u01be"+
- "\u0090\u0001\u0000\u0000\u0000\u01bf\u01c3\u0003\u00a3Q\u0000\u01c0\u01c3"+
- "\u0003\u00a5R\u0000\u01c1\u01c3\u0003\u00a7S\u0000\u01c2\u01bf\u0001\u0000"+
- "\u0000\u0000\u01c2\u01c0\u0001\u0000\u0000\u0000\u01c2\u01c1\u0001\u0000"+
- "\u0000\u0000\u01c3\u01c4\u0001\u0000\u0000\u0000\u01c4\u01c5\u0006H\u0007"+
- "\u0000\u01c5\u0092\u0001\u0000\u0000\u0000\u01c6\u01c7\t\u0000\u0000\u0000"+
- "\u01c7\u0094\u0001\u0000\u0000\u0000\u01c8\u01c9\u0005\\\u0000\u0000\u01c9"+
- "\u01cd\t\u0000\u0000\u0000\u01ca\u01cb\u0005\\\u0000\u0000\u01cb\u01cd"+
- "\u0003+\u0015\u0000\u01cc\u01c8\u0001\u0000\u0000\u0000\u01cc\u01ca\u0001"+
- "\u0000\u0000\u0000\u01cd\u0096\u0001\u0000\u0000\u0000\u01ce\u01cf\u0007"+
- "\u0004\u0000\u0000\u01cf\u0098\u0001\u0000\u0000\u0000\u01d0\u01d1\u0007"+
- "\u0005\u0000\u0000\u01d1\u009a\u0001\u0000\u0000\u0000\u01d2\u01d4\u0003"+
- "\u009fO\u0000\u01d3\u01d2\u0001\u0000\u0000\u0000\u01d3\u01d4\u0001\u0000"+
- "\u0000\u0000\u01d4\u01d5\u0001\u0000\u0000\u0000\u01d5\u01d7\u0005.\u0000"+
- "\u0000\u01d6\u01d8\u0003\u0099L\u0000\u01d7\u01d6\u0001\u0000\u0000\u0000"+
- "\u01d8\u01d9\u0001\u0000\u0000\u0000\u01d9\u01d7\u0001\u0000\u0000\u0000"+
- "\u01d9\u01da\u0001\u0000\u0000\u0000\u01da\u01df\u0001\u0000\u0000\u0000"+
- "\u01db\u01dc\u0003\u009fO\u0000\u01dc\u01dd\u0005.\u0000\u0000\u01dd\u01df"+
- "\u0001\u0000\u0000\u0000\u01de\u01d3\u0001\u0000\u0000\u0000\u01de\u01db"+
- "\u0001\u0000\u0000\u0000\u01df\u009c\u0001\u0000\u0000\u0000\u01e0\u01e3"+
- "\u0003\u009fO\u0000\u01e1\u01e3\u0003\u009bM\u0000\u01e2\u01e0\u0001\u0000"+
- "\u0000\u0000\u01e2\u01e1\u0001\u0000\u0000\u0000\u01e3\u01e4\u0001\u0000"+
- "\u0000\u0000\u01e4\u01e5\u0003\u00a1P\u0000\u01e5\u009e\u0001\u0000\u0000"+
- "\u0000\u01e6\u01e8\u0003\u0099L\u0000\u01e7\u01e6\u0001\u0000\u0000\u0000"+
- "\u01e8\u01e9\u0001\u0000\u0000\u0000\u01e9\u01e7\u0001\u0000\u0000\u0000"+
- "\u01e9\u01ea\u0001\u0000\u0000\u0000\u01ea\u00a0\u0001\u0000\u0000\u0000"+
- "\u01eb\u01ed\u0007\u0006\u0000\u0000\u01ec\u01ee\u0007\u0007\u0000\u0000"+
- "\u01ed\u01ec\u0001\u0000\u0000\u0000\u01ed\u01ee\u0001\u0000\u0000\u0000"+
- "\u01ee\u01f0\u0001\u0000\u0000\u0000\u01ef\u01f1\u0003\u0099L\u0000\u01f0"+
- "\u01ef\u0001\u0000\u0000\u0000\u01f1\u01f2\u0001\u0000\u0000\u0000\u01f2"+
- "\u01f0\u0001\u0000\u0000\u0000\u01f2\u01f3\u0001\u0000\u0000\u0000\u01f3"+
- "\u00a2\u0001\u0000\u0000\u0000\u01f4\u01f6\u0007\b\u0000\u0000\u01f5\u01f4"+
- "\u0001\u0000\u0000\u0000\u01f6\u01f7\u0001\u0000\u0000\u0000\u01f7\u01f5"+
- "\u0001\u0000\u0000\u0000\u01f7\u01f8\u0001\u0000\u0000\u0000\u01f8\u00a4"+
- "\u0001\u0000\u0000\u0000\u01f9\u01fd\u0005#\u0000\u0000\u01fa\u01fc\b"+
- "\t\u0000\u0000\u01fb\u01fa\u0001\u0000\u0000\u0000\u01fc\u01ff\u0001\u0000"+
- "\u0000\u0000\u01fd\u01fb\u0001\u0000\u0000\u0000\u01fd\u01fe\u0001\u0000"+
- "\u0000\u0000\u01fe\u00a6\u0001\u0000\u0000\u0000\u01ff\u01fd\u0001\u0000"+
- "\u0000\u0000\u0200\u0202\u0005\\\u0000\u0000\u0201\u0203\u0003\u00a3Q"+
- "\u0000\u0202\u0201\u0001\u0000\u0000\u0000\u0202\u0203\u0001\u0000\u0000"+
- "\u0000\u0203\u0209\u0001\u0000\u0000\u0000\u0204\u0206\u0005\r\u0000\u0000"+
- "\u0205\u0204\u0001\u0000\u0000\u0000\u0205\u0206\u0001\u0000\u0000\u0000"+
- "\u0206\u0207\u0001\u0000\u0000\u0000\u0207\u020a\u0005\n\u0000\u0000\u0208"+
- "\u020a\u0002\f\r\u0000\u0209\u0205\u0001\u0000\u0000\u0000\u0209\u0208"+
- "\u0001\u0000\u0000\u0000\u020a\u00a8\u0001\u0000\u0000\u0000\u001e\u0000"+
- "\u00ac\u00ae\u00b5\u00b7\u00bb\u00bf\u0118\u011c\u011f\u0121\u0129\u0130"+
- "\u0136\u0138\u013c\u01c2\u01cc\u01d3\u01d9\u01de\u01e2\u01e9\u01ed\u01f2"+
- "\u01f7\u01fd\u0202\u0205\u0209\b\u0001\u0015\u0000\u0001\u001c\u0001\u0001"+
- "\u001d\u0002\u0001#\u0003\u0001$\u0004\u00010\u0005\u00011\u0006\u0006"+
- "\u0000\u0000";
- public static final ATN _ATN =
- new ATNDeserializer().deserialize(_serializedATN.toCharArray());
- static {
- _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
- for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
- _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
- }
- }
-} \ No newline at end of file
diff --git a/src/parser/.antlr/Python3Lexer.tokens b/src/parser/.antlr/Python3Lexer.tokens
deleted file mode 100644
index 0f817cc..0000000
--- a/src/parser/.antlr/Python3Lexer.tokens
+++ /dev/null
@@ -1,142 +0,0 @@
-INDENT=1
-DEDENT=2
-STRING=3
-NUMBER=4
-AND=5
-AS=6
-DEF=7
-ELIF=8
-ELSE=9
-FALSE=10
-FOR=11
-FROM=12
-IF=13
-IMPORT=14
-IN=15
-IS=16
-NONE=17
-NOT=18
-OR=19
-RETURN=20
-TRUE=21
-UNDERSCORE=22
-WHILE=23
-NEWLINE=24
-NAME=25
-DECIMAL_INTEGER=26
-FLOAT_NUMBER=27
-DOT=28
-ELLIPSIS=29
-STAR=30
-OPEN_PAREN=31
-CLOSE_PAREN=32
-COMMA=33
-COLON=34
-SEMI_COLON=35
-POWER=36
-ASSIGN=37
-OPEN_BRACK=38
-CLOSE_BRACK=39
-OR_OP=40
-XOR=41
-AND_OP=42
-LEFT_SHIFT=43
-RIGHT_SHIFT=44
-ADD=45
-MINUS=46
-DIV=47
-MOD=48
-IDIV=49
-NOT_OP=50
-OPEN_BRACE=51
-CLOSE_BRACE=52
-LESS_THAN=53
-GREATER_THAN=54
-EQUALS=55
-GT_EQ=56
-LT_EQ=57
-NOT_EQ_1=58
-NOT_EQ_2=59
-AT=60
-ARROW=61
-ADD_ASSIGN=62
-SUB_ASSIGN=63
-MULT_ASSIGN=64
-AT_ASSIGN=65
-DIV_ASSIGN=66
-MOD_ASSIGN=67
-AND_ASSIGN=68
-OR_ASSIGN=69
-XOR_ASSIGN=70
-LEFT_SHIFT_ASSIGN=71
-RIGHT_SHIFT_ASSIGN=72
-POWER_ASSIGN=73
-IDIV_ASSIGN=74
-SKIP_=75
-UNKNOWN_CHAR=76
-'and'=5
-'as'=6
-'def'=7
-'elif'=8
-'else'=9
-'False'=10
-'for'=11
-'from'=12
-'if'=13
-'import'=14
-'in'=15
-'is'=16
-'None'=17
-'not'=18
-'or'=19
-'return'=20
-'True'=21
-'_'=22
-'while'=23
-'.'=28
-'...'=29
-'*'=30
-'('=31
-')'=32
-','=33
-':'=34
-';'=35
-'**'=36
-'='=37
-'['=38
-']'=39
-'|'=40
-'^'=41
-'&'=42
-'<<'=43
-'>>'=44
-'+'=45
-'-'=46
-'/'=47
-'%'=48
-'//'=49
-'~'=50
-'{'=51
-'}'=52
-'<'=53
-'>'=54
-'=='=55
-'>='=56
-'<='=57
-'<>'=58
-'!='=59
-'@'=60
-'->'=61
-'+='=62
-'-='=63
-'*='=64
-'@='=65
-'/='=66
-'%='=67
-'&='=68
-'|='=69
-'^='=70
-'<<='=71
-'>>='=72
-'**='=73
-'//='=74
diff --git a/src/semanticanalysis/STentry.java b/src/semanticanalysis/STentry.java
index 0e4b00e..51fb109 100644
--- a/src/semanticanalysis/STentry.java
+++ b/src/semanticanalysis/STentry.java
@@ -6,9 +6,10 @@ import ast.types.Type;
* Entry class for the symbol table.
*/
public class STentry {
- private Type type;
- private int offset;
- private int nesting;
+
+ private final Type type;
+ private final int offset;
+ private final int nesting;
private String label;
public STentry(Type type, int offset, int nesting) {
@@ -52,4 +53,10 @@ public class STentry {
return label;
}
+ @Override
+ public String toString() {
+ // Print all the fields of the STentry
+ return "Type: " + type + ", Offset: " + offset + ", Nesting: " + nesting + ", Label: " + label;
+ }
+
}
diff --git a/src/semanticanalysis/SemanticError.java b/src/semanticanalysis/SemanticError.java
index 745e3fb..ac2dc4c 100644
--- a/src/semanticanalysis/SemanticError.java
+++ b/src/semanticanalysis/SemanticError.java
@@ -4,12 +4,14 @@ package semanticanalysis;
* Class respresents a semantic error.
*/
public class SemanticError {
- private String msg;
+
+ private final String msg;
public SemanticError(String msg) {
this.msg = msg;
}
+ @Override
public String toString() {
return msg;
}
diff --git a/src/semanticanalysis/Share.java b/src/semanticanalysis/Share.java
new file mode 100644
index 0000000..7542cf7
--- /dev/null
+++ b/src/semanticanalysis/Share.java
@@ -0,0 +1,58 @@
+package semanticanalysis;
+
+import java.io.*;
+import java.util.*;
+
+public class Share {
+
+ /**
+ * Removes the duplicate elements in a list of Semantic Errors. It's not
+ * generic because it's used a custom contains function.
+ */
+ public static ArrayList<SemanticError> removeDuplicates(ArrayList<SemanticError> list) {
+ ArrayList<SemanticError> newList = new ArrayList();
+
+ for (SemanticError element : list) {
+ if (!customContains(newList, element)) {
+ newList.add(element);
+ }
+ }
+ return newList;
+ }
+
+ /**
+ * Normal contains did not work, so we made a custom contains function.
+ * Returns `true` if the String rappresentation of an object in the list is
+ * equal to the element given in input.
+ */
+ private static boolean customContains(ArrayList<SemanticError> list, SemanticError e) {
+ String e1 = e.toString();
+ for (SemanticError element : list) {
+ String e2 = element.toString();
+ if (e2.equals(e1)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static String getExtension(String fileName) {
+ int extensionIndex = fileName.lastIndexOf('.');
+ if (extensionIndex == -1) {
+ return fileName;
+ } else {
+ return fileName.substring(extensionIndex + 1);
+ }
+ }
+
+ public static String readFile(String filePath) throws IOException {
+ StringBuilder content = new StringBuilder();
+ try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ content.append(line).append("\n");
+ }
+ }
+ return content.toString();
+ }
+}
diff --git a/src/semanticanalysis/SymbolTable.java b/src/semanticanalysis/SymbolTable.java
index f2876db..b620af7 100644
--- a/src/semanticanalysis/SymbolTable.java
+++ b/src/semanticanalysis/SymbolTable.java
@@ -1,8 +1,8 @@
package semanticanalysis;
+import ast.types.*;
import java.util.ArrayList;
import java.util.HashMap;
-import ast.types.*;
/**
* Class representing a symbol table. It's a list of hash table symbol table. We
@@ -11,12 +11,12 @@ import ast.types.*;
*/
public class SymbolTable {
- private ArrayList<HashMap<String, STentry>> symbolTable;
- private ArrayList<Integer> offset;
+ private final ArrayList<HashMap<String, STentry>> symbolTable;
+ private final ArrayList<Integer> offset;
public SymbolTable() {
- this.symbolTable = new ArrayList<HashMap<String, STentry>>();
- this.offset = new ArrayList<Integer>();
+ this.symbolTable = new ArrayList();
+ this.offset = new ArrayList();
}
/**
@@ -40,8 +40,8 @@ public class SymbolTable {
HashMap<String, STentry> H = this.symbolTable.get(n);
T = H.get(id);
if (T != null) {
- found = true;
- }else {
+ found = true;
+ } else {
n = n - 1;
}
}
@@ -60,8 +60,8 @@ public class SymbolTable {
while ((n >= 0) && !found) {
HashMap<String, STentry> H = this.symbolTable.get(n);
if (H.get(id) != null) {
- found = true;
- }else {
+ found = true;
+ } else {
n = n - 1;
}
}
@@ -96,7 +96,7 @@ public class SymbolTable {
*/
public boolean top_lookup(String id) {
int n = symbolTable.size() - 1;
- STentry T = null;
+ STentry T;
HashMap<String, STentry> H = symbolTable.get(n);
T = H.get(id);
return (T != null);
@@ -125,15 +125,10 @@ public class SymbolTable {
// We always increment the offset by 1 otherwise we need ad-hoc bytecode
// operations
- if (type.getClass().equals((new BoolType()).getClass())) {
- offs = offs + 1;
- } else if (type.getClass().equals((new IntType()).getClass())) {
- offs = offs + 1;
- } else {
- offs = offs + 1;
- }
+ offs = offs + 1;
this.offset.add(offs);
+
}
/**
@@ -149,4 +144,19 @@ public class SymbolTable {
this.offset.add(offs);
}
+ @Override
+ public String toString() {
+ // Print the symbol table
+ String str = "";
+ for (int i = 0; i < this.symbolTable.size(); i++) {
+ str += "Level " + i + "\n";
+ HashMap<String, STentry> H = this.symbolTable.get(i);
+ for (String key : H.keySet()) {
+ STentry T = H.get(key);
+ str += key + " -> " + T.toString() + "\n";
+ }
+ }
+ return str;
+ }
+
}
diff --git a/test/1a.py b/test/1a.py
new file mode 100644
index 0000000..69b3dc5
--- /dev/null
+++ b/test/1a.py
@@ -0,0 +1,8 @@
+
+x = 2
+y = z
+
+def f(x, y):
+ return x + y
+
+print(f(5, 3) + x + y)
diff --git a/test/1b.py b/test/1b.py
new file mode 100644
index 0000000..a8324a0
--- /dev/null
+++ b/test/1b.py
@@ -0,0 +1,6 @@
+x = 2 ; y = 3
+
+def f(x, x):
+ return x+y
+
+print(f(5,3)+ x + y)
diff --git a/test/1c.py b/test/1c.py
new file mode 100644
index 0000000..59e51e5
--- /dev/null
+++ b/test/1c.py
@@ -0,0 +1,5 @@
+
+def mult(a, b):
+ return a * b
+
+print(mult(3, 2, 4))
diff --git a/test/trailers.py b/test/trailers.py
new file mode 100644
index 0000000..278a2d4
--- /dev/null
+++ b/test/trailers.py
@@ -0,0 +1,13 @@
+
+def mult(nums):
+ ret = []
+ for a, b in nums:
+ ret.append(a * b)
+ return ret
+
+print(mult([(2, 4), (5, 2)]))
+
+
+# left, right = 1, 2
+# print(left)
+# print(right)