Compare commits

..

No commits in common. "09e36a84dc3eca72be24e202e3e5e35eb0a986ea" and "514f7d724ab3c398c39a7f14f43a82bb9e3e6830" have entirely different histories.

7 changed files with 17 additions and 19 deletions

2
.idea/misc.xml generated
View File

@ -40,7 +40,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -1,25 +1,24 @@
package ast.literal;
import ast.expression.ExpressionNode;
import ast.type.TypeNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class LiteralNode implements ExpressionNode {
public String value;
private TypeNode type;
private String type;
public LiteralNode(String value, TypeNode type) {
public LiteralNode(String value, String type) {
this.value = value;
this.type = type;
}
public TypeNode getType() {
public String getType() {
return type;
}
public void setType(TypeNode type) {
public void setType(String type) {
this.type = type;
}

View File

@ -230,33 +230,33 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitLiteral(SimpleJavaParser.LiteralContext ctx) {
TypeNode type;
String type;
String value;
if(ctx.INTEGERLITERAL() != null) {
type = new BaseTypeNode(EnumTypeNode.INT);
type = "int";
value = ctx.INTEGERLITERAL().getText();
return new LiteralNode(value, type);
return new LiteralNode(type, value);
} else if(ctx.booleanLiteral() != null) {
type= new BaseTypeNode(EnumTypeNode.BOOLEAN);
type= "boolean";
BooleanLiteralNode booleanNode = (BooleanLiteralNode) visitBooleanLiteral(ctx.booleanLiteral());
value = booleanNode.getValue();
return new LiteralNode(value, type);
return new LiteralNode(type, value);
} else if(ctx.charLiteral() != null) {
type= new BaseTypeNode(EnumTypeNode.CHAR);
type= "char";
CharLiteralNode charNode = (CharLiteralNode) visitCharLiteral(ctx.charLiteral());
value = charNode.getValue();
return new LiteralNode(value, type);
return new LiteralNode(type, value);
}
return null;
}
@Override
public ASTNode visitBooleanLiteral(SimpleJavaParser.BooleanLiteralContext ctx) {
return (ASTNode) new BooleanLiteralNode(ctx.getText());
return super.visitBooleanLiteral(ctx);
}
@Override
public ASTNode visitCharLiteral(SimpleJavaParser.CharLiteralContext ctx) {
return (ASTNode) new CharLiteralNode(ctx.getText());
return super.visitCharLiteral(ctx);
}
}

View File

@ -146,6 +146,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override
public TypeCheckResult analyze(AssignmentStatementNode assignmentStatementNode) {
boolean valid = true;
BinaryExpressionNode binaryExpressionNode = assignmentStatementNode.expression;
var result = binaryExpressionNode.accept(this);
valid = valid && result.isValid();
return new TypeCheckResult(valid, null);
}

View File

@ -4,10 +4,6 @@ public class Example {
public static int testMethod(char x){
a = 12;
a = x;
}
}