diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2024-06-13 09:00:06 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-13 09:00:06 +0000 |
| commit | 8e7089a5d6ba1f4f50a90133bb50bc5c6c554aff (patch) | |
| tree | d4a627e56a199720f7d811af5756402e76628864 /src/ast/types | |
| parent | 1c8761901b26c0be4d61f3aed5ec0495a558a0e7 (diff) | |
Set up visitor (#3)
Co-authored-by: geno <gabriele.genovese2@studio.unibo.it>
Diffstat (limited to 'src/ast/types')
| -rw-r--r-- | src/ast/types/AtomType.java | 11 | ||||
| -rw-r--r-- | src/ast/types/BoolType.java | 10 | ||||
| -rw-r--r-- | src/ast/types/ErrorType.java | 10 | ||||
| -rw-r--r-- | src/ast/types/IntType.java | 10 | ||||
| -rw-r--r-- | src/ast/types/Type.java | 41 | ||||
| -rw-r--r-- | src/ast/types/VoidType.java | 10 |
6 files changed, 92 insertions, 0 deletions
diff --git a/src/ast/types/AtomType.java b/src/ast/types/AtomType.java new file mode 100644 index 0000000..a44a06c --- /dev/null +++ b/src/ast/types/AtomType.java @@ -0,0 +1,11 @@ +package com.clp.project.ast.types; + +/** + * An tom type. + * TODO: do I need to use this one? + */ +public class AtomType extends Type { + public String toPrint(String prefix) { + return prefix + "Atom\n"; + } +} diff --git a/src/ast/types/BoolType.java b/src/ast/types/BoolType.java new file mode 100644 index 0000000..7fc28ee --- /dev/null +++ b/src/ast/types/BoolType.java @@ -0,0 +1,10 @@ +package com.clp.project.ast.types; + +/** + * A boolean type. A bool is True or False. + */ +public class BoolType extends Type { + public String toPrint(String prefix) { + return prefix + "Bool\n"; + } +} diff --git a/src/ast/types/ErrorType.java b/src/ast/types/ErrorType.java new file mode 100644 index 0000000..30cb70e --- /dev/null +++ b/src/ast/types/ErrorType.java @@ -0,0 +1,10 @@ +package com.clp.project.ast.types; + +/** + * Error type. + */ +public class ErrorType extends Type { + public String toPrint(String prefix) { + return prefix + "Error\n"; + } +} diff --git a/src/ast/types/IntType.java b/src/ast/types/IntType.java new file mode 100644 index 0000000..9f4b250 --- /dev/null +++ b/src/ast/types/IntType.java @@ -0,0 +1,10 @@ +package com.clp.project.ast.types; + +/** + * An integer type. + */ +public class IntType extends Type { + public String toPrint(String prefix) { + return prefix + "Int\n"; + } +} diff --git a/src/ast/types/Type.java b/src/ast/types/Type.java new file mode 100644 index 0000000..4756255 --- /dev/null +++ b/src/ast/types/Type.java @@ -0,0 +1,41 @@ +package com.clp.project.ast.types; + +import java.util.ArrayList; + +import com.clp.project.semanticanalysis.SemanticError; +import com.clp.project.semanticanalysis.SymbolTable; +import com.clp.project.ast.nodes.*; + +/** + * A node which represents a type class. + */ +public class Type implements Node { + public boolean isEqual(Type A, Type B) { + if (A.getClass().equals(B.getClass())) + return true; + else + return false; + } + + public String toPrint(String s) { + return s; + } + + public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) { + // It is never invoked + return null; + } + + @Override + public Type typeCheck() { + // It is never invoked + return null; + } + + @Override + public String codeGeneration() { + // It is never invoked + return ""; + } + +} diff --git a/src/ast/types/VoidType.java b/src/ast/types/VoidType.java new file mode 100644 index 0000000..766aee2 --- /dev/null +++ b/src/ast/types/VoidType.java @@ -0,0 +1,10 @@ +package com.clp.project.ast.types; + +/** + * A void type. Voids return nothing. + */ +public class VoidType extends Type { + public String toPrint(String prefix) { + return prefix + "Void\n"; + } +} |
