johns-branch #4
@ -2,16 +2,10 @@ public class Example {
|
|||||||
|
|
||||||
public int test;
|
public int test;
|
||||||
|
|
||||||
public static int test(char b){
|
public static int TestMethod(char b){
|
||||||
|
|
||||||
test = 3;
|
test = 3;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Test {
|
|
||||||
|
|
||||||
public char test;
|
|
||||||
|
|
||||||
}
|
|
@ -2,10 +2,10 @@ package ast;
|
|||||||
|
|
||||||
public class ExpressionNode extends ASTNode {
|
public class ExpressionNode extends ASTNode {
|
||||||
|
|
||||||
int Value;
|
public int value;
|
||||||
|
|
||||||
public ExpressionNode(int value) {
|
public ExpressionNode(int value) {
|
||||||
this.Value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@ import java.util.List;
|
|||||||
|
|
||||||
public class SemanticAnalyzer {
|
public class SemanticAnalyzer {
|
||||||
|
|
||||||
List<Identifier> usedIdentifier = new ArrayList<>();
|
|
||||||
|
|
||||||
public void analyze(ASTNode node) {
|
public void analyze(ASTNode node) {
|
||||||
if (node == null) return;
|
if (node == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (node instanceof ClassNode) {
|
if (node instanceof ClassNode) {
|
||||||
|
|
||||||
@ -25,17 +25,30 @@ public class SemanticAnalyzer {
|
|||||||
analyze(member);
|
analyze(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (node instanceof AssignmentNode) {
|
||||||
|
AssignmentNode assignmentNode = (AssignmentNode) node;
|
||||||
|
System.out.println("Assignment ");
|
||||||
|
|
||||||
}else if (node instanceof ConstructorNode) {
|
|
||||||
|
|
||||||
|
analyze(assignmentNode.expression);
|
||||||
|
|
||||||
|
} else if (node instanceof MethodNode) {
|
||||||
|
MethodNode methodNode = (MethodNode) node;
|
||||||
|
System.out.println("Methode: " + methodNode.identifier.getName());
|
||||||
|
List<StatementNode> statementNodes = methodNode.statements;
|
||||||
|
for (StatementNode statement : statementNodes) {
|
||||||
|
analyze(statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (node instanceof ExpressionNode) {
|
||||||
|
ExpressionNode expressionNode = (ExpressionNode) node;
|
||||||
|
System.out.println("Klasse besitzt keinen Expression " + expressionNode.value);
|
||||||
|
|
||||||
} else if (node instanceof FieldNode) {
|
} else if (node instanceof FieldNode) {
|
||||||
|
|
||||||
FieldNode fieldNode = (FieldNode) node;
|
FieldNode fieldNode = (FieldNode) node;
|
||||||
if(identifierAlreadyUsed(fieldNode.identifier)){
|
|
||||||
//throw new RuntimeException("Error: Identifier already used");
|
|
||||||
System.out.println("Error: Identifier already used");
|
|
||||||
}
|
|
||||||
usedIdentifier.add(fieldNode.identifier);
|
|
||||||
|
|
||||||
} else if (node instanceof ProgramNode) {
|
} else if (node instanceof ProgramNode) {
|
||||||
ProgramNode programNode = (ProgramNode) node;
|
ProgramNode programNode = (ProgramNode) node;
|
||||||
@ -47,12 +60,4 @@ public class SemanticAnalyzer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean identifierAlreadyUsed(Identifier identifier){
|
|
||||||
if(usedIdentifier.contains(identifier)){
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user