Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
boozec committed Jun 4, 2024
1 parent c3dd4ef commit 289494c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 0 additions & 4 deletions progs/test2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
x = 1
if x == 1:
print("a")
else:
print("b")
21 changes: 18 additions & 3 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,34 @@ public static void main(String[] args) {

CharStream cs = CharStreams.fromFileName(fileStr);
Python3Lexer lexer = new Python3Lexer(cs);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
Python3Parser parser = new Python3Parser(tokenStream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Python3Parser parser = new Python3Parser(tokens);
Python3Parser.RootContext tree = parser.root();

// DEBUG
{
tokens.fill();
for (Token token : tokens.getTokens()) {
System.out.println(token.toString());
}

System.out.println("Tree: " + tree);
}

if (tree == null) {
System.err.println("The tree is null.");
return;
}

if (parser.getNumberOfSyntaxErrors() > 0) {
System.err.println("Error on program parsing.");
return;
}

Python3VisitorImpl visitor = new Python3VisitorImpl();
SymbolTable ST = new SymbolTable();
Node ast = visitor.visit(tree);

SymbolTable ST = new SymbolTable();
ArrayList<SemanticError> errors = ast.checkSemantics(ST, 0);
if (errors.size() > 0) {
System.out.println("You had: " + errors.size() + " errors:");
Expand Down

0 comments on commit 289494c

Please sign in to comment.