Commit cd7873f3 authored by Kevin Wu's avatar Kevin Wu

More node types; add remaining Java primitives

parent 9ef005ee
......@@ -6,10 +6,14 @@ package io.kwu.kythera.parser;
* to fully describe and distinguish the type.
*/
public enum BaseType {
BOOL("bool", true),
BYTE("byte", true),
SHORT("short", true),
INT("int", true),
LONG("long", true),
FLOAT("float", true),
DOUBLE("double", true),
BOOL("bool", true),
CHAR("char", true),
TYPE("type", true), // type may not be scalar in the future
LIST("list", false),
TUPLE("tuple", false),
......@@ -23,4 +27,4 @@ public enum BaseType {
this.name = name;
this.scalar = scalar;
}
}
}
\ No newline at end of file
package io.kwu.kythera.parser;
import java.util.List;
public class FnNodeType extends NodeType {
public final List<NodeType> parameters;
public final NodeType returnType;
public FnNodeType(List<NodeType> parameters, NodeType returnType) {
super(BaseType.FN);
this.parameters = parameters;
this.returnType = returnType;
}
@Override
public boolean equals(Object other) {
if(!(other instanceof FnNodeType)) {
return false;
}
FnNodeType otherFnNodeType = (FnNodeType)other;
assert(otherFnNodeType.baseType.equals(BaseType.FN));
return this.returnType.equals(otherFnNodeType.returnType) &&
this.parameters.equals(otherFnNodeType.parameters);
}
}
package io.kwu.kythera.parser;
public final class Parser {
public Parser() {
......
package io.kwu.kythera.parser;
import java.util.HashMap;
import java.util.Map;
public class StructNodeType extends NodeType {
public final HashMap<String, NodeType> entries;
public final Map<String, NodeType> entries;
public StructNodeType(HashMap<String, NodeType> entries) {
public StructNodeType(Map<String, NodeType> entries) {
super(BaseType.STRUCT);
this.entries = entries;
}
......@@ -19,6 +19,6 @@ public class StructNodeType extends NodeType {
StructNodeType otherStructNodeType = (StructNodeType)other;
assert(otherStructNodeType.baseType.equals(BaseType.STRUCT));
return otherStructNodeType.entries.equals(this.entries);
return this.entries.equals(otherStructNodeType.entries);
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ public enum NodeKind {
WHILE,
RETURN,
// AS,
// TYPEOF,
CALL,
ACCESS,
THIS,
......
......@@ -13,10 +13,10 @@ public class ScalarLiteralNode<V> extends LiteralNode {
public ScalarLiteralNode(NodeType type, V value) throws ParserException {
super(type);
if(!type.baseType.scalar) {
if (!type.baseType.scalar) {
throw new ParserException(type.baseType.name + " is not a scalar type.");
}
this.value = value;
}
}
}
\ No newline at end of file
package io.kwu.kythera.parser.node;
public class ThisNode extends ExpressionNode {
public ThisNode() {
super(NodeKind.THIS);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment