update
This commit is contained in:
@ -66,7 +66,7 @@ public final class TypeChecker {
|
|||||||
ASTNode literalNode = root.getChildren().get(0);
|
ASTNode literalNode = root.getChildren().get(0);
|
||||||
String literalType = nodeTable.get(literalNode);
|
String literalType = nodeTable.get(literalNode);
|
||||||
|
|
||||||
log("Validating Assignment: " + identifierType + ": " + identifier + " = " + literalNode.toString().trim());
|
log("Validating Assignment: " + identifierType + ": " + identifier + " = " + literalType);
|
||||||
|
|
||||||
if (!literalType.equals(identifierType)) {
|
if (!literalType.equals(identifierType)) {
|
||||||
throw new AssignmentTypeMismatchException("Trying to assign " + literalType + " to a " + identifierType + " variable.");
|
throw new AssignmentTypeMismatchException("Trying to assign " + literalType + " to a " + identifierType + " variable.");
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import parser.ast.AST;
|
|||||||
import parser.ast.ASTBalancer;
|
import parser.ast.ASTBalancer;
|
||||||
import parser.ast.ASTCompacter;
|
import parser.ast.ASTCompacter;
|
||||||
import parser.grammar.Grammar;
|
import parser.grammar.Grammar;
|
||||||
|
import typechecker.TypeChecker;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@ -74,4 +75,18 @@ class Demo {
|
|||||||
ASTBalancer.operatorPrecedence(tree);
|
ASTBalancer.operatorPrecedence(tree);
|
||||||
System.out.println("After operator-precedence:\n" + tree);
|
System.out.println("After operator-precedence:\n" + tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void demoTypeCheck() throws URISyntaxException, IOException {
|
||||||
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
|
Lexer lex = this.initLexer("General.stups");
|
||||||
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
|
|
||||||
|
tree.postprocess(grammar);
|
||||||
|
|
||||||
|
TypeChecker.validate(tree);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
class MyClass {
|
class MyClass {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
boolean b = true;
|
boolean b = true || (1 < 2) && (5 / 4) == 2 && !((1 / 5) == 2 + 1) || (-1 - -5) / 2 == 2 && true == false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user