diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e61ff3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/bin +.classpath +.project +.settings/ \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000..061bb59 --- /dev/null +++ b/README @@ -0,0 +1,9 @@ +MiniGen is a mini object oriented language dedicated to genericity experimentations. + +Features: + +* Simple and generic classes; +* Multiple formal types; +* Simple and multiple inheritance; +* Conservation of generic types at compile time (no erase); +* Comparison of generic types in linear time; \ No newline at end of file diff --git a/examples/base_formal.minigen b/examples/base_formal.minigen new file mode 100644 index 0000000..712fb95 --- /dev/null +++ b/examples/base_formal.minigen @@ -0,0 +1,10 @@ +# Fail : Formal type X already declared +#class B1[X, X] end + +# Fail : Formal type conflict +#class Int end +#class Bool end +#class A[T] end +#class B[T] super A[T] end +#class C super A[Bool] end +#class D super B[Int], C end \ No newline at end of file diff --git a/examples/base_inheritance.minigen b/examples/base_inheritance.minigen new file mode 100644 index 0000000..310c93a --- /dev/null +++ b/examples/base_inheritance.minigen @@ -0,0 +1,48 @@ +# Test simple inheritance +class A end +class B end +class C super A end +#class D super A end +#class F super C, D end +#class G super C, D end + +# Test complex inheritance +#class Y1 end +#class Y2 super Y1 end +#class Y3 super Y2, Y4 end +#class Y4 super Y1 end +#class Y5 super Y4, Y2 end +#class Y6 super Y3, Y5 end + +# Test generic super classes +class X1[X : Object, Y: A, Z:Object] end +class X2[X: Object] super X1[X, C, B] end + +# Must fail: Bad bound +#class C1 end +#class C2 super C1 end +#class C3[T: C1] end +#class C4 super C3[Object] end + + +# Must fail: Herit himself +#class Z1 super Z1 end + +# Must fail: Unknown super class +#class Z2 super Z999 end + +# Must fail: Already declared as parent +#class Z3 super A, A end + +# Must fail: Inheritance loop +#class Z4 super Z5 end +#class Z5 super Z4 end + +# Must fail: Formal type arity +#class F1[X: Object] end +#class F2 super F1 end + +# Must fail: Formal type not declared +#class F1[X: Object] end +#class F2 super F1[X] end + diff --git a/examples/base_isa.minigen b/examples/base_isa.minigen new file mode 100644 index 0000000..e7d7e8b --- /dev/null +++ b/examples/base_isa.minigen @@ -0,0 +1,41 @@ +# For : Simple tests +class A1 end +class A2 super A1 end +class A3 super A2 end +class A4 super A3 end +class A5 end + +# For medium tests +class Bool end +class Int end + +class A[T, U] end +class B[T, U] super A[Object, Object] end +class C[T] super A[Bool, Int] end +class D super C[Object] end + +# Simple tests +A1 isa A1 # prints TRUE +A2 isa A1 # prints TRUE +A4 isa A1 # prints TRUE +A5 isa A1 # prints FALSE +A1 isa A5 # prints FALSE + +# Medium tests +Bool isa Int # prints FALSE +B[Int, Bool] isa A[Object, Object] # prints TRUE +B[Object, Object] isa A[Int, Bool] # prints FALSE +B[Object, Object] isa A[Object, Object] # prints TRUE +C[Int] isa A[Bool, Int] # prints TRUE +D isa A[Object, Object] # prints TRUE +C[Bool] isa A[Bool, Int] # prints TRUE + +# Must fail : type undeclared +#Toto isa Bbb + +# Must fail : type undeclared +#C[Toto] isa B[Int] + +# Must fail : generic arity +#C isa A + diff --git a/examples/hard_isa.minigen b/examples/hard_isa.minigen new file mode 100644 index 0000000..b75b86c --- /dev/null +++ b/examples/hard_isa.minigen @@ -0,0 +1,32 @@ +class Number end +class Int super Number end +class Bool end + +# For: Test 1 +class X[T] end +class A[U] end +class B[V] super A[X[V]] end +class C[W] super B[X[W]] end +class D super C[Int] end + +# For: Test 2 +#class D[T] end +#class E[T] super D[T] end +#class F[T] super E[T], G[Bool] end +#class G[T] super D[T] end + +# Test 1 +Bool isa Int # prints FALSE +B[Int] isa A[Int] # prints FALSE +B[Int] isa A[X[Int]] # prints TRUE +B[Int] isa A[X[Object]] # prints TRUE +B[Int] isa A[X[Bool]] # prints FALSE +C[Int] isa A[X[X[Int]]] # prints TRUE +C[Int] isa A[X[Int]] # prints FALSE +A[X[X[Int]]] isa A[X[X[Int]]] #prints TRUE +A[X[X[Int]]] isa A[X[X[Bool]]] #prints FALSE +A[X[X[Int]]] isa A[X[X[Number]]] #prints TRUE +B[X[X[Int]]] isa A[X[X[Int]]] #prints FALSE + +# Test 2 +#F[Int] isa D[Bool] # prints TRUE \ No newline at end of file diff --git a/examples/nitstdlib.minigen b/examples/nitstdlib.minigen new file mode 100644 index 0000000..10a3f37 --- /dev/null +++ b/examples/nitstdlib.minigen @@ -0,0 +1,87 @@ +class AbstractArray[E] super AbstractArrayRead[E], Sequence[E] end +class AbstractArrayRead[E] super SequenceRead[E] end +class AbstractSorter[E] super Object end +class AbstractString super AbstractArrayRead[Char] end +class ArrayCapable[E] super Object end +class Array[E] super AbstractArray[E], ArrayCapable[E] end +class ArrayIterator[E] super IndexedIterator[E] end +class ArrayMap[K, E] super CoupleMap[K, E] end +class ArraySet[E] super Set[E] end +class ArraySetIterator[E] super Iterator[E] end +class BMPattern super Pattern end +class Bool super Object end +class BufferedIStream super IStream end +class Buffer super AbstractString, Comparable, StringCapable, AbstractArray[Char] end +class Char super Discrete end +class Collection[E] super Object end +class ComparableSorter[E] super AbstractSorter[E] end +class Comparable super Object end +class Container[E] super Collection[E] end +class ContainerIterator[E] super Iterator[E] end +class Couple[F, S] super Object end +class CoupleMapIterator[K, E] super MapIterator[K, E] end +class CoupleMap[K, E] super Map[K, E] end +class Discrete super Comparable end +class FDIOStream super FDIStream, FDOStream, IOStream end +class FDIStream super FDStream, IStream end +class FDOStream super FDStream, OStream end +class FDStream super IOS end +class FileStat super Pointer end +class Float super Object end +class FStream super IOS, NativeFileCapable end +class HashCollection[K, N, E] super Collection[E], ArrayCapable[E] end +class HashMapIterator[K, V] super MapIterator[K, V] end +class HashMap[K, V] super Map[K, V], HashCollection[K, HashMapNode[K, V], V] end +class HashMapNode[K, V] super HashNode[K] end +class HashNode[K] super Object end +class HashSet[E] super Set[E], HashCollection[E, HashSetNode[E], E] end +class HashSetIterator[E] super Iterator[E] end +class HashSetNode[E] super HashNode[E] end +class IFStream super FStream, BufferedIStream end +class IndexedIterator[E] super MapIterator[Int, E] end +class Int super Discrete end +class IOProcess super IProcess, OProcess, IOStream end +class IOS super Object end +class IOStream super IStream, OStream end +class IProcess super Process, IStream end +class IStream super IOS end +class Iterator[E] super Object end +class IteratorRange[E] super Iterator[E] end +class List[E] super Sequence[E] end +class ListIterator[E] super IndexedIterator[E] end +class ListNode[E] super Container[E] end +class MapIterator[K, E] super Iterator[E] end +class Map[K, E] super RemovableCollection[E], MapRead[K, E] end +class MapRead[K, E] super Collection[E] end +class Match super Object end +class NaiveCollection[E] super Collection[E] end +class NativeArray[E] super Object end +class NativeFileCapable super Object end +class NativeFile super Pointer end +class NativeProcess super Pointer end +class NativeString super Object end +class OFStream super FStream, OStream end +class OProcess super Process, OStream end +class OStream super IOS end +class Pattern super Object end +class Pointer super Object end +class Process super Object end +class Range[E] super Collection[E] end +class RemovableCollection[E] super Collection[E] end +class Sequence[E] super SequenceRead[E], Map[Int, E], SimpleCollection[E] end +class SequenceRead[E] super MapRead[Int, E] end +class Set[E] super SimpleCollection[E] end +class SimpleCollection[E] super RemovableCollection[E] end +class Stderr super OFStream end +class Stdin super IFStream end +class Stdout super OFStream end +class StringCapable super Object end +class String super Pattern, Comparable, AbstractString end +class Symbol super Object end +class Sys super Object end + +# Tests + +Int isa Discrete # prints TRUE +AbstractString isa AbstractArrayRead[Char] # prints TRUE +AbstractString isa MapRead[Int, Char] # prints TRUE diff --git a/examples/test.minigen b/examples/test.minigen new file mode 100644 index 0000000..76eefce --- /dev/null +++ b/examples/test.minigen @@ -0,0 +1,14 @@ +class Number end +class Bool end +class Int super Number end + +class A[T, U] end + +class B[V] super A[Object, V] end + +class C[X, Y, Z] super B[Z] end + + + +A[Bool, Bool] isa A[Object, Object] +A[Object, Object] isa A[Bool, Bool] \ No newline at end of file diff --git a/grammar/minigen.sablecc3 b/grammar/minigen.sablecc3 new file mode 100644 index 0000000..0838fe4 --- /dev/null +++ b/grammar/minigen.sablecc3 @@ -0,0 +1,89 @@ +Package minigen.syntax3; + +Helpers + + upper = ['A'..'Z']; + lower = ['a'..'z']; + letter = [upper+lower]; + digit = ['0'..'9']; + + cr = 13; + lf = 10; + tab = 9; + + eol = cr | lf | cr lf; + + blank = ' ' | eol | tab; + + not_eol = [[0..127]-[cr+lf]]; + +Tokens + + comma = ','; + + lb = '['; + rb = ']'; + + kend = 'end'; + kisa = 'isa'; + kclass = 'class'; + ksuper = 'super'; + knew = 'new'; + + name = upper (letter | digit)*; + + blanks = blank+; + comment = '#' not_eol*; + +Ignored Tokens + blanks, comment; + +Productions + + program = + [classes]: class_decl* [instrs]:instr*; + + class_decl = + kclass name formal_decls? super_decls? kend; + + formal_decls = + lb formal_decl+ rb; + + formal_decl = + name additional_formal_types*; + + additional_formal_types = + comma name; + + type = + name generic_part?; + + generic_part = + lb generic_types rb; + + generic_types = + type additional_types*; + + additional_types = + comma type; + + super_decls = + ksuper super_type additional_supers*; + + additional_supers = + comma super_type; + + super_type = + name super_generic_part?; + + super_generic_part = + lb super_generic_types rb; + + super_generic_types = + super_type super_additional_types*; + + super_additional_types = + comma super_type; + + instr = + {isa} [left]:type kisa [right]:type; \ No newline at end of file diff --git a/lib/sablecc.jar b/lib/sablecc.jar new file mode 100644 index 0000000..1580cd0 Binary files /dev/null and b/lib/sablecc.jar differ diff --git a/src/minigen/ClassAnalysis.java b/src/minigen/ClassAnalysis.java new file mode 100644 index 0000000..331bf54 --- /dev/null +++ b/src/minigen/ClassAnalysis.java @@ -0,0 +1,45 @@ +package minigen; + +import minigen.model.Class; +import minigen.model.ObjectClass; +import minigen.model.Model; +import minigen.syntax3.analysis.DepthFirstAdapter; +import minigen.syntax3.node.AClassDecl; + +public class ClassAnalysis extends DepthFirstAdapter { + + private Model model; + private int currentId; + + public ClassAnalysis(Model classScope) { + this.currentId = 0; + this.model = classScope; + + //Reserve id 0 for Object class + reserveCurrentId(); + + // Declare Object class + this.model.declareClass(null, ObjectClass.getInstance()); + } + + @Override + public void caseAClassDecl(AClassDecl node) { + + //Get the class id + int id = reserveCurrentId(); + + //Declare class + model.declareClass(node, new Class(node.getName().getText().trim(), + node.getKclass(), id)); + } + + /* + * Returns and increments the current id + */ + private int reserveCurrentId() { + int id = this.currentId; + this.currentId++; + return id; + } + +} diff --git a/src/minigen/FormalTypeAnalysis.java b/src/minigen/FormalTypeAnalysis.java new file mode 100644 index 0000000..f301166 --- /dev/null +++ b/src/minigen/FormalTypeAnalysis.java @@ -0,0 +1,89 @@ +package minigen; + +import minigen.model.Class; +import minigen.model.FormalType; +import minigen.model.Model; +import minigen.syntax3.analysis.DepthFirstAdapter; +import minigen.syntax3.node.AAdditionalFormalTypes; +import minigen.syntax3.node.AClassDecl; +import minigen.syntax3.node.AFormalDecl; +import minigen.syntax3.node.AFormalDecls; +import minigen.syntax3.node.Node; +import minigen.syntax3.node.PAdditionalFormalTypes; +import minigen.syntax3.node.PFormalDecl; +import minigen.syntax3.node.Token; +import minigen.exception.*; + +public class FormalTypeAnalysis extends DepthFirstAdapter { + + private Model model; + private Class currentClass; + private int currentPos; + + public FormalTypeAnalysis(Model classScope) { + this.model = classScope; + } + + private void visit(Node node) { + if (node != null) { + node.apply(this); + } + } + + @Override + public void caseAClassDecl(AClassDecl node) { + String name = node.getName().getText().trim(); + + this.currentClass = model.getClassByNode(node.getName(), node, name); + + visit(node.getFormalDecls()); + + this.currentClass = null; + } + + @Override + public void caseAFormalDecls(AFormalDecls node) { + this.currentPos = -1; + for (PFormalDecl f : node.getFormalDecl()) { + visit(f); + } + this.currentPos = -1; + } + + @Override + public void caseAFormalDecl(AFormalDecl node) { + String name = node.getName().getText().trim(); + + this.currentPos++; + FormalType ftype = computeFormalType(node.getName(), name); + this.currentClass.addFormalType(ftype); + + for (PAdditionalFormalTypes f : node.getAdditionalFormalTypes()) { + visit(f); + } + } + + @Override + public void caseAAdditionalFormalTypes(AAdditionalFormalTypes node) { + String name = node.getName().getText().trim(); + + this.currentPos++; + FormalType ftype = computeFormalType(node.getName(), name); + this.currentClass.addFormalType(ftype); + } + + /* + * Check formal type validity + */ + private FormalType computeFormalType(Token token, String name) { + + // Not already declared in local class + if (this.currentClass.isFormalTypeDeclared(name)) { + throw new SemanticException(token, "formal type " + name + + " already declared"); + } + + return new FormalType(name, this.currentPos); + } + +} diff --git a/src/minigen/InheritanceAnalysis.java b/src/minigen/InheritanceAnalysis.java new file mode 100644 index 0000000..e1f4725 --- /dev/null +++ b/src/minigen/InheritanceAnalysis.java @@ -0,0 +1,255 @@ +package minigen; + +import java.util.ArrayList; +import java.util.List; + +import minigen.exception.SemanticException; +import minigen.model.Class; +import minigen.model.FormalType; +import minigen.model.Model; +import minigen.model.ObjectClass; +import minigen.model.ObjectType; +import minigen.model.Type; +import minigen.syntax3.analysis.DepthFirstAdapter; +import minigen.syntax3.node.AClassDecl; +import minigen.syntax3.node.ASuperDecls; +import minigen.syntax3.node.ASuperGenericPart; +import minigen.syntax3.node.ASuperGenericTypes; +import minigen.syntax3.node.ASuperType; +import minigen.syntax3.node.EOF; +import minigen.syntax3.node.Node; +import minigen.syntax3.node.PAdditionalSupers; +import minigen.syntax3.node.PSuperAdditionalTypes; + +public class InheritanceAnalysis extends DepthFirstAdapter { + + private Model model; + private Class currentClass = null; + private Type currentType; + + private List currentSuperClasses; + + public InheritanceAnalysis(Model classScope) { + this.model = classScope; + } + + private void visit(Node node) { + + if (node != null) { + node.apply(this); + } + } + + private Type computeType(Node node) { + this.currentType = null; + visit(node); + Type resultType = this.currentType; + this.currentType = null; + return resultType; + } + + @Override + public void caseAClassDecl(AClassDecl node) { + String name = node.getName().getText().trim(); + + this.currentClass = model.getClassByNode(node.getName(), node, name); + this.currentSuperClasses = new ArrayList(); + visit(node.getSuperDecls()); + + this.currentClass = null; + this.currentSuperClasses = null; + } + + @Override + public void caseASuperDecls(ASuperDecls node) { + Type type = computeType(node.getSuperType()); + + Class parent = computeClassParent(node, type); + + this.currentClass.addParent(parent, type.getGenericTypes()); + this.currentSuperClasses.add(parent); + + for (PAdditionalSupers t : node.getAdditionalSupers()) { + type = computeType(t); + + if (!model.containsClassDeclaration(type.getName())) { + throw new SemanticException(node.getKsuper(), "class " + + type.getName() + " not declared"); + } + + parent = computeClassParent(node, type); + + this.currentClass.addParent(parent, type.getGenericTypes()); + this.currentSuperClasses.add(parent); + } + } + + @Override + public void caseASuperType(ASuperType node) { + String name = node.getName().getText().trim(); + + if (name.equals(ObjectType.getInstance().getName())) { + this.currentType = ObjectType.getInstance(); + } else { + Class intro; + FormalType link = null; + if (!model.containsClassDeclaration(name)) { + if (!this.currentClass.isFormalTypeDeclared(name)) { + throw new SemanticException(node.getName(), "class " + name + + " not declared"); + } else { + intro = this.currentClass; + link = this.currentClass.getFormalType(name); + } + } else { + intro = model.getClassByName(node.getName(), name); + } + + this.currentType = new Type(name, intro); + this.currentType.setFormalTypeLink(link); + } + + visit(node.getSuperGenericPart()); + } + + @Override + public void caseASuperGenericPart(ASuperGenericPart node) { + visit(node.getSuperGenericTypes()); + } + + @Override + public void caseASuperGenericTypes(ASuperGenericTypes node) { + + Type savedType = this.currentType; + Type type = computeType(node.getSuperType()); + savedType.addGenericType(type); + + for (PSuperAdditionalTypes t : node.getSuperAdditionalTypes()) { + type = computeType(t); + savedType.addGenericType(type); + } + + this.currentType = savedType; + } + + /** + * Check if a super definition is repeated like: class A super B, B, ... + */ + public boolean checkAlreadyInSuper(Class c) { + return this.currentSuperClasses.contains(c); + } + + /** + * Check if a super definition is not the current class definition like: + * class A super A + */ + public boolean checkIsItSelf(Class c) { + if (this.currentClass.getName().equals(c.getName())) { + return true; + } + return false; + } + + public boolean checkGenericPartArity(Class parent, Type type) { + if (parent.getFormalTypes().size() != type.getArity()) { + return false; + } + return true; + } + + /** + * Check inheritance loops like: A <: B and B <: A + * + * @param type + * @return + */ + public boolean checkInheritanceLoop(Class parent) { + if (parent.isSubClassOf(this.currentClass)) { + return true; + } + return false; + } + + public Class computeClassParent(ASuperDecls node, Type type) { + if (!model.containsClassDeclaration(type.getName())) { + throw new SemanticException(node.getKsuper(), "class " + + type.getName() + " not declared"); + } + + Class parent = model.getClassByName(node.getKsuper(), type.getName()); + + // Check parent is not class it self + if (checkIsItSelf(parent)) { + throw new SemanticException(node.getKsuper(), "Class " + + parent.getName() + " cannot import itself"); + } + + // Check parent not already in current super clause + if (checkAlreadyInSuper(parent)) { + throw new SemanticException(node.getKsuper(), parent.getName() + + " already declared as parent in this super clause"); + } + + // Check inheritance loops + if (checkInheritanceLoop(parent)) { + throw new SemanticException(node.getKsuper(), + "Loop inheritance between class " + + this.currentClass.getName() + " and parent " + + parent.getName()); + } + + // Check generic arity + if (!checkGenericPartArity(parent, type)) { + throw new SemanticException(node.getKsuper(), parent.getName() + + " expects " + parent.getFormalTypes().size() + + " parameter(s) (" + type.getArity() + " are provided)"); + } + + // Check generic types are declared + for (Type t : type.getGenericTypes()) { + if (this.currentClass.isFormalTypeDeclared(t.getName())) { + continue; + } + if (!model.containsClassDeclaration(t.getName())) { + System.out.println(type.getName()); + throw new SemanticException(node.getKsuper(), "class " + + t.getName() + " not declared"); + } + } + + // Check bound conformity + /* + * for( int i = 0; i < type.getArity(); i ++ ) { + * + * String name = type.getGenericTypes().get(i).getName(); Type + * localType; + * + * if(model.containsClassDeclaration(name)) { localType = + * model.getClassByName(node.getKsuper(), name).getType(); } else { + * localType = this.currentClass.getFormalType(name).getBound(); } + * + * Type parentType = parent.getOrderedFormalTypes().get(i).getBound(); + * + * if( !localType.isSubTypeOf(parentType)) { throw new + * SemanticException(node.getKsuper(), "generic type " + + * localType.getName() + " must be a subtype of " + parentType.getName() + * + " formal type bound"); } } + */ + + return parent; + } + + /* + * Add Object as parent for all classes that haven't it yet (except Object + * itself) + */ + @Override + public void caseEOF(EOF node) { + for (Class c : model.getClasses()) { + if (c.getParents().isEmpty() && !c.isObjectIntro()) { + c.addParent(ObjectClass.getInstance(), new ArrayList()); + } + } + } + +} \ No newline at end of file diff --git a/src/minigen/Interpreter.java b/src/minigen/Interpreter.java new file mode 100644 index 0000000..b4fee50 --- /dev/null +++ b/src/minigen/Interpreter.java @@ -0,0 +1,127 @@ +package minigen; + +import minigen.exception.SemanticException; +import minigen.model.Class; +import minigen.model.Model; +import minigen.model.Type; +import minigen.syntax3.analysis.DepthFirstAdapter; +import minigen.syntax3.node.AGenericPart; +import minigen.syntax3.node.AGenericTypes; +import minigen.syntax3.node.AIsaInstr; +import minigen.syntax3.node.AType; +import minigen.syntax3.node.Node; +import minigen.syntax3.node.PAdditionalTypes; + +public class Interpreter extends DepthFirstAdapter { + + private Model model; + private Type currentType; + + public Interpreter(Model model) { + this.model = model; + + System.out.println("------- File Statistics -------"); + System.out.println(); + + System.out.println("Classes found : " + model.getClasses().size()); + System.out.println(); + + System.out.println("Max color : " + model.getMaxColor()); + System.out.println(); + + System.out.println("Inheritance relations found:"); + for (Class c : model.getClasses()) { + System.out.println(" - class " + c.toStringWithParents() + " get " + c.getSubClasses().size() + " subclasses (depth : "+ c.getDepth() +")"); + } + System.out.println(); + + System.out.println("Adaptations tables :"); + for(minigen.model.Class c : model.getClasses()) { + System.out.println(" - For class " + c + "("+ c.getClassId() +") : " + c.toStringWithAdaptationsTable()); + } + System.out.println(); + + System.out.println("-------------------------------"); + + + } + + private Type computeType(Node node) { + this.currentType = null; + visit(node); + Type resultType = this.currentType; + this.currentType = null; + return resultType; + } + + private void visit(Node node) { + if (node != null) { + node.apply(this); + } + } + + /* + * Write result of type comparaison on console + */ + @Override + public void caseAIsaInstr(AIsaInstr node) { + + // Compute types + Type leftType = computeType(node.getLeft()); + Type rightType = computeType(node.getRight()); + + // Check isa and display results + System.out.println(" - " + leftType + " isa " + rightType + " => " + + leftType.isa(rightType, leftType)); + + + } + + @Override + public void caseAType(AType node) { + + String name = node.getName().getText().trim(); + if (!model.containsClassDeclaration(name)) { + throw new SemanticException(node.getName(), "class " + name + + " not declared"); + } + this.currentType = new Type(name, model.getClassByName(node.getName(), + name)); + + visit(node.getGenericPart()); + + if (this.currentType.getIntro().getArity() != this.currentType + .getArity()) { + throw new SemanticException(node.getName(), this.currentType + .getIntro().getName() + + " expects " + + this.currentType.getIntro().getArity() + + " parameter(s) (" + + this.currentType.getArity() + + " are provided)"); + } + } + + @Override + public void caseAGenericPart(AGenericPart node) { + visit(node.getGenericTypes()); + } + + @Override + public void caseAGenericTypes(AGenericTypes node) { + Type savedType = this.currentType; + + Type type = computeType(node.getType()); + savedType.addGenericType(type); + type = null; + + for (PAdditionalTypes t : node.getAdditionalTypes()) { + type = computeType(t); + savedType.addGenericType(type); + type = null; + } + + this.currentType = savedType; + } + +} diff --git a/src/minigen/Main.java b/src/minigen/Main.java new file mode 100644 index 0000000..8e931c9 --- /dev/null +++ b/src/minigen/Main.java @@ -0,0 +1,84 @@ +package minigen; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PushbackReader; + +import minigen.exception.InterpreterException; +import minigen.exception.SemanticException; +import minigen.model.Model; +import minigen.syntax3.lexer.Lexer; +import minigen.syntax3.lexer.LexerException; +import minigen.syntax3.node.Node; +import minigen.syntax3.parser.Parser; +import minigen.syntax3.parser.ParserException; + +public class Main { + + public static void main(String[] args) { + + if (args.length != 1) { + System.out.println("usage:"); + System.out.println(" java miniproc.Main filename"); + return; + } + + try { + FileReader in = new FileReader(args[0]); + Lexer lexer = new Lexer(new PushbackReader(new BufferedReader(in), + 1020)); + Parser parser = new Parser(lexer); + + Node tree = parser.parse(); + + in.close(); + + // Prepare class scope + Model model = new Model(); + + // Check class declarations + tree.apply(new ClassAnalysis(model)); + + // Check formal type declarations + tree.apply(new FormalTypeAnalysis(model)); + + // Check inheritance declarations + tree.apply(new InheritanceAnalysis(model)); + + // Compute tables + new TablesComputation(model); + + // Build type check tables in all classes + model.buildAdaptations(); + + // Run interpreter + tree.apply(new Interpreter(model)); + + System.out.println("\nEXECUTION END SUCCESSFULLY"); + + } catch (IOException e) { + System.out.flush(); + System.err.println("IO ERROR: while reading " + args[0] + ": " + + e.getMessage()); + return; + } catch (LexerException e) { + System.out.flush(); + System.err.println("LEXICAL ERROR: " + e.getMessage()); + return; + } catch (ParserException e) { + System.out.flush(); + System.err.println("SYNTAX ERROR: " + e.getMessage()); + return; + } catch (SemanticException e) { + System.out.flush(); + System.err.println("SEMANTIC ERROR: " + e.getMessage()); + return; + } catch (InterpreterException e) { + System.out.flush(); + System.err.println("INTERPRETER ERROR: " + e.getMessage()); + return; + } + } + +} diff --git a/src/minigen/TablesComputation.java b/src/minigen/TablesComputation.java new file mode 100644 index 0000000..de533d1 --- /dev/null +++ b/src/minigen/TablesComputation.java @@ -0,0 +1,203 @@ +package minigen; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +import minigen.model.Class; +import minigen.model.ObjectClass; + +import minigen.model.Model; + +public class TablesComputation implements Comparator { + + private Model model; + private List globalLinearExt; + private Map> linearExts; + + private List core = new ArrayList(); + private List crown = new ArrayList(); + private List border = new ArrayList(); + + public TablesComputation(Model model) { + this.model = model; + + // Compute classes depths + computeClassDepth(ObjectClass.getInstance(), 0); + + // Compute linear extension of model + computeModelLinearExt(); + + // Compute linear ext for each class + this.linearExts = new HashMap>(); + computeClassLinearExt(ObjectClass.getInstance(), new ArrayList()); + + // Compute core, crown and border + computeCoreCrownBorder(); + + // Compute conflict graph on core classes + computeConflicts(); + } + + private void computeConflicts() { + // Sort core by linear order + Collections.sort(core, this); + + for(Class c : core) { + if(c.getSuperClasses().size() == 2) { + + HashSet d = new HashSet(); + + List linC1 = linearExts.get(c.getSuperClasses().get(0)); + List linC2 = linearExts.get(c.getSuperClasses().get(1)); + + // linC1 - linC2 + for(Class p : linC2) { + if(!linC1.contains(p)) { + d.add(p); + } + } + + // linC2 - linC1 + for(Class p : linC1) { + if(!linC2.contains(p)) { + d.add(p); + } + } + + + } + } + + } + + /* + * Compute core, crown and border classes + */ + private void computeCoreCrownBorder() { + HashSet core = new HashSet(); + HashSet crown = new HashSet(); + HashSet border = new HashSet(); + + for(Class c : model.getClasses()) { + // Check crown classes + if(c.getSuperClasses().size() == 1 && !c.getSubClasses().isEmpty()) { + boolean flag = true; + for(Class s : c.getSubClasses()) { + if(s.getSuperClasses().size() != 1) { + flag = false; + } + } + if(flag) { + crown.add(c); + } + + // Check core classes + } else if(c.getSuperClasses().size() > 1 && !c.getSubClasses().isEmpty()) { + core.add(c); + } + } + + for(Class c : core) { + boolean flag = false; + for(Class s : c.getSubClasses()) { + if(crown.contains(s)) { + flag = true; + } + } + + if(flag) { + border.add(c); + } + + } + + this.core.addAll(core); + this.crown.addAll(crown); + this.border.addAll(border); + + System.out.println("crown : " + crown); + System.out.println("core : " + core); + System.out.println("border : " + border); + + } + + /* + * Compute the linear extension of global model + */ + private void computeModelLinearExt() { + this.globalLinearExt = new ArrayList(); + this.globalLinearExt.addAll(this.model.getClasses()); + + // Sort classes by total order + Collections.sort(this.globalLinearExt, this); + + } + + /* + * Compute depth of class in global class tree + */ + private void computeClassDepth(Class toTag, int depth) { + + // Check transitive relations + if(toTag.getDepth() > depth) { + depth = toTag.getDepth(); + } + + // Tag class + toTag.setDepth(depth); + depth++; + + // Explore childs + for(Class child : toTag.getSubClasses()) { + computeClassDepth(child, depth); + } + } + + private void computeClassLinearExt(Class c, List prev) { + + // Merge parent linExt with current + HashSet currentLinExt = new HashSet(); + currentLinExt.addAll(prev); + for(Class p : c.getParents()) { + currentLinExt.add(p); + } + + // Sort by decreasing linear order and store it + List orderedLinExt = new ArrayList(); + orderedLinExt.addAll(currentLinExt); + Collections.sort(orderedLinExt, this); + this.linearExts.put(c, orderedLinExt); + + // Propagate to children + for(Class child : c.getSubClasses()) { + computeClassLinearExt(child, orderedLinExt); + } + } + + + @Override + public int compare(Class o1, Class o2) { + if( o2.isSubClassOf(o1) ) { + return -1; + } + if( o1.isSubClassOf(o2) ) { + return 1; + } + + if(o2.getDepth() - o1.getDepth() != 0) { + return o1.getDepth() - o2.getDepth(); + } + + return o1.getName().compareTo(o2.getName()); + } + + + + + +} diff --git a/src/minigen/exception/InterpreterException.java b/src/minigen/exception/InterpreterException.java new file mode 100644 index 0000000..0a4077b --- /dev/null +++ b/src/minigen/exception/InterpreterException.java @@ -0,0 +1,12 @@ +package minigen.exception; + +public class InterpreterException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public InterpreterException(String message) { + + super("[Internal Error] " + message); + } + +} diff --git a/src/minigen/exception/SemanticException.java b/src/minigen/exception/SemanticException.java new file mode 100644 index 0000000..a695091 --- /dev/null +++ b/src/minigen/exception/SemanticException.java @@ -0,0 +1,18 @@ + +package minigen.exception; + +import minigen.syntax3.node.*; + +public class SemanticException + extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public SemanticException( + Token token, + String message) { + + super("[" + token.getLine() + "," + token.getPos() + "] " + message); + } + +} diff --git a/src/minigen/model/Adaptation.java b/src/minigen/model/Adaptation.java new file mode 100644 index 0000000..75cb33e --- /dev/null +++ b/src/minigen/model/Adaptation.java @@ -0,0 +1,94 @@ +package minigen.model; + +import java.util.ArrayList; +import java.util.List; + +public class Adaptation { + + private List types; + private Class parent; + + public Adaptation(Class parent) { + this.types = new ArrayList(); + this.parent = parent; + } + + public boolean isCompatibleTo(Adaptation a) { + if(this.getTypes().size() != a.getTypes().size()) { + return false; + } + + for(int i = 0; i < this.getTypes().size(); i++) { + Class local = this.get(i).getIntro(); + Class other = a.get(i).getIntro(); + + if(!local.isSameClass(other)) { + return false; + } + } + + + return true; + } + + public void add(Type t) { + this.types.add(t); + } + + public Type get(int index) { + return types.get(index); + } + + public Type get(String name) { + for(Type t : types) { + if( t.getName().equals(name)) { + return t; + } + } + return null; + } + + public List getTypes() { + return types; + } + + public boolean contains(Type ot) { + for(Type t : types) { + if( ot.getName().equals(t.getName())) { + return true; + } + } + return false; + } + + @Override + public String toString() { + String str = this.parent.getName(); + + if(!this.types.isEmpty()) { + str += "["; + } + + int i = 0; + for(Type t : this.types) { + str += t.toString(); + + if(i < this.types.size() - 1) { + str += ", "; + } + + i++; + } + + if(!this.types.isEmpty()) { + str += "]"; + } + + return str; + } + + public boolean isFor(Class c) { + return this.parent.isSameClass(c); + } + +} diff --git a/src/minigen/model/Class.java b/src/minigen/model/Class.java new file mode 100644 index 0000000..3d6b273 --- /dev/null +++ b/src/minigen/model/Class.java @@ -0,0 +1,334 @@ +package minigen.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import minigen.exception.InterpreterException; +import minigen.exception.SemanticException; +import minigen.syntax3.node.Token; + +public class Class { + + private int classId; + private int color; + private int depth; + private String name; + private Token location; + + private Map formalTypes = new HashMap(); + + private List orderedFormalTypes = new ArrayList(); + + private Map parents = new HashMap(); + private List subClasses = new ArrayList(); + private List superClasses = new ArrayList(); + + private Map> parentsBounds = new HashMap>(); + + private Adaptation[] adaptationsTable; + + public Class(String name, Token location, int classId) { + super(); + this.classId = classId; + this.name = name; + this.location = location; + this.depth = -1; + } + + /* + * Add a parent class to the current class + */ + public void addParent(Class parent, List bounds) { + this.parents.put(parent.getName(), parent); + this.parentsBounds.put(parent, bounds); + this.superClasses.add(parent); + parent.getSubClasses().add(this); + } + + /* + * Add a formal type to the current class + */ + public void addFormalType(FormalType ftype) { + this.formalTypes.put(ftype.getName(), ftype); + this.orderedFormalTypes.add(ftype); + } + + /* + * Check if a formal type is already declared Checks are based on the formal + * type name + */ + public boolean isFormalTypeDeclared(String name) { + return formalTypes.containsKey(name); + } + + /* + * Retrieve a formal type by is name + */ + public FormalType getFormalType(String name) { + if (!this.formalTypes.containsKey(name)) { + throw new SemanticException(null, name + + "formal type not declared in type " + this.getName()); + } + return this.formalTypes.get(name); + } + + public boolean isGeneric() { + return this.orderedFormalTypes.size() != 0; + } + + /* + * Return the arity of the generic class + */ + public int getArity() { + return this.orderedFormalTypes.size(); + } + + @Override + public String toString() { + String str = this.getName(); + int i = 0; + if (orderedFormalTypes.size() > 0) { + str += '['; + for (FormalType ft : this.orderedFormalTypes) { + str += i < this.orderedFormalTypes.size() - 1 ? ft + ", " : ft; + i++; + } + str += ']'; + } + + return str; + } + + /* + * Rapid isa, constant time execution + */ + public boolean isa(Class c) { + return this.adaptationsTable[c.getClassId()] != null; + } + + /* + * Get the adaptation to specified parent + */ + public Adaptation getAdaptation(Class to) { + return this.adaptationsTable[to.getClassId()]; + } + + /* + * Register adaptation to super class + * Throw Exception if formal type conflict is found + */ + public void addAdaptation(Class to, Adaptation adaptation) { + if(to.getClassId() > this.adaptationsTable.length) { + throw new InterpreterException("Class id for class " + to + " is out of bound for table adaptation of class " + this); + } + + /*if(this.adaptationsTable[to.getClassId()] != null) { + System.out.println(to); + System.out.println(this.adaptationsTable[to.getClassId()]); + if(!adaptation.isCompatibleTo(this.adaptationsTable[to.getClassId()])) { + throw new SemanticException(location, "Formal type definition conflict detected for class " + this + " with parent " + to); + } + }*/ + this.adaptationsTable[to.getClassId()] = adaptation; + } + + /* + * Check if current class is a sub class of c Comparisons are based on + * parents names WARNING : Low efficiency, highly recursive, used only as + * bootstrap for type check. Use isa method instead. + */ + public boolean isSubClassOf(Class c) { + if (c.getName().equals("Object")) { + return true; + } + + if (this.isSameClass(c)) { + return true; + } + + for (Class parent : parents.values()) { + if (parent.isSubClassOf(c)) { + return true; + } + } + return false; + } + + /* + * Display inheritance relations of current class + */ + public String toStringWithParents() { + String str = this.getName(); + int i = 0; + if (orderedFormalTypes.size() > 0) { + str += '['; + for (FormalType ft : this.orderedFormalTypes) { + str += i < this.orderedFormalTypes.size() - 1 ? ft + ", " : ft; + i++; + } + str += ']'; + } + if (parents.size() > 0) { + str += " <: "; + int j = 0; + for (Class c : this.parents.values()) { + String classStr = c.getName(); + + // Disp bounds super relations + if (parentsBounds.get(c).size() > 0) { + classStr += "["; + int k = 0; + for (Type parent : parentsBounds.get(c)) { + classStr += k < this.parentsBounds.get(c).size() - 1 ? parent + + ", " + : parent; + k++; + } + classStr += "]"; + } + str += j < this.parents.size() - 1 ? classStr + ", " : classStr; + j++; + } + } + + return str; + } + + public String toStringWithAdaptationsTable() { + String print = "{"; + for (int i = 0; i < this.adaptationsTable.length; i++) { + print += "[" + i + "]" + " = " + this.adaptationsTable[i]; + + if(i < this.adaptationsTable.length - 1) { + print += ", "; + } + } + print += "}"; + return print; + } + + /* + * Check if current class is same class than c Comparisons are based on name + * and formal type arity + */ + public boolean isSameClass(Class c) { + return this.getName().equals(c.getName()); + } + + /* + * Is the local class introduction for Object ? + */ + public boolean isObjectIntro() { + return false; + } + + /* + * Getters, setters + */ + + public String getName() { + return name; + } + + public Token getLocation() { + return location; + } + + public Map getFormalTypes() { + return formalTypes; + } + + public Collection getParents() { + return parents.values(); + } + + public Class getParentByName(String name) { + return parents.get(name); + } + + public Map> getParentsBounds() { + return parentsBounds; + } + + public List getParentBounds(Class c) { + return parentsBounds.get(c); + } + + public int getClassId() { + return classId; + } + + public Adaptation[] getAdaptationsTable() { + return adaptationsTable; + } + + public void setAdaptationsTable(Adaptation[] adaptationsTable) { + this.adaptationsTable = adaptationsTable; + } + + public List getOrderedFormalTypes() { + return orderedFormalTypes; + } + + public List getSubClasses() { + return subClasses; + } + + public void setSubClasses(List subClasses) { + this.subClasses = subClasses; + } + + public int getDegree() { + return this.subClasses.size() + this.parents.size(); + } + + public void setClassId(int classId) { + this.classId = classId; + } + + public Collection getRelatedTo() { + + Collection result = new ArrayList(); + result.addAll(this.getParents()); + result.addAll(this.getSubClasses()); + + return result; + } + + public boolean isRelatedTo(Class c) { + for(Class p : this.getParents()) { + if(p.isSameClass(c)) { + return true; + } + } + return false; + } + + public List getSuperClasses() { + return superClasses; + } + + public int getColor() { + return color; + } + + public void setColor(int color) { + this.color = color; + } + + public void allocateAdaptationTable(int i) { + this.adaptationsTable = new Adaptation[i]; + } + + public int getDepth() { + return depth; + } + + public void setDepth(int depth) { + this.depth = depth; + } + +} diff --git a/src/minigen/model/FormalType.java b/src/minigen/model/FormalType.java new file mode 100644 index 0000000..64e7508 --- /dev/null +++ b/src/minigen/model/FormalType.java @@ -0,0 +1,28 @@ +package minigen.model; + + +public class FormalType { + + private String name; + private int position; + + public FormalType(String name, int position) { + super(); + this.name = name; + this.position = position; + } + + @Override + public String toString() { + return this.getName(); + } + + public String getName() { + return name; + } + + public int getPosition() { + return position; + } + +} diff --git a/src/minigen/model/Model.java b/src/minigen/model/Model.java new file mode 100644 index 0000000..2f17e04 --- /dev/null +++ b/src/minigen/model/Model.java @@ -0,0 +1,223 @@ +package minigen.model; + +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import minigen.exception.SemanticException; +import minigen.syntax3.node.Node; +import minigen.syntax3.node.Token; + +public class Model implements Comparator { + + private Map classesByNames; + private Map classesByNodes; + private Map colorsByClasses; + private int maxColor; + + public Model() { + this.classesByNodes = new HashMap(); + this.classesByNames = new HashMap(); + } + + /* + * For each class in model, we pre-calculate all possibles adaptations + */ + public void buildAdaptations() { + + for (Class c : this.getClasses()) { + + // Allocate table adaptation in class + c.allocateAdaptationTable(this.getClasses().size()); + + // Computation is based on classe's parents discovery + computeAdaptations(c); + + } + + } + + /* + * Compute adaptations for each class in the model + */ + public void computeAdaptations(Class c) { + + // Build adaptation for self + c.addAdaptation(c, this.getBaseAdaptation(c)); + + // Explore parents + for (Class p : c.getParents()) { + + Adaptation a = new Adaptation(p); + + // Explore generic part + if (p.isGeneric()) { + computeGenericPart(a, c.getParentsBounds().get(p)); + } + + // Add adaptation in table + c.addAdaptation(p, a); + + // Start recursion for parent exploration + computeParents(c, p, a); + + } + } + + /* + * Copy bound definition to adaptation + */ + public void computeGenericPart(Adaptation a, List bounds) { + for (Type bound : bounds) { + a.add(bound); + } + } + + /* + * Compute parents adaptation to add to child table + */ + public void computeParents(Class child, Class parent, Adaptation previous) { + + // Compute parents of parent + for (Class pp : parent.getParents()) { + + Adaptation a = new Adaptation(pp); + + // Adapt generic part (recursively) + if (pp.isGeneric()) { + + List bounds = parent.getParentBounds(pp); + + for (Type bound : bounds) { + Type adaptedBound = adaptBoundRecursively(bound, previous); + a.add(adaptedBound); + } + + } + + child.addAdaptation(pp, a); + + // Explore parents of parent (recursively) + computeParents(child, pp, a); + } + + } + + /* + * Replace current formal type by previous adaptation + */ + private Type adaptBoundRecursively(Type bound, Adaptation previous) { + if (bound.isLinkedToFormalType()) { + int pos = bound.getFormalType().getPosition(); + return previous.get(pos); + } + + if (bound.isGeneric()) { + + // build a new type definition + Type adaptedBound = new Type(bound.getName(), bound.getIntro()); + + for (Type gt : bound.getGenericTypes()) { + // Adapt generic type and replace formal types by previous + // adaptation + Type adaptedGt = adaptBoundRecursively(gt, previous); + adaptedBound.addGenericType(adaptedGt); + } + + return adaptedBound; + } + + return bound; + + } + + /* + * Compute adaptation of a class to itself + */ + public Adaptation getBaseAdaptation(Class child) { + + Adaptation a = new Adaptation(child); + + // For each bounds to this parent + if (child.isGeneric()) { + for (FormalType ft : child.getOrderedFormalTypes()) { + Type adapted = new Type(ft.getName(), child); + adapted.setFormalTypeLink(ft); + a.add(adapted); + } + } + + return a; + + } + + public boolean containsClassDeclaration(Node node) { + if (this.classesByNodes.containsKey(node)) { + return true; + } + return false; + } + + public boolean containsClassDeclaration(String name) { + if (this.classesByNames.containsKey(name)) { + return true; + } + return false; + } + + public void declareClass(Node n, Class c) { + if (containsClassDeclaration(c.getName())) { + if (c.getName().equals("Object")) { + throw new SemanticException(c.getLocation(), + "You cannot redeclare class Object"); + } + throw new SemanticException(c.getLocation(), c + + " is already declared in " + + classesByNames.get(c.getName()).getLocation().getLine() + + ":" + + classesByNames.get(c.getName()).getLocation().getPos()); + } + this.classesByNodes.put(n, c); + this.classesByNames.put(c.getName(), c); + } + + public Class getClassByNode(Token location, Node n, String name) { + if (!containsClassDeclaration(n)) { + throw new SemanticException(location, "class " + name + + " is not declared"); + } + return this.classesByNodes.get(n); + } + + public Class getClassByName(Token location, String name) { + if (!containsClassDeclaration(name)) { + throw new SemanticException(location, "class " + name + + " is not declared"); + } + return this.classesByNames.get(name); + } + + public Collection getClasses() { + return this.classesByNodes.values(); + } + + @Override + public int compare(Class arg0, Class arg1) { + return arg1.getDegree() - arg0.getDegree(); + } + + public Map getColorsByClasses() { + return colorsByClasses; + } + + public void setColorsByClasses(Map colorsByClasses) { + this.colorsByClasses = colorsByClasses; + } + + public int getMaxColor() { + return maxColor; + } + +} diff --git a/src/minigen/model/ObjectClass.java b/src/minigen/model/ObjectClass.java new file mode 100644 index 0000000..fb2ffdb --- /dev/null +++ b/src/minigen/model/ObjectClass.java @@ -0,0 +1,60 @@ +package minigen.model; + +import minigen.exception.*; + +public class ObjectClass extends Class { + + private static Class instance = null; + + private ObjectClass() { + super("Object", null, 0); + } + + public static final Class getInstance() { + if (instance == null) { + instance = new ObjectClass(); + } + return instance; + } + + @Override + public boolean isObjectIntro() { + return true; + } + + @Override + public boolean isSubClassOf(Class c) { + if(c.isObjectIntro()) { + return true; + } + return false; + } + + + @Override + public boolean isFormalTypeDeclared(String name) { + return false; + } + + @Override + public FormalType getFormalType(String name) { + throw new SemanticException(null, name + + "formal type not declared in type " + this.getName()); + } + + @Override + public int getArity() { + return 0; + } + + @Override + public String toString() { + return this.getName(); + } + + @Override + public String toStringWithParents() { + return this.toString(); + } + +} diff --git a/src/minigen/model/ObjectType.java b/src/minigen/model/ObjectType.java new file mode 100644 index 0000000..4fdf1c7 --- /dev/null +++ b/src/minigen/model/ObjectType.java @@ -0,0 +1,28 @@ +package minigen.model; + +public class ObjectType extends Type { + + private static ObjectType instance = null; + + private ObjectType() { + super("Object", ObjectClass.getInstance()); + } + + public static final ObjectType getInstance() { + if (instance == null) { + instance = new ObjectType(); + } + return instance; + } + + @Override + public boolean isGeneric() { + return false; + } + + @Override + public String toString() { + return this.getName(); + } + +} diff --git a/src/minigen/model/Type.java b/src/minigen/model/Type.java new file mode 100644 index 0000000..2e22940 --- /dev/null +++ b/src/minigen/model/Type.java @@ -0,0 +1,184 @@ +package minigen.model; + +import java.util.ArrayList; +import java.util.List; + +public class Type { + + // Type name + private String name; + + // Generic part of Type + private List genericTypes; + + // Type first introduction + private Class intro; + + private FormalType link; + + public Type(String name, Class intro) { + this.name = name; + this.intro = intro; + this.link = null; + + this.genericTypes = new ArrayList(); + } + + /* + * Is the current type a generic type ? + */ + public boolean isGeneric() { + return getArity() > 0; + } + + /* + * Is the type definition linked to a formal type ? + */ + public boolean isLinkedToFormalType() { + return link != null; + } + + /* + * Get the arity of the current type + */ + public int getArity() { + return genericTypes.size(); + } + + /* + * Formal type linked to generic type if any + */ + public FormalType getFormalType() { + return link; + } + + /* + * Check if current type isa a subtype of ot Base is used to formal type + * replacement with concrete type + */ + public boolean isa(Type ot, Type base) { + + // Check rapid subtyping using adaptation table size + if(ot.getIntro().getClassId() >= this.getIntro().getAdaptationsTable().length) { + return false; + } + + // Get adpatation for ot + Adaptation a = this.getIntro().getAdaptationsTable()[ot.getIntro().getClassId()]; + if (a == null) { + return false; + } + + // Check is expected adaptation + if(!a.isFor(ot.getIntro())) { + return false; + } + + // Replace formal type form adaptation with concrete type from type + Type toCheck = this.buildConcreteAdaptation(a, ot, base); + + for (int i = 0; i < toCheck.getGenericTypes().size(); i++) { + if (!toCheck.getGenericTypes().get(i).isa(ot.getGenericTypes().get(i),toCheck.getGenericTypes().get(i))) { + return false; + } + } + return true; + } + + /* + * Build a concrete adaptation from formal adaptation Replace each formal + * type in adaptation by concrete type provided by type to check + */ + public Type buildConcreteAdaptation(Adaptation a, Type to, Type base) { + + Type result = new Type(to.getName(), to.getIntro()); + + for (Type gt : a.getTypes()) { + + if (gt.isLinkedToFormalType()) { + int pos = gt.getFormalType().getPosition(); + Type adapted = base.getGenericTypes().get(pos); + result.addGenericType(adapted); + } else if (gt.isGeneric()) { + Type resultGt = new Type(gt.getName(), gt.getIntro()); + recursiveBuild(gt, resultGt, base); + result.addGenericType(resultGt); + } else { + result.addGenericType(gt); + } + } + + return result; + } + + /* + * Adapt generic part of new concrete adaptation recursively + */ + private void recursiveBuild(Type t, Type toAdapt, Type base) { + + for (Type gt : t.getGenericTypes()) { + if (gt.isLinkedToFormalType()) { + int pos = gt.getFormalType().getPosition(); + Type adapted = base.getGenericTypes().get(pos); + toAdapt.addGenericType(adapted); + } + if (gt.isGeneric()) { + Type resultGt = new Type(gt.getName(), gt.getIntro()); + recursiveBuild(gt, resultGt, base); + toAdapt.addGenericType(resultGt); + } + } + } + + /* + * Add a generic type to current type + */ + public void addGenericType(Type type) { + this.genericTypes.add(type); + } + + /* + * Getters, setters + */ + + @Override + public String toString() { + String str = this.getName(); + + int i = 0; + if (this.isGeneric()) { + str += "["; + for (Type type : genericTypes) { + str += type.toString(); + if (i < genericTypes.size() - 1) { + str += ", "; + } + i++; + } + str += "]"; + } + + if (this.isLinkedToFormalType()) { + str += "*"; + } + + return str; + } + + public String getName() { + return name; + } + + public List getGenericTypes() { + return genericTypes; + } + + public Class getIntro() { + return intro; + } + + public void setFormalTypeLink(FormalType link) { + this.link = link; + } + +} diff --git a/src/minigen/syntax3/analysis/Analysis.java b/src/minigen/syntax3/analysis/Analysis.java new file mode 100644 index 0000000..20c0499 --- /dev/null +++ b/src/minigen/syntax3/analysis/Analysis.java @@ -0,0 +1,44 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.analysis; + +import minigen.syntax3.node.*; + +public interface Analysis extends Switch +{ + Object getIn(Node node); + void setIn(Node node, Object o); + Object getOut(Node node); + void setOut(Node node, Object o); + + void caseStart(Start node); + void caseAProgram(AProgram node); + void caseAClassDecl(AClassDecl node); + void caseAFormalDecls(AFormalDecls node); + void caseAFormalDecl(AFormalDecl node); + void caseAAdditionalFormalTypes(AAdditionalFormalTypes node); + void caseAType(AType node); + void caseAGenericPart(AGenericPart node); + void caseAGenericTypes(AGenericTypes node); + void caseAAdditionalTypes(AAdditionalTypes node); + void caseASuperDecls(ASuperDecls node); + void caseAAdditionalSupers(AAdditionalSupers node); + void caseASuperType(ASuperType node); + void caseASuperGenericPart(ASuperGenericPart node); + void caseASuperGenericTypes(ASuperGenericTypes node); + void caseASuperAdditionalTypes(ASuperAdditionalTypes node); + void caseAIsaInstr(AIsaInstr node); + + void caseTComma(TComma node); + void caseTLb(TLb node); + void caseTRb(TRb node); + void caseTKend(TKend node); + void caseTKisa(TKisa node); + void caseTKclass(TKclass node); + void caseTKsuper(TKsuper node); + void caseTKnew(TKnew node); + void caseTName(TName node); + void caseTBlanks(TBlanks node); + void caseTComment(TComment node); + void caseEOF(EOF node); +} diff --git a/src/minigen/syntax3/analysis/AnalysisAdapter.java b/src/minigen/syntax3/analysis/AnalysisAdapter.java new file mode 100644 index 0000000..546e00b --- /dev/null +++ b/src/minigen/syntax3/analysis/AnalysisAdapter.java @@ -0,0 +1,216 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.analysis; + +import java.util.*; +import minigen.syntax3.node.*; + +public class AnalysisAdapter implements Analysis +{ + private Hashtable in; + private Hashtable out; + + public Object getIn(Node node) + { + if(this.in == null) + { + return null; + } + + return this.in.get(node); + } + + public void setIn(Node node, Object o) + { + if(this.in == null) + { + this.in = new Hashtable(1); + } + + if(o != null) + { + this.in.put(node, o); + } + else + { + this.in.remove(node); + } + } + + public Object getOut(Node node) + { + if(this.out == null) + { + return null; + } + + return this.out.get(node); + } + + public void setOut(Node node, Object o) + { + if(this.out == null) + { + this.out = new Hashtable(1); + } + + if(o != null) + { + this.out.put(node, o); + } + else + { + this.out.remove(node); + } + } + + public void caseStart(Start node) + { + defaultCase(node); + } + + public void caseAProgram(AProgram node) + { + defaultCase(node); + } + + public void caseAClassDecl(AClassDecl node) + { + defaultCase(node); + } + + public void caseAFormalDecls(AFormalDecls node) + { + defaultCase(node); + } + + public void caseAFormalDecl(AFormalDecl node) + { + defaultCase(node); + } + + public void caseAAdditionalFormalTypes(AAdditionalFormalTypes node) + { + defaultCase(node); + } + + public void caseAType(AType node) + { + defaultCase(node); + } + + public void caseAGenericPart(AGenericPart node) + { + defaultCase(node); + } + + public void caseAGenericTypes(AGenericTypes node) + { + defaultCase(node); + } + + public void caseAAdditionalTypes(AAdditionalTypes node) + { + defaultCase(node); + } + + public void caseASuperDecls(ASuperDecls node) + { + defaultCase(node); + } + + public void caseAAdditionalSupers(AAdditionalSupers node) + { + defaultCase(node); + } + + public void caseASuperType(ASuperType node) + { + defaultCase(node); + } + + public void caseASuperGenericPart(ASuperGenericPart node) + { + defaultCase(node); + } + + public void caseASuperGenericTypes(ASuperGenericTypes node) + { + defaultCase(node); + } + + public void caseASuperAdditionalTypes(ASuperAdditionalTypes node) + { + defaultCase(node); + } + + public void caseAIsaInstr(AIsaInstr node) + { + defaultCase(node); + } + + public void caseTComma(TComma node) + { + defaultCase(node); + } + + public void caseTLb(TLb node) + { + defaultCase(node); + } + + public void caseTRb(TRb node) + { + defaultCase(node); + } + + public void caseTKend(TKend node) + { + defaultCase(node); + } + + public void caseTKisa(TKisa node) + { + defaultCase(node); + } + + public void caseTKclass(TKclass node) + { + defaultCase(node); + } + + public void caseTKsuper(TKsuper node) + { + defaultCase(node); + } + + public void caseTKnew(TKnew node) + { + defaultCase(node); + } + + public void caseTName(TName node) + { + defaultCase(node); + } + + public void caseTBlanks(TBlanks node) + { + defaultCase(node); + } + + public void caseTComment(TComment node) + { + defaultCase(node); + } + + public void caseEOF(EOF node) + { + defaultCase(node); + } + + public void defaultCase(@SuppressWarnings("unused") Node node) + { + // do nothing + } +} diff --git a/src/minigen/syntax3/analysis/DepthFirstAdapter.java b/src/minigen/syntax3/analysis/DepthFirstAdapter.java new file mode 100644 index 0000000..baaf384 --- /dev/null +++ b/src/minigen/syntax3/analysis/DepthFirstAdapter.java @@ -0,0 +1,491 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.analysis; + +import java.util.*; +import minigen.syntax3.node.*; + +public class DepthFirstAdapter extends AnalysisAdapter +{ + public void inStart(Start node) + { + defaultIn(node); + } + + public void outStart(Start node) + { + defaultOut(node); + } + + public void defaultIn(@SuppressWarnings("unused") Node node) + { + // Do nothing + } + + public void defaultOut(@SuppressWarnings("unused") Node node) + { + // Do nothing + } + + @Override + public void caseStart(Start node) + { + inStart(node); + node.getPProgram().apply(this); + node.getEOF().apply(this); + outStart(node); + } + + public void inAProgram(AProgram node) + { + defaultIn(node); + } + + public void outAProgram(AProgram node) + { + defaultOut(node); + } + + @Override + public void caseAProgram(AProgram node) + { + inAProgram(node); + { + List copy = new ArrayList(node.getClasses()); + for(PClassDecl e : copy) + { + e.apply(this); + } + } + { + List copy = new ArrayList(node.getInstrs()); + for(PInstr e : copy) + { + e.apply(this); + } + } + outAProgram(node); + } + + public void inAClassDecl(AClassDecl node) + { + defaultIn(node); + } + + public void outAClassDecl(AClassDecl node) + { + defaultOut(node); + } + + @Override + public void caseAClassDecl(AClassDecl node) + { + inAClassDecl(node); + if(node.getKclass() != null) + { + node.getKclass().apply(this); + } + if(node.getName() != null) + { + node.getName().apply(this); + } + if(node.getFormalDecls() != null) + { + node.getFormalDecls().apply(this); + } + if(node.getSuperDecls() != null) + { + node.getSuperDecls().apply(this); + } + if(node.getKend() != null) + { + node.getKend().apply(this); + } + outAClassDecl(node); + } + + public void inAFormalDecls(AFormalDecls node) + { + defaultIn(node); + } + + public void outAFormalDecls(AFormalDecls node) + { + defaultOut(node); + } + + @Override + public void caseAFormalDecls(AFormalDecls node) + { + inAFormalDecls(node); + if(node.getLb() != null) + { + node.getLb().apply(this); + } + { + List copy = new ArrayList(node.getFormalDecl()); + for(PFormalDecl e : copy) + { + e.apply(this); + } + } + if(node.getRb() != null) + { + node.getRb().apply(this); + } + outAFormalDecls(node); + } + + public void inAFormalDecl(AFormalDecl node) + { + defaultIn(node); + } + + public void outAFormalDecl(AFormalDecl node) + { + defaultOut(node); + } + + @Override + public void caseAFormalDecl(AFormalDecl node) + { + inAFormalDecl(node); + if(node.getName() != null) + { + node.getName().apply(this); + } + { + List copy = new ArrayList(node.getAdditionalFormalTypes()); + for(PAdditionalFormalTypes e : copy) + { + e.apply(this); + } + } + outAFormalDecl(node); + } + + public void inAAdditionalFormalTypes(AAdditionalFormalTypes node) + { + defaultIn(node); + } + + public void outAAdditionalFormalTypes(AAdditionalFormalTypes node) + { + defaultOut(node); + } + + @Override + public void caseAAdditionalFormalTypes(AAdditionalFormalTypes node) + { + inAAdditionalFormalTypes(node); + if(node.getComma() != null) + { + node.getComma().apply(this); + } + if(node.getName() != null) + { + node.getName().apply(this); + } + outAAdditionalFormalTypes(node); + } + + public void inAType(AType node) + { + defaultIn(node); + } + + public void outAType(AType node) + { + defaultOut(node); + } + + @Override + public void caseAType(AType node) + { + inAType(node); + if(node.getName() != null) + { + node.getName().apply(this); + } + if(node.getGenericPart() != null) + { + node.getGenericPart().apply(this); + } + outAType(node); + } + + public void inAGenericPart(AGenericPart node) + { + defaultIn(node); + } + + public void outAGenericPart(AGenericPart node) + { + defaultOut(node); + } + + @Override + public void caseAGenericPart(AGenericPart node) + { + inAGenericPart(node); + if(node.getLb() != null) + { + node.getLb().apply(this); + } + if(node.getGenericTypes() != null) + { + node.getGenericTypes().apply(this); + } + if(node.getRb() != null) + { + node.getRb().apply(this); + } + outAGenericPart(node); + } + + public void inAGenericTypes(AGenericTypes node) + { + defaultIn(node); + } + + public void outAGenericTypes(AGenericTypes node) + { + defaultOut(node); + } + + @Override + public void caseAGenericTypes(AGenericTypes node) + { + inAGenericTypes(node); + if(node.getType() != null) + { + node.getType().apply(this); + } + { + List copy = new ArrayList(node.getAdditionalTypes()); + for(PAdditionalTypes e : copy) + { + e.apply(this); + } + } + outAGenericTypes(node); + } + + public void inAAdditionalTypes(AAdditionalTypes node) + { + defaultIn(node); + } + + public void outAAdditionalTypes(AAdditionalTypes node) + { + defaultOut(node); + } + + @Override + public void caseAAdditionalTypes(AAdditionalTypes node) + { + inAAdditionalTypes(node); + if(node.getComma() != null) + { + node.getComma().apply(this); + } + if(node.getType() != null) + { + node.getType().apply(this); + } + outAAdditionalTypes(node); + } + + public void inASuperDecls(ASuperDecls node) + { + defaultIn(node); + } + + public void outASuperDecls(ASuperDecls node) + { + defaultOut(node); + } + + @Override + public void caseASuperDecls(ASuperDecls node) + { + inASuperDecls(node); + if(node.getKsuper() != null) + { + node.getKsuper().apply(this); + } + if(node.getSuperType() != null) + { + node.getSuperType().apply(this); + } + { + List copy = new ArrayList(node.getAdditionalSupers()); + for(PAdditionalSupers e : copy) + { + e.apply(this); + } + } + outASuperDecls(node); + } + + public void inAAdditionalSupers(AAdditionalSupers node) + { + defaultIn(node); + } + + public void outAAdditionalSupers(AAdditionalSupers node) + { + defaultOut(node); + } + + @Override + public void caseAAdditionalSupers(AAdditionalSupers node) + { + inAAdditionalSupers(node); + if(node.getComma() != null) + { + node.getComma().apply(this); + } + if(node.getSuperType() != null) + { + node.getSuperType().apply(this); + } + outAAdditionalSupers(node); + } + + public void inASuperType(ASuperType node) + { + defaultIn(node); + } + + public void outASuperType(ASuperType node) + { + defaultOut(node); + } + + @Override + public void caseASuperType(ASuperType node) + { + inASuperType(node); + if(node.getName() != null) + { + node.getName().apply(this); + } + if(node.getSuperGenericPart() != null) + { + node.getSuperGenericPart().apply(this); + } + outASuperType(node); + } + + public void inASuperGenericPart(ASuperGenericPart node) + { + defaultIn(node); + } + + public void outASuperGenericPart(ASuperGenericPart node) + { + defaultOut(node); + } + + @Override + public void caseASuperGenericPart(ASuperGenericPart node) + { + inASuperGenericPart(node); + if(node.getLb() != null) + { + node.getLb().apply(this); + } + if(node.getSuperGenericTypes() != null) + { + node.getSuperGenericTypes().apply(this); + } + if(node.getRb() != null) + { + node.getRb().apply(this); + } + outASuperGenericPart(node); + } + + public void inASuperGenericTypes(ASuperGenericTypes node) + { + defaultIn(node); + } + + public void outASuperGenericTypes(ASuperGenericTypes node) + { + defaultOut(node); + } + + @Override + public void caseASuperGenericTypes(ASuperGenericTypes node) + { + inASuperGenericTypes(node); + if(node.getSuperType() != null) + { + node.getSuperType().apply(this); + } + { + List copy = new ArrayList(node.getSuperAdditionalTypes()); + for(PSuperAdditionalTypes e : copy) + { + e.apply(this); + } + } + outASuperGenericTypes(node); + } + + public void inASuperAdditionalTypes(ASuperAdditionalTypes node) + { + defaultIn(node); + } + + public void outASuperAdditionalTypes(ASuperAdditionalTypes node) + { + defaultOut(node); + } + + @Override + public void caseASuperAdditionalTypes(ASuperAdditionalTypes node) + { + inASuperAdditionalTypes(node); + if(node.getComma() != null) + { + node.getComma().apply(this); + } + if(node.getSuperType() != null) + { + node.getSuperType().apply(this); + } + outASuperAdditionalTypes(node); + } + + public void inAIsaInstr(AIsaInstr node) + { + defaultIn(node); + } + + public void outAIsaInstr(AIsaInstr node) + { + defaultOut(node); + } + + @Override + public void caseAIsaInstr(AIsaInstr node) + { + inAIsaInstr(node); + if(node.getLeft() != null) + { + node.getLeft().apply(this); + } + if(node.getKisa() != null) + { + node.getKisa().apply(this); + } + if(node.getRight() != null) + { + node.getRight().apply(this); + } + outAIsaInstr(node); + } +} diff --git a/src/minigen/syntax3/analysis/ReversedDepthFirstAdapter.java b/src/minigen/syntax3/analysis/ReversedDepthFirstAdapter.java new file mode 100644 index 0000000..9b28dc5 --- /dev/null +++ b/src/minigen/syntax3/analysis/ReversedDepthFirstAdapter.java @@ -0,0 +1,498 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.analysis; + +import java.util.*; +import minigen.syntax3.node.*; + +public class ReversedDepthFirstAdapter extends AnalysisAdapter +{ + public void inStart(Start node) + { + defaultIn(node); + } + + public void outStart(Start node) + { + defaultOut(node); + } + + public void defaultIn(@SuppressWarnings("unused") Node node) + { + // Do nothing + } + + public void defaultOut(@SuppressWarnings("unused") Node node) + { + // Do nothing + } + + @Override + public void caseStart(Start node) + { + inStart(node); + node.getEOF().apply(this); + node.getPProgram().apply(this); + outStart(node); + } + + public void inAProgram(AProgram node) + { + defaultIn(node); + } + + public void outAProgram(AProgram node) + { + defaultOut(node); + } + + @Override + public void caseAProgram(AProgram node) + { + inAProgram(node); + { + List copy = new ArrayList(node.getInstrs()); + Collections.reverse(copy); + for(PInstr e : copy) + { + e.apply(this); + } + } + { + List copy = new ArrayList(node.getClasses()); + Collections.reverse(copy); + for(PClassDecl e : copy) + { + e.apply(this); + } + } + outAProgram(node); + } + + public void inAClassDecl(AClassDecl node) + { + defaultIn(node); + } + + public void outAClassDecl(AClassDecl node) + { + defaultOut(node); + } + + @Override + public void caseAClassDecl(AClassDecl node) + { + inAClassDecl(node); + if(node.getKend() != null) + { + node.getKend().apply(this); + } + if(node.getSuperDecls() != null) + { + node.getSuperDecls().apply(this); + } + if(node.getFormalDecls() != null) + { + node.getFormalDecls().apply(this); + } + if(node.getName() != null) + { + node.getName().apply(this); + } + if(node.getKclass() != null) + { + node.getKclass().apply(this); + } + outAClassDecl(node); + } + + public void inAFormalDecls(AFormalDecls node) + { + defaultIn(node); + } + + public void outAFormalDecls(AFormalDecls node) + { + defaultOut(node); + } + + @Override + public void caseAFormalDecls(AFormalDecls node) + { + inAFormalDecls(node); + if(node.getRb() != null) + { + node.getRb().apply(this); + } + { + List copy = new ArrayList(node.getFormalDecl()); + Collections.reverse(copy); + for(PFormalDecl e : copy) + { + e.apply(this); + } + } + if(node.getLb() != null) + { + node.getLb().apply(this); + } + outAFormalDecls(node); + } + + public void inAFormalDecl(AFormalDecl node) + { + defaultIn(node); + } + + public void outAFormalDecl(AFormalDecl node) + { + defaultOut(node); + } + + @Override + public void caseAFormalDecl(AFormalDecl node) + { + inAFormalDecl(node); + { + List copy = new ArrayList(node.getAdditionalFormalTypes()); + Collections.reverse(copy); + for(PAdditionalFormalTypes e : copy) + { + e.apply(this); + } + } + if(node.getName() != null) + { + node.getName().apply(this); + } + outAFormalDecl(node); + } + + public void inAAdditionalFormalTypes(AAdditionalFormalTypes node) + { + defaultIn(node); + } + + public void outAAdditionalFormalTypes(AAdditionalFormalTypes node) + { + defaultOut(node); + } + + @Override + public void caseAAdditionalFormalTypes(AAdditionalFormalTypes node) + { + inAAdditionalFormalTypes(node); + if(node.getName() != null) + { + node.getName().apply(this); + } + if(node.getComma() != null) + { + node.getComma().apply(this); + } + outAAdditionalFormalTypes(node); + } + + public void inAType(AType node) + { + defaultIn(node); + } + + public void outAType(AType node) + { + defaultOut(node); + } + + @Override + public void caseAType(AType node) + { + inAType(node); + if(node.getGenericPart() != null) + { + node.getGenericPart().apply(this); + } + if(node.getName() != null) + { + node.getName().apply(this); + } + outAType(node); + } + + public void inAGenericPart(AGenericPart node) + { + defaultIn(node); + } + + public void outAGenericPart(AGenericPart node) + { + defaultOut(node); + } + + @Override + public void caseAGenericPart(AGenericPart node) + { + inAGenericPart(node); + if(node.getRb() != null) + { + node.getRb().apply(this); + } + if(node.getGenericTypes() != null) + { + node.getGenericTypes().apply(this); + } + if(node.getLb() != null) + { + node.getLb().apply(this); + } + outAGenericPart(node); + } + + public void inAGenericTypes(AGenericTypes node) + { + defaultIn(node); + } + + public void outAGenericTypes(AGenericTypes node) + { + defaultOut(node); + } + + @Override + public void caseAGenericTypes(AGenericTypes node) + { + inAGenericTypes(node); + { + List copy = new ArrayList(node.getAdditionalTypes()); + Collections.reverse(copy); + for(PAdditionalTypes e : copy) + { + e.apply(this); + } + } + if(node.getType() != null) + { + node.getType().apply(this); + } + outAGenericTypes(node); + } + + public void inAAdditionalTypes(AAdditionalTypes node) + { + defaultIn(node); + } + + public void outAAdditionalTypes(AAdditionalTypes node) + { + defaultOut(node); + } + + @Override + public void caseAAdditionalTypes(AAdditionalTypes node) + { + inAAdditionalTypes(node); + if(node.getType() != null) + { + node.getType().apply(this); + } + if(node.getComma() != null) + { + node.getComma().apply(this); + } + outAAdditionalTypes(node); + } + + public void inASuperDecls(ASuperDecls node) + { + defaultIn(node); + } + + public void outASuperDecls(ASuperDecls node) + { + defaultOut(node); + } + + @Override + public void caseASuperDecls(ASuperDecls node) + { + inASuperDecls(node); + { + List copy = new ArrayList(node.getAdditionalSupers()); + Collections.reverse(copy); + for(PAdditionalSupers e : copy) + { + e.apply(this); + } + } + if(node.getSuperType() != null) + { + node.getSuperType().apply(this); + } + if(node.getKsuper() != null) + { + node.getKsuper().apply(this); + } + outASuperDecls(node); + } + + public void inAAdditionalSupers(AAdditionalSupers node) + { + defaultIn(node); + } + + public void outAAdditionalSupers(AAdditionalSupers node) + { + defaultOut(node); + } + + @Override + public void caseAAdditionalSupers(AAdditionalSupers node) + { + inAAdditionalSupers(node); + if(node.getSuperType() != null) + { + node.getSuperType().apply(this); + } + if(node.getComma() != null) + { + node.getComma().apply(this); + } + outAAdditionalSupers(node); + } + + public void inASuperType(ASuperType node) + { + defaultIn(node); + } + + public void outASuperType(ASuperType node) + { + defaultOut(node); + } + + @Override + public void caseASuperType(ASuperType node) + { + inASuperType(node); + if(node.getSuperGenericPart() != null) + { + node.getSuperGenericPart().apply(this); + } + if(node.getName() != null) + { + node.getName().apply(this); + } + outASuperType(node); + } + + public void inASuperGenericPart(ASuperGenericPart node) + { + defaultIn(node); + } + + public void outASuperGenericPart(ASuperGenericPart node) + { + defaultOut(node); + } + + @Override + public void caseASuperGenericPart(ASuperGenericPart node) + { + inASuperGenericPart(node); + if(node.getRb() != null) + { + node.getRb().apply(this); + } + if(node.getSuperGenericTypes() != null) + { + node.getSuperGenericTypes().apply(this); + } + if(node.getLb() != null) + { + node.getLb().apply(this); + } + outASuperGenericPart(node); + } + + public void inASuperGenericTypes(ASuperGenericTypes node) + { + defaultIn(node); + } + + public void outASuperGenericTypes(ASuperGenericTypes node) + { + defaultOut(node); + } + + @Override + public void caseASuperGenericTypes(ASuperGenericTypes node) + { + inASuperGenericTypes(node); + { + List copy = new ArrayList(node.getSuperAdditionalTypes()); + Collections.reverse(copy); + for(PSuperAdditionalTypes e : copy) + { + e.apply(this); + } + } + if(node.getSuperType() != null) + { + node.getSuperType().apply(this); + } + outASuperGenericTypes(node); + } + + public void inASuperAdditionalTypes(ASuperAdditionalTypes node) + { + defaultIn(node); + } + + public void outASuperAdditionalTypes(ASuperAdditionalTypes node) + { + defaultOut(node); + } + + @Override + public void caseASuperAdditionalTypes(ASuperAdditionalTypes node) + { + inASuperAdditionalTypes(node); + if(node.getSuperType() != null) + { + node.getSuperType().apply(this); + } + if(node.getComma() != null) + { + node.getComma().apply(this); + } + outASuperAdditionalTypes(node); + } + + public void inAIsaInstr(AIsaInstr node) + { + defaultIn(node); + } + + public void outAIsaInstr(AIsaInstr node) + { + defaultOut(node); + } + + @Override + public void caseAIsaInstr(AIsaInstr node) + { + inAIsaInstr(node); + if(node.getRight() != null) + { + node.getRight().apply(this); + } + if(node.getKisa() != null) + { + node.getKisa().apply(this); + } + if(node.getLeft() != null) + { + node.getLeft().apply(this); + } + outAIsaInstr(node); + } +} diff --git a/src/minigen/syntax3/lexer/Lexer.java b/src/minigen/syntax3/lexer/Lexer.java new file mode 100644 index 0000000..6d783cc --- /dev/null +++ b/src/minigen/syntax3/lexer/Lexer.java @@ -0,0 +1,470 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.lexer; + +import java.io.*; +import minigen.syntax3.node.*; + +@SuppressWarnings("nls") +public class Lexer +{ + protected Token token; + protected State state = State.INITIAL; + + private PushbackReader in; + private int line; + private int pos; + private boolean cr; + private boolean eof; + private final StringBuffer text = new StringBuffer(); + + @SuppressWarnings("unused") + protected void filter() throws LexerException, IOException + { + // Do nothing + } + + public Lexer(@SuppressWarnings("hiding") PushbackReader in) + { + this.in = in; + } + + public Token peek() throws LexerException, IOException + { + while(this.token == null) + { + this.token = getToken(); + filter(); + } + + return this.token; + } + + public Token next() throws LexerException, IOException + { + while(this.token == null) + { + this.token = getToken(); + filter(); + } + + Token result = this.token; + this.token = null; + return result; + } + + protected Token getToken() throws IOException, LexerException + { + int dfa_state = 0; + + int start_pos = this.pos; + int start_line = this.line; + + int accept_state = -1; + int accept_token = -1; + int accept_length = -1; + int accept_pos = -1; + int accept_line = -1; + + @SuppressWarnings("hiding") int[][][] gotoTable = Lexer.gotoTable[this.state.id()]; + @SuppressWarnings("hiding") int[] accept = Lexer.accept[this.state.id()]; + this.text.setLength(0); + + while(true) + { + int c = getChar(); + + if(c != -1) + { + switch(c) + { + case 10: + if(this.cr) + { + this.cr = false; + } + else + { + this.line++; + this.pos = 0; + } + break; + case 13: + this.line++; + this.pos = 0; + this.cr = true; + break; + default: + this.pos++; + this.cr = false; + break; + } + + this.text.append((char) c); + + do + { + int oldState = (dfa_state < -1) ? (-2 -dfa_state) : dfa_state; + + dfa_state = -1; + + int[][] tmp1 = gotoTable[oldState]; + int low = 0; + int high = tmp1.length - 1; + + while(low <= high) + { + int middle = (low + high) / 2; + int[] tmp2 = tmp1[middle]; + + if(c < tmp2[0]) + { + high = middle - 1; + } + else if(c > tmp2[1]) + { + low = middle + 1; + } + else + { + dfa_state = tmp2[2]; + break; + } + } + }while(dfa_state < -1); + } + else + { + dfa_state = -1; + } + + if(dfa_state >= 0) + { + if(accept[dfa_state] != -1) + { + accept_state = dfa_state; + accept_token = accept[dfa_state]; + accept_length = this.text.length(); + accept_pos = this.pos; + accept_line = this.line; + } + } + else + { + if(accept_state != -1) + { + switch(accept_token) + { + case 0: + { + @SuppressWarnings("hiding") Token token = new0( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 1: + { + @SuppressWarnings("hiding") Token token = new1( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 2: + { + @SuppressWarnings("hiding") Token token = new2( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 3: + { + @SuppressWarnings("hiding") Token token = new3( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 4: + { + @SuppressWarnings("hiding") Token token = new4( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 5: + { + @SuppressWarnings("hiding") Token token = new5( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 6: + { + @SuppressWarnings("hiding") Token token = new6( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 7: + { + @SuppressWarnings("hiding") Token token = new7( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 8: + { + @SuppressWarnings("hiding") Token token = new8( + getText(accept_length), + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 9: + { + @SuppressWarnings("hiding") Token token = new9( + getText(accept_length), + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 10: + { + @SuppressWarnings("hiding") Token token = new10( + getText(accept_length), + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + } + } + else + { + if(this.text.length() > 0) + { + throw new LexerException( + "[" + (start_line + 1) + "," + (start_pos + 1) + "]" + + " Unknown token: " + this.text); + } + + @SuppressWarnings("hiding") EOF token = new EOF( + start_line + 1, + start_pos + 1); + return token; + } + } + } + } + + Token new0(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TComma(line, pos); } + Token new1(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLb(line, pos); } + Token new2(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TRb(line, pos); } + Token new3(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKend(line, pos); } + Token new4(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKisa(line, pos); } + Token new5(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKclass(line, pos); } + Token new6(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKsuper(line, pos); } + Token new7(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKnew(line, pos); } + Token new8(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TName(text, line, pos); } + Token new9(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TBlanks(text, line, pos); } + Token new10(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TComment(text, line, pos); } + + private int getChar() throws IOException + { + if(this.eof) + { + return -1; + } + + int result = this.in.read(); + + if(result == -1) + { + this.eof = true; + } + + return result; + } + + private void pushBack(int acceptLength) throws IOException + { + int length = this.text.length(); + for(int i = length - 1; i >= acceptLength; i--) + { + this.eof = false; + + this.in.unread(this.text.charAt(i)); + } + } + + protected void unread(@SuppressWarnings("hiding") Token token) throws IOException + { + @SuppressWarnings("hiding") String text = token.getText(); + int length = text.length(); + + for(int i = length - 1; i >= 0; i--) + { + this.eof = false; + + this.in.unread(text.charAt(i)); + } + + this.pos = token.getPos() - 1; + this.line = token.getLine() - 1; + } + + private String getText(int acceptLength) + { + StringBuffer s = new StringBuffer(acceptLength); + for(int i = 0; i < acceptLength; i++) + { + s.append(this.text.charAt(i)); + } + + return s.toString(); + } + + private static int[][][][] gotoTable; +/* { + { // INITIAL + {{9, 9, 1}, {10, 10, 2}, {13, 13, 3}, {32, 32, 4}, {35, 35, 5}, {44, 44, 6}, {65, 90, 7}, {91, 91, 8}, {93, 93, 9}, {99, 99, 10}, {101, 101, 11}, {105, 105, 12}, {110, 110, 13}, {115, 115, 14}, }, + {{9, 32, -2}, }, + {{9, 32, -2}, }, + {{9, 9, 1}, {10, 10, 15}, {13, 32, -2}, }, + {{9, 32, -2}, }, + {{0, 9, 16}, {11, 12, 16}, {14, 127, 16}, }, + {}, + {{48, 57, 17}, {65, 90, 18}, {97, 122, 18}, }, + {}, + {}, + {{108, 108, 19}, }, + {{110, 110, 20}, }, + {{115, 115, 21}, }, + {{101, 101, 22}, }, + {{117, 117, 23}, }, + {{9, 32, -2}, }, + {{0, 127, -7}, }, + {{48, 122, -9}, }, + {{48, 122, -9}, }, + {{97, 97, 24}, }, + {{100, 100, 25}, }, + {{97, 97, 26}, }, + {{119, 119, 27}, }, + {{112, 112, 28}, }, + {{115, 115, 29}, }, + {}, + {}, + {}, + {{101, 101, 30}, }, + {{115, 115, 31}, }, + {{114, 114, 32}, }, + {}, + {}, + } + };*/ + + private static int[][] accept; +/* { + // INITIAL + {-1, 9, 9, 9, 9, 10, 0, 8, 1, 2, -1, -1, -1, -1, -1, 9, 10, 8, 8, -1, -1, -1, -1, -1, -1, 3, 4, 7, -1, -1, -1, 5, 6, }, + + };*/ + + public static class State + { + public final static State INITIAL = new State(0); + + private int id; + + private State(@SuppressWarnings("hiding") int id) + { + this.id = id; + } + + public int id() + { + return this.id; + } + } + + static + { + try + { + DataInputStream s = new DataInputStream( + new BufferedInputStream( + Lexer.class.getResourceAsStream("lexer.dat"))); + + // read gotoTable + int length = s.readInt(); + gotoTable = new int[length][][][]; + for(int i = 0; i < gotoTable.length; i++) + { + length = s.readInt(); + gotoTable[i] = new int[length][][]; + for(int j = 0; j < gotoTable[i].length; j++) + { + length = s.readInt(); + gotoTable[i][j] = new int[length][3]; + for(int k = 0; k < gotoTable[i][j].length; k++) + { + for(int l = 0; l < 3; l++) + { + gotoTable[i][j][k][l] = s.readInt(); + } + } + } + } + + // read accept + length = s.readInt(); + accept = new int[length][]; + for(int i = 0; i < accept.length; i++) + { + length = s.readInt(); + accept[i] = new int[length]; + for(int j = 0; j < accept[i].length; j++) + { + accept[i][j] = s.readInt(); + } + } + + s.close(); + } + catch(Exception e) + { + throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted."); + } + } +} diff --git a/src/minigen/syntax3/lexer/LexerException.java b/src/minigen/syntax3/lexer/LexerException.java new file mode 100644 index 0000000..8d2428a --- /dev/null +++ b/src/minigen/syntax3/lexer/LexerException.java @@ -0,0 +1,12 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.lexer; + +@SuppressWarnings("serial") +public class LexerException extends Exception +{ + public LexerException(String message) + { + super(message); + } +} diff --git a/src/minigen/syntax3/lexer/lexer.dat b/src/minigen/syntax3/lexer/lexer.dat new file mode 100644 index 0000000..da18cf6 Binary files /dev/null and b/src/minigen/syntax3/lexer/lexer.dat differ diff --git a/src/minigen/syntax3/node/AAdditionalFormalTypes.java b/src/minigen/syntax3/node/AAdditionalFormalTypes.java new file mode 100644 index 0000000..8e1de55 --- /dev/null +++ b/src/minigen/syntax3/node/AAdditionalFormalTypes.java @@ -0,0 +1,137 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AAdditionalFormalTypes extends PAdditionalFormalTypes +{ + private TComma _comma_; + private TName _name_; + + public AAdditionalFormalTypes() + { + // Constructor + } + + public AAdditionalFormalTypes( + @SuppressWarnings("hiding") TComma _comma_, + @SuppressWarnings("hiding") TName _name_) + { + // Constructor + setComma(_comma_); + + setName(_name_); + + } + + @Override + public Object clone() + { + return new AAdditionalFormalTypes( + cloneNode(this._comma_), + cloneNode(this._name_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAAdditionalFormalTypes(this); + } + + public TComma getComma() + { + return this._comma_; + } + + public void setComma(TComma node) + { + if(this._comma_ != null) + { + this._comma_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._comma_ = node; + } + + public TName getName() + { + return this._name_; + } + + public void setName(TName node) + { + if(this._name_ != null) + { + this._name_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._name_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._comma_) + + toString(this._name_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._comma_ == child) + { + this._comma_ = null; + return; + } + + if(this._name_ == child) + { + this._name_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._comma_ == oldChild) + { + setComma((TComma) newChild); + return; + } + + if(this._name_ == oldChild) + { + setName((TName) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/AAdditionalSupers.java b/src/minigen/syntax3/node/AAdditionalSupers.java new file mode 100644 index 0000000..8e9a9e0 --- /dev/null +++ b/src/minigen/syntax3/node/AAdditionalSupers.java @@ -0,0 +1,137 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AAdditionalSupers extends PAdditionalSupers +{ + private TComma _comma_; + private PSuperType _superType_; + + public AAdditionalSupers() + { + // Constructor + } + + public AAdditionalSupers( + @SuppressWarnings("hiding") TComma _comma_, + @SuppressWarnings("hiding") PSuperType _superType_) + { + // Constructor + setComma(_comma_); + + setSuperType(_superType_); + + } + + @Override + public Object clone() + { + return new AAdditionalSupers( + cloneNode(this._comma_), + cloneNode(this._superType_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAAdditionalSupers(this); + } + + public TComma getComma() + { + return this._comma_; + } + + public void setComma(TComma node) + { + if(this._comma_ != null) + { + this._comma_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._comma_ = node; + } + + public PSuperType getSuperType() + { + return this._superType_; + } + + public void setSuperType(PSuperType node) + { + if(this._superType_ != null) + { + this._superType_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._superType_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._comma_) + + toString(this._superType_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._comma_ == child) + { + this._comma_ = null; + return; + } + + if(this._superType_ == child) + { + this._superType_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._comma_ == oldChild) + { + setComma((TComma) newChild); + return; + } + + if(this._superType_ == oldChild) + { + setSuperType((PSuperType) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/AAdditionalTypes.java b/src/minigen/syntax3/node/AAdditionalTypes.java new file mode 100644 index 0000000..4b8a428 --- /dev/null +++ b/src/minigen/syntax3/node/AAdditionalTypes.java @@ -0,0 +1,137 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AAdditionalTypes extends PAdditionalTypes +{ + private TComma _comma_; + private PType _type_; + + public AAdditionalTypes() + { + // Constructor + } + + public AAdditionalTypes( + @SuppressWarnings("hiding") TComma _comma_, + @SuppressWarnings("hiding") PType _type_) + { + // Constructor + setComma(_comma_); + + setType(_type_); + + } + + @Override + public Object clone() + { + return new AAdditionalTypes( + cloneNode(this._comma_), + cloneNode(this._type_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAAdditionalTypes(this); + } + + public TComma getComma() + { + return this._comma_; + } + + public void setComma(TComma node) + { + if(this._comma_ != null) + { + this._comma_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._comma_ = node; + } + + public PType getType() + { + return this._type_; + } + + public void setType(PType node) + { + if(this._type_ != null) + { + this._type_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._type_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._comma_) + + toString(this._type_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._comma_ == child) + { + this._comma_ = null; + return; + } + + if(this._type_ == child) + { + this._type_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._comma_ == oldChild) + { + setComma((TComma) newChild); + return; + } + + if(this._type_ == oldChild) + { + setType((PType) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/AClassDecl.java b/src/minigen/syntax3/node/AClassDecl.java new file mode 100644 index 0000000..1233934 --- /dev/null +++ b/src/minigen/syntax3/node/AClassDecl.java @@ -0,0 +1,266 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AClassDecl extends PClassDecl +{ + private TKclass _kclass_; + private TName _name_; + private PFormalDecls _formalDecls_; + private PSuperDecls _superDecls_; + private TKend _kend_; + + public AClassDecl() + { + // Constructor + } + + public AClassDecl( + @SuppressWarnings("hiding") TKclass _kclass_, + @SuppressWarnings("hiding") TName _name_, + @SuppressWarnings("hiding") PFormalDecls _formalDecls_, + @SuppressWarnings("hiding") PSuperDecls _superDecls_, + @SuppressWarnings("hiding") TKend _kend_) + { + // Constructor + setKclass(_kclass_); + + setName(_name_); + + setFormalDecls(_formalDecls_); + + setSuperDecls(_superDecls_); + + setKend(_kend_); + + } + + @Override + public Object clone() + { + return new AClassDecl( + cloneNode(this._kclass_), + cloneNode(this._name_), + cloneNode(this._formalDecls_), + cloneNode(this._superDecls_), + cloneNode(this._kend_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAClassDecl(this); + } + + public TKclass getKclass() + { + return this._kclass_; + } + + public void setKclass(TKclass node) + { + if(this._kclass_ != null) + { + this._kclass_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._kclass_ = node; + } + + public TName getName() + { + return this._name_; + } + + public void setName(TName node) + { + if(this._name_ != null) + { + this._name_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._name_ = node; + } + + public PFormalDecls getFormalDecls() + { + return this._formalDecls_; + } + + public void setFormalDecls(PFormalDecls node) + { + if(this._formalDecls_ != null) + { + this._formalDecls_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._formalDecls_ = node; + } + + public PSuperDecls getSuperDecls() + { + return this._superDecls_; + } + + public void setSuperDecls(PSuperDecls node) + { + if(this._superDecls_ != null) + { + this._superDecls_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._superDecls_ = node; + } + + public TKend getKend() + { + return this._kend_; + } + + public void setKend(TKend node) + { + if(this._kend_ != null) + { + this._kend_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._kend_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._kclass_) + + toString(this._name_) + + toString(this._formalDecls_) + + toString(this._superDecls_) + + toString(this._kend_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._kclass_ == child) + { + this._kclass_ = null; + return; + } + + if(this._name_ == child) + { + this._name_ = null; + return; + } + + if(this._formalDecls_ == child) + { + this._formalDecls_ = null; + return; + } + + if(this._superDecls_ == child) + { + this._superDecls_ = null; + return; + } + + if(this._kend_ == child) + { + this._kend_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._kclass_ == oldChild) + { + setKclass((TKclass) newChild); + return; + } + + if(this._name_ == oldChild) + { + setName((TName) newChild); + return; + } + + if(this._formalDecls_ == oldChild) + { + setFormalDecls((PFormalDecls) newChild); + return; + } + + if(this._superDecls_ == oldChild) + { + setSuperDecls((PSuperDecls) newChild); + return; + } + + if(this._kend_ == oldChild) + { + setKend((TKend) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/AFormalDecl.java b/src/minigen/syntax3/node/AFormalDecl.java new file mode 100644 index 0000000..4031ec4 --- /dev/null +++ b/src/minigen/syntax3/node/AFormalDecl.java @@ -0,0 +1,144 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import java.util.*; +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AFormalDecl extends PFormalDecl +{ + private TName _name_; + private final LinkedList _additionalFormalTypes_ = new LinkedList(); + + public AFormalDecl() + { + // Constructor + } + + public AFormalDecl( + @SuppressWarnings("hiding") TName _name_, + @SuppressWarnings("hiding") List _additionalFormalTypes_) + { + // Constructor + setName(_name_); + + setAdditionalFormalTypes(_additionalFormalTypes_); + + } + + @Override + public Object clone() + { + return new AFormalDecl( + cloneNode(this._name_), + cloneList(this._additionalFormalTypes_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAFormalDecl(this); + } + + public TName getName() + { + return this._name_; + } + + public void setName(TName node) + { + if(this._name_ != null) + { + this._name_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._name_ = node; + } + + public LinkedList getAdditionalFormalTypes() + { + return this._additionalFormalTypes_; + } + + public void setAdditionalFormalTypes(List list) + { + this._additionalFormalTypes_.clear(); + this._additionalFormalTypes_.addAll(list); + for(PAdditionalFormalTypes e : list) + { + if(e.parent() != null) + { + e.parent().removeChild(e); + } + + e.parent(this); + } + } + + @Override + public String toString() + { + return "" + + toString(this._name_) + + toString(this._additionalFormalTypes_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._name_ == child) + { + this._name_ = null; + return; + } + + if(this._additionalFormalTypes_.remove(child)) + { + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._name_ == oldChild) + { + setName((TName) newChild); + return; + } + + for(ListIterator i = this._additionalFormalTypes_.listIterator(); i.hasNext();) + { + if(i.next() == oldChild) + { + if(newChild != null) + { + i.set((PAdditionalFormalTypes) newChild); + newChild.parent(this); + oldChild.parent(null); + return; + } + + i.remove(); + oldChild.parent(null); + return; + } + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/AFormalDecls.java b/src/minigen/syntax3/node/AFormalDecls.java new file mode 100644 index 0000000..0eda962 --- /dev/null +++ b/src/minigen/syntax3/node/AFormalDecls.java @@ -0,0 +1,187 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import java.util.*; +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AFormalDecls extends PFormalDecls +{ + private TLb _lb_; + private final LinkedList _formalDecl_ = new LinkedList(); + private TRb _rb_; + + public AFormalDecls() + { + // Constructor + } + + public AFormalDecls( + @SuppressWarnings("hiding") TLb _lb_, + @SuppressWarnings("hiding") List _formalDecl_, + @SuppressWarnings("hiding") TRb _rb_) + { + // Constructor + setLb(_lb_); + + setFormalDecl(_formalDecl_); + + setRb(_rb_); + + } + + @Override + public Object clone() + { + return new AFormalDecls( + cloneNode(this._lb_), + cloneList(this._formalDecl_), + cloneNode(this._rb_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAFormalDecls(this); + } + + public TLb getLb() + { + return this._lb_; + } + + public void setLb(TLb node) + { + if(this._lb_ != null) + { + this._lb_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._lb_ = node; + } + + public LinkedList getFormalDecl() + { + return this._formalDecl_; + } + + public void setFormalDecl(List list) + { + this._formalDecl_.clear(); + this._formalDecl_.addAll(list); + for(PFormalDecl e : list) + { + if(e.parent() != null) + { + e.parent().removeChild(e); + } + + e.parent(this); + } + } + + public TRb getRb() + { + return this._rb_; + } + + public void setRb(TRb node) + { + if(this._rb_ != null) + { + this._rb_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._rb_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._lb_) + + toString(this._formalDecl_) + + toString(this._rb_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._lb_ == child) + { + this._lb_ = null; + return; + } + + if(this._formalDecl_.remove(child)) + { + return; + } + + if(this._rb_ == child) + { + this._rb_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._lb_ == oldChild) + { + setLb((TLb) newChild); + return; + } + + for(ListIterator i = this._formalDecl_.listIterator(); i.hasNext();) + { + if(i.next() == oldChild) + { + if(newChild != null) + { + i.set((PFormalDecl) newChild); + newChild.parent(this); + oldChild.parent(null); + return; + } + + i.remove(); + oldChild.parent(null); + return; + } + } + + if(this._rb_ == oldChild) + { + setRb((TRb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/AGenericPart.java b/src/minigen/syntax3/node/AGenericPart.java new file mode 100644 index 0000000..85449e4 --- /dev/null +++ b/src/minigen/syntax3/node/AGenericPart.java @@ -0,0 +1,180 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AGenericPart extends PGenericPart +{ + private TLb _lb_; + private PGenericTypes _genericTypes_; + private TRb _rb_; + + public AGenericPart() + { + // Constructor + } + + public AGenericPart( + @SuppressWarnings("hiding") TLb _lb_, + @SuppressWarnings("hiding") PGenericTypes _genericTypes_, + @SuppressWarnings("hiding") TRb _rb_) + { + // Constructor + setLb(_lb_); + + setGenericTypes(_genericTypes_); + + setRb(_rb_); + + } + + @Override + public Object clone() + { + return new AGenericPart( + cloneNode(this._lb_), + cloneNode(this._genericTypes_), + cloneNode(this._rb_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAGenericPart(this); + } + + public TLb getLb() + { + return this._lb_; + } + + public void setLb(TLb node) + { + if(this._lb_ != null) + { + this._lb_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._lb_ = node; + } + + public PGenericTypes getGenericTypes() + { + return this._genericTypes_; + } + + public void setGenericTypes(PGenericTypes node) + { + if(this._genericTypes_ != null) + { + this._genericTypes_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._genericTypes_ = node; + } + + public TRb getRb() + { + return this._rb_; + } + + public void setRb(TRb node) + { + if(this._rb_ != null) + { + this._rb_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._rb_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._lb_) + + toString(this._genericTypes_) + + toString(this._rb_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._lb_ == child) + { + this._lb_ = null; + return; + } + + if(this._genericTypes_ == child) + { + this._genericTypes_ = null; + return; + } + + if(this._rb_ == child) + { + this._rb_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._lb_ == oldChild) + { + setLb((TLb) newChild); + return; + } + + if(this._genericTypes_ == oldChild) + { + setGenericTypes((PGenericTypes) newChild); + return; + } + + if(this._rb_ == oldChild) + { + setRb((TRb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/AGenericTypes.java b/src/minigen/syntax3/node/AGenericTypes.java new file mode 100644 index 0000000..b459f3c --- /dev/null +++ b/src/minigen/syntax3/node/AGenericTypes.java @@ -0,0 +1,144 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import java.util.*; +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AGenericTypes extends PGenericTypes +{ + private PType _type_; + private final LinkedList _additionalTypes_ = new LinkedList(); + + public AGenericTypes() + { + // Constructor + } + + public AGenericTypes( + @SuppressWarnings("hiding") PType _type_, + @SuppressWarnings("hiding") List _additionalTypes_) + { + // Constructor + setType(_type_); + + setAdditionalTypes(_additionalTypes_); + + } + + @Override + public Object clone() + { + return new AGenericTypes( + cloneNode(this._type_), + cloneList(this._additionalTypes_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAGenericTypes(this); + } + + public PType getType() + { + return this._type_; + } + + public void setType(PType node) + { + if(this._type_ != null) + { + this._type_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._type_ = node; + } + + public LinkedList getAdditionalTypes() + { + return this._additionalTypes_; + } + + public void setAdditionalTypes(List list) + { + this._additionalTypes_.clear(); + this._additionalTypes_.addAll(list); + for(PAdditionalTypes e : list) + { + if(e.parent() != null) + { + e.parent().removeChild(e); + } + + e.parent(this); + } + } + + @Override + public String toString() + { + return "" + + toString(this._type_) + + toString(this._additionalTypes_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._type_ == child) + { + this._type_ = null; + return; + } + + if(this._additionalTypes_.remove(child)) + { + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._type_ == oldChild) + { + setType((PType) newChild); + return; + } + + for(ListIterator i = this._additionalTypes_.listIterator(); i.hasNext();) + { + if(i.next() == oldChild) + { + if(newChild != null) + { + i.set((PAdditionalTypes) newChild); + newChild.parent(this); + oldChild.parent(null); + return; + } + + i.remove(); + oldChild.parent(null); + return; + } + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/AIsaInstr.java b/src/minigen/syntax3/node/AIsaInstr.java new file mode 100644 index 0000000..ebc3b9f --- /dev/null +++ b/src/minigen/syntax3/node/AIsaInstr.java @@ -0,0 +1,180 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AIsaInstr extends PInstr +{ + private PType _left_; + private TKisa _kisa_; + private PType _right_; + + public AIsaInstr() + { + // Constructor + } + + public AIsaInstr( + @SuppressWarnings("hiding") PType _left_, + @SuppressWarnings("hiding") TKisa _kisa_, + @SuppressWarnings("hiding") PType _right_) + { + // Constructor + setLeft(_left_); + + setKisa(_kisa_); + + setRight(_right_); + + } + + @Override + public Object clone() + { + return new AIsaInstr( + cloneNode(this._left_), + cloneNode(this._kisa_), + cloneNode(this._right_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAIsaInstr(this); + } + + public PType getLeft() + { + return this._left_; + } + + public void setLeft(PType node) + { + if(this._left_ != null) + { + this._left_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._left_ = node; + } + + public TKisa getKisa() + { + return this._kisa_; + } + + public void setKisa(TKisa node) + { + if(this._kisa_ != null) + { + this._kisa_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._kisa_ = node; + } + + public PType getRight() + { + return this._right_; + } + + public void setRight(PType node) + { + if(this._right_ != null) + { + this._right_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._right_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._left_) + + toString(this._kisa_) + + toString(this._right_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._left_ == child) + { + this._left_ = null; + return; + } + + if(this._kisa_ == child) + { + this._kisa_ = null; + return; + } + + if(this._right_ == child) + { + this._right_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._left_ == oldChild) + { + setLeft((PType) newChild); + return; + } + + if(this._kisa_ == oldChild) + { + setKisa((TKisa) newChild); + return; + } + + if(this._right_ == oldChild) + { + setRight((PType) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/AProgram.java b/src/minigen/syntax3/node/AProgram.java new file mode 100644 index 0000000..7a4d525 --- /dev/null +++ b/src/minigen/syntax3/node/AProgram.java @@ -0,0 +1,150 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import java.util.*; +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AProgram extends PProgram +{ + private final LinkedList _classes_ = new LinkedList(); + private final LinkedList _instrs_ = new LinkedList(); + + public AProgram() + { + // Constructor + } + + public AProgram( + @SuppressWarnings("hiding") List _classes_, + @SuppressWarnings("hiding") List _instrs_) + { + // Constructor + setClasses(_classes_); + + setInstrs(_instrs_); + + } + + @Override + public Object clone() + { + return new AProgram( + cloneList(this._classes_), + cloneList(this._instrs_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAProgram(this); + } + + public LinkedList getClasses() + { + return this._classes_; + } + + public void setClasses(List list) + { + this._classes_.clear(); + this._classes_.addAll(list); + for(PClassDecl e : list) + { + if(e.parent() != null) + { + e.parent().removeChild(e); + } + + e.parent(this); + } + } + + public LinkedList getInstrs() + { + return this._instrs_; + } + + public void setInstrs(List list) + { + this._instrs_.clear(); + this._instrs_.addAll(list); + for(PInstr e : list) + { + if(e.parent() != null) + { + e.parent().removeChild(e); + } + + e.parent(this); + } + } + + @Override + public String toString() + { + return "" + + toString(this._classes_) + + toString(this._instrs_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._classes_.remove(child)) + { + return; + } + + if(this._instrs_.remove(child)) + { + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + for(ListIterator i = this._classes_.listIterator(); i.hasNext();) + { + if(i.next() == oldChild) + { + if(newChild != null) + { + i.set((PClassDecl) newChild); + newChild.parent(this); + oldChild.parent(null); + return; + } + + i.remove(); + oldChild.parent(null); + return; + } + } + + for(ListIterator i = this._instrs_.listIterator(); i.hasNext();) + { + if(i.next() == oldChild) + { + if(newChild != null) + { + i.set((PInstr) newChild); + newChild.parent(this); + oldChild.parent(null); + return; + } + + i.remove(); + oldChild.parent(null); + return; + } + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/ASuperAdditionalTypes.java b/src/minigen/syntax3/node/ASuperAdditionalTypes.java new file mode 100644 index 0000000..0615bf6 --- /dev/null +++ b/src/minigen/syntax3/node/ASuperAdditionalTypes.java @@ -0,0 +1,137 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class ASuperAdditionalTypes extends PSuperAdditionalTypes +{ + private TComma _comma_; + private PSuperType _superType_; + + public ASuperAdditionalTypes() + { + // Constructor + } + + public ASuperAdditionalTypes( + @SuppressWarnings("hiding") TComma _comma_, + @SuppressWarnings("hiding") PSuperType _superType_) + { + // Constructor + setComma(_comma_); + + setSuperType(_superType_); + + } + + @Override + public Object clone() + { + return new ASuperAdditionalTypes( + cloneNode(this._comma_), + cloneNode(this._superType_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseASuperAdditionalTypes(this); + } + + public TComma getComma() + { + return this._comma_; + } + + public void setComma(TComma node) + { + if(this._comma_ != null) + { + this._comma_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._comma_ = node; + } + + public PSuperType getSuperType() + { + return this._superType_; + } + + public void setSuperType(PSuperType node) + { + if(this._superType_ != null) + { + this._superType_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._superType_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._comma_) + + toString(this._superType_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._comma_ == child) + { + this._comma_ = null; + return; + } + + if(this._superType_ == child) + { + this._superType_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._comma_ == oldChild) + { + setComma((TComma) newChild); + return; + } + + if(this._superType_ == oldChild) + { + setSuperType((PSuperType) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/ASuperDecls.java b/src/minigen/syntax3/node/ASuperDecls.java new file mode 100644 index 0000000..fe4aabf --- /dev/null +++ b/src/minigen/syntax3/node/ASuperDecls.java @@ -0,0 +1,187 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import java.util.*; +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class ASuperDecls extends PSuperDecls +{ + private TKsuper _ksuper_; + private PSuperType _superType_; + private final LinkedList _additionalSupers_ = new LinkedList(); + + public ASuperDecls() + { + // Constructor + } + + public ASuperDecls( + @SuppressWarnings("hiding") TKsuper _ksuper_, + @SuppressWarnings("hiding") PSuperType _superType_, + @SuppressWarnings("hiding") List _additionalSupers_) + { + // Constructor + setKsuper(_ksuper_); + + setSuperType(_superType_); + + setAdditionalSupers(_additionalSupers_); + + } + + @Override + public Object clone() + { + return new ASuperDecls( + cloneNode(this._ksuper_), + cloneNode(this._superType_), + cloneList(this._additionalSupers_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseASuperDecls(this); + } + + public TKsuper getKsuper() + { + return this._ksuper_; + } + + public void setKsuper(TKsuper node) + { + if(this._ksuper_ != null) + { + this._ksuper_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ksuper_ = node; + } + + public PSuperType getSuperType() + { + return this._superType_; + } + + public void setSuperType(PSuperType node) + { + if(this._superType_ != null) + { + this._superType_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._superType_ = node; + } + + public LinkedList getAdditionalSupers() + { + return this._additionalSupers_; + } + + public void setAdditionalSupers(List list) + { + this._additionalSupers_.clear(); + this._additionalSupers_.addAll(list); + for(PAdditionalSupers e : list) + { + if(e.parent() != null) + { + e.parent().removeChild(e); + } + + e.parent(this); + } + } + + @Override + public String toString() + { + return "" + + toString(this._ksuper_) + + toString(this._superType_) + + toString(this._additionalSupers_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._ksuper_ == child) + { + this._ksuper_ = null; + return; + } + + if(this._superType_ == child) + { + this._superType_ = null; + return; + } + + if(this._additionalSupers_.remove(child)) + { + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._ksuper_ == oldChild) + { + setKsuper((TKsuper) newChild); + return; + } + + if(this._superType_ == oldChild) + { + setSuperType((PSuperType) newChild); + return; + } + + for(ListIterator i = this._additionalSupers_.listIterator(); i.hasNext();) + { + if(i.next() == oldChild) + { + if(newChild != null) + { + i.set((PAdditionalSupers) newChild); + newChild.parent(this); + oldChild.parent(null); + return; + } + + i.remove(); + oldChild.parent(null); + return; + } + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/ASuperGenericPart.java b/src/minigen/syntax3/node/ASuperGenericPart.java new file mode 100644 index 0000000..65644fc --- /dev/null +++ b/src/minigen/syntax3/node/ASuperGenericPart.java @@ -0,0 +1,180 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class ASuperGenericPart extends PSuperGenericPart +{ + private TLb _lb_; + private PSuperGenericTypes _superGenericTypes_; + private TRb _rb_; + + public ASuperGenericPart() + { + // Constructor + } + + public ASuperGenericPart( + @SuppressWarnings("hiding") TLb _lb_, + @SuppressWarnings("hiding") PSuperGenericTypes _superGenericTypes_, + @SuppressWarnings("hiding") TRb _rb_) + { + // Constructor + setLb(_lb_); + + setSuperGenericTypes(_superGenericTypes_); + + setRb(_rb_); + + } + + @Override + public Object clone() + { + return new ASuperGenericPart( + cloneNode(this._lb_), + cloneNode(this._superGenericTypes_), + cloneNode(this._rb_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseASuperGenericPart(this); + } + + public TLb getLb() + { + return this._lb_; + } + + public void setLb(TLb node) + { + if(this._lb_ != null) + { + this._lb_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._lb_ = node; + } + + public PSuperGenericTypes getSuperGenericTypes() + { + return this._superGenericTypes_; + } + + public void setSuperGenericTypes(PSuperGenericTypes node) + { + if(this._superGenericTypes_ != null) + { + this._superGenericTypes_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._superGenericTypes_ = node; + } + + public TRb getRb() + { + return this._rb_; + } + + public void setRb(TRb node) + { + if(this._rb_ != null) + { + this._rb_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._rb_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._lb_) + + toString(this._superGenericTypes_) + + toString(this._rb_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._lb_ == child) + { + this._lb_ = null; + return; + } + + if(this._superGenericTypes_ == child) + { + this._superGenericTypes_ = null; + return; + } + + if(this._rb_ == child) + { + this._rb_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._lb_ == oldChild) + { + setLb((TLb) newChild); + return; + } + + if(this._superGenericTypes_ == oldChild) + { + setSuperGenericTypes((PSuperGenericTypes) newChild); + return; + } + + if(this._rb_ == oldChild) + { + setRb((TRb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/ASuperGenericTypes.java b/src/minigen/syntax3/node/ASuperGenericTypes.java new file mode 100644 index 0000000..f0515c0 --- /dev/null +++ b/src/minigen/syntax3/node/ASuperGenericTypes.java @@ -0,0 +1,144 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import java.util.*; +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class ASuperGenericTypes extends PSuperGenericTypes +{ + private PSuperType _superType_; + private final LinkedList _superAdditionalTypes_ = new LinkedList(); + + public ASuperGenericTypes() + { + // Constructor + } + + public ASuperGenericTypes( + @SuppressWarnings("hiding") PSuperType _superType_, + @SuppressWarnings("hiding") List _superAdditionalTypes_) + { + // Constructor + setSuperType(_superType_); + + setSuperAdditionalTypes(_superAdditionalTypes_); + + } + + @Override + public Object clone() + { + return new ASuperGenericTypes( + cloneNode(this._superType_), + cloneList(this._superAdditionalTypes_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseASuperGenericTypes(this); + } + + public PSuperType getSuperType() + { + return this._superType_; + } + + public void setSuperType(PSuperType node) + { + if(this._superType_ != null) + { + this._superType_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._superType_ = node; + } + + public LinkedList getSuperAdditionalTypes() + { + return this._superAdditionalTypes_; + } + + public void setSuperAdditionalTypes(List list) + { + this._superAdditionalTypes_.clear(); + this._superAdditionalTypes_.addAll(list); + for(PSuperAdditionalTypes e : list) + { + if(e.parent() != null) + { + e.parent().removeChild(e); + } + + e.parent(this); + } + } + + @Override + public String toString() + { + return "" + + toString(this._superType_) + + toString(this._superAdditionalTypes_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._superType_ == child) + { + this._superType_ = null; + return; + } + + if(this._superAdditionalTypes_.remove(child)) + { + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._superType_ == oldChild) + { + setSuperType((PSuperType) newChild); + return; + } + + for(ListIterator i = this._superAdditionalTypes_.listIterator(); i.hasNext();) + { + if(i.next() == oldChild) + { + if(newChild != null) + { + i.set((PSuperAdditionalTypes) newChild); + newChild.parent(this); + oldChild.parent(null); + return; + } + + i.remove(); + oldChild.parent(null); + return; + } + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/ASuperType.java b/src/minigen/syntax3/node/ASuperType.java new file mode 100644 index 0000000..738c241 --- /dev/null +++ b/src/minigen/syntax3/node/ASuperType.java @@ -0,0 +1,137 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class ASuperType extends PSuperType +{ + private TName _name_; + private PSuperGenericPart _superGenericPart_; + + public ASuperType() + { + // Constructor + } + + public ASuperType( + @SuppressWarnings("hiding") TName _name_, + @SuppressWarnings("hiding") PSuperGenericPart _superGenericPart_) + { + // Constructor + setName(_name_); + + setSuperGenericPart(_superGenericPart_); + + } + + @Override + public Object clone() + { + return new ASuperType( + cloneNode(this._name_), + cloneNode(this._superGenericPart_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseASuperType(this); + } + + public TName getName() + { + return this._name_; + } + + public void setName(TName node) + { + if(this._name_ != null) + { + this._name_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._name_ = node; + } + + public PSuperGenericPart getSuperGenericPart() + { + return this._superGenericPart_; + } + + public void setSuperGenericPart(PSuperGenericPart node) + { + if(this._superGenericPart_ != null) + { + this._superGenericPart_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._superGenericPart_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._name_) + + toString(this._superGenericPart_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._name_ == child) + { + this._name_ = null; + return; + } + + if(this._superGenericPart_ == child) + { + this._superGenericPart_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._name_ == oldChild) + { + setName((TName) newChild); + return; + } + + if(this._superGenericPart_ == oldChild) + { + setSuperGenericPart((PSuperGenericPart) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/AType.java b/src/minigen/syntax3/node/AType.java new file mode 100644 index 0000000..ea0fcfe --- /dev/null +++ b/src/minigen/syntax3/node/AType.java @@ -0,0 +1,137 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class AType extends PType +{ + private TName _name_; + private PGenericPart _genericPart_; + + public AType() + { + // Constructor + } + + public AType( + @SuppressWarnings("hiding") TName _name_, + @SuppressWarnings("hiding") PGenericPart _genericPart_) + { + // Constructor + setName(_name_); + + setGenericPart(_genericPart_); + + } + + @Override + public Object clone() + { + return new AType( + cloneNode(this._name_), + cloneNode(this._genericPart_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseAType(this); + } + + public TName getName() + { + return this._name_; + } + + public void setName(TName node) + { + if(this._name_ != null) + { + this._name_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._name_ = node; + } + + public PGenericPart getGenericPart() + { + return this._genericPart_; + } + + public void setGenericPart(PGenericPart node) + { + if(this._genericPart_ != null) + { + this._genericPart_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._genericPart_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._name_) + + toString(this._genericPart_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._name_ == child) + { + this._name_ = null; + return; + } + + if(this._genericPart_ == child) + { + this._genericPart_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._name_ == oldChild) + { + setName((TName) newChild); + return; + } + + if(this._genericPart_ == oldChild) + { + setGenericPart((PGenericPart) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/node/EOF.java b/src/minigen/syntax3/node/EOF.java new file mode 100644 index 0000000..3117e62 --- /dev/null +++ b/src/minigen/syntax3/node/EOF.java @@ -0,0 +1,32 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class EOF extends Token +{ + public EOF() + { + setText(""); + } + + public EOF(int line, int pos) + { + setText(""); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new EOF(getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseEOF(this); + } +} diff --git a/src/minigen/syntax3/node/Node.java b/src/minigen/syntax3/node/Node.java new file mode 100644 index 0000000..5bbe3de --- /dev/null +++ b/src/minigen/syntax3/node/Node.java @@ -0,0 +1,77 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import java.util.*; + +@SuppressWarnings("nls") +public abstract class Node implements Switchable, Cloneable +{ + private Node parent; + + @Override + public abstract Object clone(); + + public Node parent() + { + return this.parent; + } + + void parent(@SuppressWarnings("hiding") Node parent) + { + this.parent = parent; + } + + abstract void removeChild(Node child); + abstract void replaceChild(Node oldChild, Node newChild); + + public void replaceBy(Node node) + { + this.parent.replaceChild(this, node); + } + + protected String toString(Node node) + { + if(node != null) + { + return node.toString(); + } + + return ""; + } + + protected String toString(List list) + { + StringBuffer s = new StringBuffer(); + + for(Iterator i = list.iterator(); i.hasNext();) + { + s.append(i.next()); + } + + return s.toString(); + } + + @SuppressWarnings("unchecked") + protected T cloneNode(T node) + { + if(node != null) + { + return (T) node.clone(); + } + + return null; + } + + protected List cloneList(List list) + { + List clone = new LinkedList(); + + for(T n : list) + { + clone.add(n); + } + + return clone; + } +} diff --git a/src/minigen/syntax3/node/PAdditionalFormalTypes.java b/src/minigen/syntax3/node/PAdditionalFormalTypes.java new file mode 100644 index 0000000..cc9b142 --- /dev/null +++ b/src/minigen/syntax3/node/PAdditionalFormalTypes.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PAdditionalFormalTypes extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PAdditionalSupers.java b/src/minigen/syntax3/node/PAdditionalSupers.java new file mode 100644 index 0000000..a1be465 --- /dev/null +++ b/src/minigen/syntax3/node/PAdditionalSupers.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PAdditionalSupers extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PAdditionalTypes.java b/src/minigen/syntax3/node/PAdditionalTypes.java new file mode 100644 index 0000000..98fe245 --- /dev/null +++ b/src/minigen/syntax3/node/PAdditionalTypes.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PAdditionalTypes extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PClassDecl.java b/src/minigen/syntax3/node/PClassDecl.java new file mode 100644 index 0000000..0e7f938 --- /dev/null +++ b/src/minigen/syntax3/node/PClassDecl.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PClassDecl extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PFormalDecl.java b/src/minigen/syntax3/node/PFormalDecl.java new file mode 100644 index 0000000..7066aca --- /dev/null +++ b/src/minigen/syntax3/node/PFormalDecl.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PFormalDecl extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PFormalDecls.java b/src/minigen/syntax3/node/PFormalDecls.java new file mode 100644 index 0000000..3ea8cac --- /dev/null +++ b/src/minigen/syntax3/node/PFormalDecls.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PFormalDecls extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PGenericPart.java b/src/minigen/syntax3/node/PGenericPart.java new file mode 100644 index 0000000..96ca680 --- /dev/null +++ b/src/minigen/syntax3/node/PGenericPart.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PGenericPart extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PGenericTypes.java b/src/minigen/syntax3/node/PGenericTypes.java new file mode 100644 index 0000000..e253ed7 --- /dev/null +++ b/src/minigen/syntax3/node/PGenericTypes.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PGenericTypes extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PInstr.java b/src/minigen/syntax3/node/PInstr.java new file mode 100644 index 0000000..53ccff7 --- /dev/null +++ b/src/minigen/syntax3/node/PInstr.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PInstr extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PProgram.java b/src/minigen/syntax3/node/PProgram.java new file mode 100644 index 0000000..f4340e3 --- /dev/null +++ b/src/minigen/syntax3/node/PProgram.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PProgram extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PSuperAdditionalTypes.java b/src/minigen/syntax3/node/PSuperAdditionalTypes.java new file mode 100644 index 0000000..5a32a06 --- /dev/null +++ b/src/minigen/syntax3/node/PSuperAdditionalTypes.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PSuperAdditionalTypes extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PSuperDecls.java b/src/minigen/syntax3/node/PSuperDecls.java new file mode 100644 index 0000000..4028d69 --- /dev/null +++ b/src/minigen/syntax3/node/PSuperDecls.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PSuperDecls extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PSuperGenericPart.java b/src/minigen/syntax3/node/PSuperGenericPart.java new file mode 100644 index 0000000..2dbff9d --- /dev/null +++ b/src/minigen/syntax3/node/PSuperGenericPart.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PSuperGenericPart extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PSuperGenericTypes.java b/src/minigen/syntax3/node/PSuperGenericTypes.java new file mode 100644 index 0000000..2b84061 --- /dev/null +++ b/src/minigen/syntax3/node/PSuperGenericTypes.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PSuperGenericTypes extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PSuperType.java b/src/minigen/syntax3/node/PSuperType.java new file mode 100644 index 0000000..c96990e --- /dev/null +++ b/src/minigen/syntax3/node/PSuperType.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PSuperType extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/PType.java b/src/minigen/syntax3/node/PType.java new file mode 100644 index 0000000..5469583 --- /dev/null +++ b/src/minigen/syntax3/node/PType.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public abstract class PType extends Node +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/Start.java b/src/minigen/syntax3/node/Start.java new file mode 100644 index 0000000..5b4acc2 --- /dev/null +++ b/src/minigen/syntax3/node/Start.java @@ -0,0 +1,132 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class Start extends Node +{ + private PProgram _pProgram_; + private EOF _eof_; + + public Start() + { + // Empty body + } + + public Start( + @SuppressWarnings("hiding") PProgram _pProgram_, + @SuppressWarnings("hiding") EOF _eof_) + { + setPProgram(_pProgram_); + setEOF(_eof_); + } + + @Override + public Object clone() + { + return new Start( + cloneNode(this._pProgram_), + cloneNode(this._eof_)); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseStart(this); + } + + public PProgram getPProgram() + { + return this._pProgram_; + } + + public void setPProgram(PProgram node) + { + if(this._pProgram_ != null) + { + this._pProgram_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._pProgram_ = node; + } + + public EOF getEOF() + { + return this._eof_; + } + + public void setEOF(EOF node) + { + if(this._eof_ != null) + { + this._eof_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._eof_ = node; + } + + @Override + void removeChild(Node child) + { + if(this._pProgram_ == child) + { + this._pProgram_ = null; + return; + } + + if(this._eof_ == child) + { + this._eof_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(Node oldChild, Node newChild) + { + if(this._pProgram_ == oldChild) + { + setPProgram((PProgram) newChild); + return; + } + + if(this._eof_ == oldChild) + { + setEOF((EOF) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + public String toString() + { + return "" + + toString(this._pProgram_) + + toString(this._eof_); + } +} diff --git a/src/minigen/syntax3/node/Switch.java b/src/minigen/syntax3/node/Switch.java new file mode 100644 index 0000000..a75f207 --- /dev/null +++ b/src/minigen/syntax3/node/Switch.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public interface Switch +{ + // Empty body +} diff --git a/src/minigen/syntax3/node/Switchable.java b/src/minigen/syntax3/node/Switchable.java new file mode 100644 index 0000000..d2ec7e1 --- /dev/null +++ b/src/minigen/syntax3/node/Switchable.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +public interface Switchable +{ + void apply(Switch sw); +} diff --git a/src/minigen/syntax3/node/TBlanks.java b/src/minigen/syntax3/node/TBlanks.java new file mode 100644 index 0000000..99b5d6a --- /dev/null +++ b/src/minigen/syntax3/node/TBlanks.java @@ -0,0 +1,32 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TBlanks extends Token +{ + public TBlanks(String text) + { + setText(text); + } + + public TBlanks(String text, int line, int pos) + { + setText(text); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TBlanks(getText(), getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTBlanks(this); + } +} diff --git a/src/minigen/syntax3/node/TComma.java b/src/minigen/syntax3/node/TComma.java new file mode 100644 index 0000000..2ab0d71 --- /dev/null +++ b/src/minigen/syntax3/node/TComma.java @@ -0,0 +1,38 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TComma extends Token +{ + public TComma() + { + super.setText(","); + } + + public TComma(int line, int pos) + { + super.setText(","); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TComma(getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTComma(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TComma text."); + } +} diff --git a/src/minigen/syntax3/node/TComment.java b/src/minigen/syntax3/node/TComment.java new file mode 100644 index 0000000..d68a652 --- /dev/null +++ b/src/minigen/syntax3/node/TComment.java @@ -0,0 +1,32 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TComment extends Token +{ + public TComment(String text) + { + setText(text); + } + + public TComment(String text, int line, int pos) + { + setText(text); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TComment(getText(), getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTComment(this); + } +} diff --git a/src/minigen/syntax3/node/TKclass.java b/src/minigen/syntax3/node/TKclass.java new file mode 100644 index 0000000..d5a5e03 --- /dev/null +++ b/src/minigen/syntax3/node/TKclass.java @@ -0,0 +1,38 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TKclass extends Token +{ + public TKclass() + { + super.setText("class"); + } + + public TKclass(int line, int pos) + { + super.setText("class"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TKclass(getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTKclass(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TKclass text."); + } +} diff --git a/src/minigen/syntax3/node/TKend.java b/src/minigen/syntax3/node/TKend.java new file mode 100644 index 0000000..a8e304f --- /dev/null +++ b/src/minigen/syntax3/node/TKend.java @@ -0,0 +1,38 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TKend extends Token +{ + public TKend() + { + super.setText("end"); + } + + public TKend(int line, int pos) + { + super.setText("end"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TKend(getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTKend(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TKend text."); + } +} diff --git a/src/minigen/syntax3/node/TKisa.java b/src/minigen/syntax3/node/TKisa.java new file mode 100644 index 0000000..6416e6d --- /dev/null +++ b/src/minigen/syntax3/node/TKisa.java @@ -0,0 +1,38 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TKisa extends Token +{ + public TKisa() + { + super.setText("isa"); + } + + public TKisa(int line, int pos) + { + super.setText("isa"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TKisa(getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTKisa(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TKisa text."); + } +} diff --git a/src/minigen/syntax3/node/TKnew.java b/src/minigen/syntax3/node/TKnew.java new file mode 100644 index 0000000..fe9122c --- /dev/null +++ b/src/minigen/syntax3/node/TKnew.java @@ -0,0 +1,38 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TKnew extends Token +{ + public TKnew() + { + super.setText("new"); + } + + public TKnew(int line, int pos) + { + super.setText("new"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TKnew(getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTKnew(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TKnew text."); + } +} diff --git a/src/minigen/syntax3/node/TKsuper.java b/src/minigen/syntax3/node/TKsuper.java new file mode 100644 index 0000000..b2c702a --- /dev/null +++ b/src/minigen/syntax3/node/TKsuper.java @@ -0,0 +1,38 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TKsuper extends Token +{ + public TKsuper() + { + super.setText("super"); + } + + public TKsuper(int line, int pos) + { + super.setText("super"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TKsuper(getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTKsuper(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TKsuper text."); + } +} diff --git a/src/minigen/syntax3/node/TLb.java b/src/minigen/syntax3/node/TLb.java new file mode 100644 index 0000000..a052219 --- /dev/null +++ b/src/minigen/syntax3/node/TLb.java @@ -0,0 +1,38 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TLb extends Token +{ + public TLb() + { + super.setText("["); + } + + public TLb(int line, int pos) + { + super.setText("["); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TLb(getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTLb(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TLb text."); + } +} diff --git a/src/minigen/syntax3/node/TName.java b/src/minigen/syntax3/node/TName.java new file mode 100644 index 0000000..a675dd6 --- /dev/null +++ b/src/minigen/syntax3/node/TName.java @@ -0,0 +1,32 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TName extends Token +{ + public TName(String text) + { + setText(text); + } + + public TName(String text, int line, int pos) + { + setText(text); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TName(getText(), getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTName(this); + } +} diff --git a/src/minigen/syntax3/node/TRb.java b/src/minigen/syntax3/node/TRb.java new file mode 100644 index 0000000..fc48f37 --- /dev/null +++ b/src/minigen/syntax3/node/TRb.java @@ -0,0 +1,38 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +import minigen.syntax3.analysis.*; + +@SuppressWarnings("nls") +public final class TRb extends Token +{ + public TRb() + { + super.setText("]"); + } + + public TRb(int line, int pos) + { + super.setText("]"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TRb(getLine(), getPos()); + } + + public void apply(Switch sw) + { + ((Analysis) sw).caseTRb(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TRb text."); + } +} diff --git a/src/minigen/syntax3/node/Token.java b/src/minigen/syntax3/node/Token.java new file mode 100644 index 0000000..5667929 --- /dev/null +++ b/src/minigen/syntax3/node/Token.java @@ -0,0 +1,59 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.node; + +@SuppressWarnings("nls") +public abstract class Token extends Node +{ + private String text; + private int line; + private int pos; + + public String getText() + { + return this.text; + } + + public void setText(@SuppressWarnings("hiding") String text) + { + this.text = text; + } + + public int getLine() + { + return this.line; + } + + public void setLine(@SuppressWarnings("hiding") int line) + { + this.line = line; + } + + public int getPos() + { + return this.pos; + } + + public void setPos(@SuppressWarnings("hiding") int pos) + { + this.pos = pos; + } + + @Override + public String toString() + { + return this.text + " "; + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + throw new RuntimeException("Not a child."); + } +} diff --git a/src/minigen/syntax3/parser/Parser.java b/src/minigen/syntax3/parser/Parser.java new file mode 100644 index 0000000..5aeb779 --- /dev/null +++ b/src/minigen/syntax3/parser/Parser.java @@ -0,0 +1,1757 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.parser; + +import minigen.syntax3.lexer.*; +import minigen.syntax3.node.*; +import minigen.syntax3.analysis.*; +import java.util.*; + +import java.io.DataInputStream; +import java.io.BufferedInputStream; +import java.io.IOException; + +@SuppressWarnings("nls") +public class Parser +{ + public final Analysis ignoredTokens = new AnalysisAdapter(); + + protected ArrayList nodeList; + + private final Lexer lexer; + private final ListIterator stack = new LinkedList().listIterator(); + private int last_pos; + private int last_line; + private Token last_token; + private final TokenIndex converter = new TokenIndex(); + private final int[] action = new int[2]; + + private final static int SHIFT = 0; + private final static int REDUCE = 1; + private final static int ACCEPT = 2; + private final static int ERROR = 3; + + public Parser(@SuppressWarnings("hiding") Lexer lexer) + { + this.lexer = lexer; + } + + protected void filter() throws ParserException, LexerException, IOException + { + // Empty body + } + + private void push(int numstate, ArrayList listNode, boolean hidden) throws ParserException, LexerException, IOException + { + this.nodeList = listNode; + + if(!hidden) + { + filter(); + } + + if(!this.stack.hasNext()) + { + this.stack.add(new State(numstate, this.nodeList)); + return; + } + + State s = (State) this.stack.next(); + s.state = numstate; + s.nodes = this.nodeList; + } + + private int goTo(int index) + { + int state = state(); + int low = 1; + int high = gotoTable[index].length - 1; + int value = gotoTable[index][0][1]; + + while(low <= high) + { + int middle = (low + high) / 2; + + if(state < gotoTable[index][middle][0]) + { + high = middle - 1; + } + else if(state > gotoTable[index][middle][0]) + { + low = middle + 1; + } + else + { + value = gotoTable[index][middle][1]; + break; + } + } + + return value; + } + + private int state() + { + State s = (State) this.stack.previous(); + this.stack.next(); + return s.state; + } + + private ArrayList pop() + { + return ((State) this.stack.previous()).nodes; + } + + private int index(Switchable token) + { + this.converter.index = -1; + token.apply(this.converter); + return this.converter.index; + } + + @SuppressWarnings("unchecked") + public Start parse() throws ParserException, LexerException, IOException + { + push(0, null, true); + List ign = null; + while(true) + { + while(index(this.lexer.peek()) == -1) + { + if(ign == null) + { + ign = new LinkedList(); + } + + ign.add(this.lexer.next()); + } + + if(ign != null) + { + this.ignoredTokens.setIn(this.lexer.peek(), ign); + ign = null; + } + + this.last_pos = this.lexer.peek().getPos(); + this.last_line = this.lexer.peek().getLine(); + this.last_token = this.lexer.peek(); + + int index = index(this.lexer.peek()); + this.action[0] = Parser.actionTable[state()][0][1]; + this.action[1] = Parser.actionTable[state()][0][2]; + + int low = 1; + int high = Parser.actionTable[state()].length - 1; + + while(low <= high) + { + int middle = (low + high) / 2; + + if(index < Parser.actionTable[state()][middle][0]) + { + high = middle - 1; + } + else if(index > Parser.actionTable[state()][middle][0]) + { + low = middle + 1; + } + else + { + this.action[0] = Parser.actionTable[state()][middle][1]; + this.action[1] = Parser.actionTable[state()][middle][2]; + break; + } + } + + switch(this.action[0]) + { + case SHIFT: + { + ArrayList list = new ArrayList(); + list.add(this.lexer.next()); + push(this.action[1], list, false); + } + break; + case REDUCE: + switch(this.action[1]) + { + case 0: /* reduce AAprogram1Program */ + { + ArrayList list = new0(); + push(goTo(0), list, false); + } + break; + case 1: /* reduce AAprogram2Program */ + { + ArrayList list = new1(); + push(goTo(0), list, false); + } + break; + case 2: /* reduce AAprogram3Program */ + { + ArrayList list = new2(); + push(goTo(0), list, false); + } + break; + case 3: /* reduce AAprogram4Program */ + { + ArrayList list = new3(); + push(goTo(0), list, false); + } + break; + case 4: /* reduce AAclassdecl1ClassDecl */ + { + ArrayList list = new4(); + push(goTo(1), list, false); + } + break; + case 5: /* reduce AAclassdecl2ClassDecl */ + { + ArrayList list = new5(); + push(goTo(1), list, false); + } + break; + case 6: /* reduce AAclassdecl3ClassDecl */ + { + ArrayList list = new6(); + push(goTo(1), list, false); + } + break; + case 7: /* reduce AAclassdecl4ClassDecl */ + { + ArrayList list = new7(); + push(goTo(1), list, false); + } + break; + case 8: /* reduce AFormalDecls */ + { + ArrayList list = new8(); + push(goTo(2), list, false); + } + break; + case 9: /* reduce AAformaldecl1FormalDecl */ + { + ArrayList list = new9(); + push(goTo(3), list, false); + } + break; + case 10: /* reduce AAformaldecl2FormalDecl */ + { + ArrayList list = new10(); + push(goTo(3), list, false); + } + break; + case 11: /* reduce AAdditionalFormalTypes */ + { + ArrayList list = new11(); + push(goTo(4), list, false); + } + break; + case 12: /* reduce AAtype1Type */ + { + ArrayList list = new12(); + push(goTo(5), list, false); + } + break; + case 13: /* reduce AAtype2Type */ + { + ArrayList list = new13(); + push(goTo(5), list, false); + } + break; + case 14: /* reduce AGenericPart */ + { + ArrayList list = new14(); + push(goTo(6), list, false); + } + break; + case 15: /* reduce AAgenerictypes1GenericTypes */ + { + ArrayList list = new15(); + push(goTo(7), list, false); + } + break; + case 16: /* reduce AAgenerictypes2GenericTypes */ + { + ArrayList list = new16(); + push(goTo(7), list, false); + } + break; + case 17: /* reduce AAdditionalTypes */ + { + ArrayList list = new17(); + push(goTo(8), list, false); + } + break; + case 18: /* reduce AAsuperdecls1SuperDecls */ + { + ArrayList list = new18(); + push(goTo(9), list, false); + } + break; + case 19: /* reduce AAsuperdecls2SuperDecls */ + { + ArrayList list = new19(); + push(goTo(9), list, false); + } + break; + case 20: /* reduce AAdditionalSupers */ + { + ArrayList list = new20(); + push(goTo(10), list, false); + } + break; + case 21: /* reduce AAsupertype1SuperType */ + { + ArrayList list = new21(); + push(goTo(11), list, false); + } + break; + case 22: /* reduce AAsupertype2SuperType */ + { + ArrayList list = new22(); + push(goTo(11), list, false); + } + break; + case 23: /* reduce ASuperGenericPart */ + { + ArrayList list = new23(); + push(goTo(12), list, false); + } + break; + case 24: /* reduce AAsupergenerictypes1SuperGenericTypes */ + { + ArrayList list = new24(); + push(goTo(13), list, false); + } + break; + case 25: /* reduce AAsupergenerictypes2SuperGenericTypes */ + { + ArrayList list = new25(); + push(goTo(13), list, false); + } + break; + case 26: /* reduce ASuperAdditionalTypes */ + { + ArrayList list = new26(); + push(goTo(14), list, false); + } + break; + case 27: /* reduce AIsaInstr */ + { + ArrayList list = new27(); + push(goTo(15), list, false); + } + break; + case 28: /* reduce ATerminal$ClassDecl */ + { + ArrayList list = new28(); + push(goTo(16), list, true); + } + break; + case 29: /* reduce ANonTerminal$ClassDecl */ + { + ArrayList list = new29(); + push(goTo(16), list, true); + } + break; + case 30: /* reduce ATerminal$Instr */ + { + ArrayList list = new30(); + push(goTo(17), list, true); + } + break; + case 31: /* reduce ANonTerminal$Instr */ + { + ArrayList list = new31(); + push(goTo(17), list, true); + } + break; + case 32: /* reduce ATerminal$FormalDecl */ + { + ArrayList list = new32(); + push(goTo(18), list, true); + } + break; + case 33: /* reduce ANonTerminal$FormalDecl */ + { + ArrayList list = new33(); + push(goTo(18), list, true); + } + break; + case 34: /* reduce ATerminal$AdditionalFormalTypes */ + { + ArrayList list = new34(); + push(goTo(19), list, true); + } + break; + case 35: /* reduce ANonTerminal$AdditionalFormalTypes */ + { + ArrayList list = new35(); + push(goTo(19), list, true); + } + break; + case 36: /* reduce ATerminal$AdditionalTypes */ + { + ArrayList list = new36(); + push(goTo(20), list, true); + } + break; + case 37: /* reduce ANonTerminal$AdditionalTypes */ + { + ArrayList list = new37(); + push(goTo(20), list, true); + } + break; + case 38: /* reduce ATerminal$AdditionalSupers */ + { + ArrayList list = new38(); + push(goTo(21), list, true); + } + break; + case 39: /* reduce ANonTerminal$AdditionalSupers */ + { + ArrayList list = new39(); + push(goTo(21), list, true); + } + break; + case 40: /* reduce ATerminal$SuperAdditionalTypes */ + { + ArrayList list = new40(); + push(goTo(22), list, true); + } + break; + case 41: /* reduce ANonTerminal$SuperAdditionalTypes */ + { + ArrayList list = new41(); + push(goTo(22), list, true); + } + break; + } + break; + case ACCEPT: + { + EOF node2 = (EOF) this.lexer.next(); + PProgram node1 = (PProgram) pop().get(0); + Start node = new Start(node1, node2); + return node; + } + case ERROR: + throw new ParserException(this.last_token, + "[" + this.last_line + "," + this.last_pos + "] " + + Parser.errorMessages[Parser.errors[this.action[1]]]); + } + } + } + + + + @SuppressWarnings("unchecked") + ArrayList new0() /* reduce AAprogram1Program */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + PProgram pprogramNode1; + { + // Block + LinkedList listNode2 = new LinkedList(); + LinkedList listNode3 = new LinkedList(); + { + // Block + } + { + // Block + } + + pprogramNode1 = new AProgram(listNode2, listNode3); + } + nodeList.add(pprogramNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new1() /* reduce AAprogram2Program */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PProgram pprogramNode1; + { + // Block + LinkedList listNode3 = new LinkedList(); + LinkedList listNode4 = new LinkedList(); + { + // Block + LinkedList listNode2 = new LinkedList(); + listNode2 = (LinkedList)nodeArrayList1.get(0); + if(listNode2 != null) + { + listNode3.addAll(listNode2); + } + } + { + // Block + } + + pprogramNode1 = new AProgram(listNode3, listNode4); + } + nodeList.add(pprogramNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new2() /* reduce AAprogram3Program */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PProgram pprogramNode1; + { + // Block + LinkedList listNode2 = new LinkedList(); + LinkedList listNode4 = new LinkedList(); + { + // Block + } + { + // Block + LinkedList listNode3 = new LinkedList(); + listNode3 = (LinkedList)nodeArrayList1.get(0); + if(listNode3 != null) + { + listNode4.addAll(listNode3); + } + } + + pprogramNode1 = new AProgram(listNode2, listNode4); + } + nodeList.add(pprogramNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new3() /* reduce AAprogram4Program */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PProgram pprogramNode1; + { + // Block + LinkedList listNode3 = new LinkedList(); + LinkedList listNode5 = new LinkedList(); + { + // Block + LinkedList listNode2 = new LinkedList(); + listNode2 = (LinkedList)nodeArrayList1.get(0); + if(listNode2 != null) + { + listNode3.addAll(listNode2); + } + } + { + // Block + LinkedList listNode4 = new LinkedList(); + listNode4 = (LinkedList)nodeArrayList2.get(0); + if(listNode4 != null) + { + listNode5.addAll(listNode4); + } + } + + pprogramNode1 = new AProgram(listNode3, listNode5); + } + nodeList.add(pprogramNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new4() /* reduce AAclassdecl1ClassDecl */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PClassDecl pclassdeclNode1; + { + // Block + TKclass tkclassNode2; + TName tnameNode3; + @SuppressWarnings("unused") Object nullNode4 = null; + @SuppressWarnings("unused") Object nullNode5 = null; + TKend tkendNode6; + tkclassNode2 = (TKclass)nodeArrayList1.get(0); + tnameNode3 = (TName)nodeArrayList2.get(0); + tkendNode6 = (TKend)nodeArrayList3.get(0); + + pclassdeclNode1 = new AClassDecl(tkclassNode2, tnameNode3, null, null, tkendNode6); + } + nodeList.add(pclassdeclNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new5() /* reduce AAclassdecl2ClassDecl */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PClassDecl pclassdeclNode1; + { + // Block + TKclass tkclassNode2; + TName tnameNode3; + PFormalDecls pformaldeclsNode4; + @SuppressWarnings("unused") Object nullNode5 = null; + TKend tkendNode6; + tkclassNode2 = (TKclass)nodeArrayList1.get(0); + tnameNode3 = (TName)nodeArrayList2.get(0); + pformaldeclsNode4 = (PFormalDecls)nodeArrayList3.get(0); + tkendNode6 = (TKend)nodeArrayList4.get(0); + + pclassdeclNode1 = new AClassDecl(tkclassNode2, tnameNode3, pformaldeclsNode4, null, tkendNode6); + } + nodeList.add(pclassdeclNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new6() /* reduce AAclassdecl3ClassDecl */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PClassDecl pclassdeclNode1; + { + // Block + TKclass tkclassNode2; + TName tnameNode3; + @SuppressWarnings("unused") Object nullNode4 = null; + PSuperDecls psuperdeclsNode5; + TKend tkendNode6; + tkclassNode2 = (TKclass)nodeArrayList1.get(0); + tnameNode3 = (TName)nodeArrayList2.get(0); + psuperdeclsNode5 = (PSuperDecls)nodeArrayList3.get(0); + tkendNode6 = (TKend)nodeArrayList4.get(0); + + pclassdeclNode1 = new AClassDecl(tkclassNode2, tnameNode3, null, psuperdeclsNode5, tkendNode6); + } + nodeList.add(pclassdeclNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new7() /* reduce AAclassdecl4ClassDecl */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList5 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PClassDecl pclassdeclNode1; + { + // Block + TKclass tkclassNode2; + TName tnameNode3; + PFormalDecls pformaldeclsNode4; + PSuperDecls psuperdeclsNode5; + TKend tkendNode6; + tkclassNode2 = (TKclass)nodeArrayList1.get(0); + tnameNode3 = (TName)nodeArrayList2.get(0); + pformaldeclsNode4 = (PFormalDecls)nodeArrayList3.get(0); + psuperdeclsNode5 = (PSuperDecls)nodeArrayList4.get(0); + tkendNode6 = (TKend)nodeArrayList5.get(0); + + pclassdeclNode1 = new AClassDecl(tkclassNode2, tnameNode3, pformaldeclsNode4, psuperdeclsNode5, tkendNode6); + } + nodeList.add(pclassdeclNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new8() /* reduce AFormalDecls */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PFormalDecls pformaldeclsNode1; + { + // Block + TLb tlbNode2; + LinkedList listNode4 = new LinkedList(); + TRb trbNode5; + tlbNode2 = (TLb)nodeArrayList1.get(0); + { + // Block + LinkedList listNode3 = new LinkedList(); + listNode3 = (LinkedList)nodeArrayList2.get(0); + if(listNode3 != null) + { + listNode4.addAll(listNode3); + } + } + trbNode5 = (TRb)nodeArrayList3.get(0); + + pformaldeclsNode1 = new AFormalDecls(tlbNode2, listNode4, trbNode5); + } + nodeList.add(pformaldeclsNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new9() /* reduce AAformaldecl1FormalDecl */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PFormalDecl pformaldeclNode1; + { + // Block + TName tnameNode2; + LinkedList listNode3 = new LinkedList(); + tnameNode2 = (TName)nodeArrayList1.get(0); + { + // Block + } + + pformaldeclNode1 = new AFormalDecl(tnameNode2, listNode3); + } + nodeList.add(pformaldeclNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new10() /* reduce AAformaldecl2FormalDecl */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PFormalDecl pformaldeclNode1; + { + // Block + TName tnameNode2; + LinkedList listNode4 = new LinkedList(); + tnameNode2 = (TName)nodeArrayList1.get(0); + { + // Block + LinkedList listNode3 = new LinkedList(); + listNode3 = (LinkedList)nodeArrayList2.get(0); + if(listNode3 != null) + { + listNode4.addAll(listNode3); + } + } + + pformaldeclNode1 = new AFormalDecl(tnameNode2, listNode4); + } + nodeList.add(pformaldeclNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new11() /* reduce AAdditionalFormalTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PAdditionalFormalTypes padditionalformaltypesNode1; + { + // Block + TComma tcommaNode2; + TName tnameNode3; + tcommaNode2 = (TComma)nodeArrayList1.get(0); + tnameNode3 = (TName)nodeArrayList2.get(0); + + padditionalformaltypesNode1 = new AAdditionalFormalTypes(tcommaNode2, tnameNode3); + } + nodeList.add(padditionalformaltypesNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new12() /* reduce AAtype1Type */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PType ptypeNode1; + { + // Block + TName tnameNode2; + @SuppressWarnings("unused") Object nullNode3 = null; + tnameNode2 = (TName)nodeArrayList1.get(0); + + ptypeNode1 = new AType(tnameNode2, null); + } + nodeList.add(ptypeNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new13() /* reduce AAtype2Type */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PType ptypeNode1; + { + // Block + TName tnameNode2; + PGenericPart pgenericpartNode3; + tnameNode2 = (TName)nodeArrayList1.get(0); + pgenericpartNode3 = (PGenericPart)nodeArrayList2.get(0); + + ptypeNode1 = new AType(tnameNode2, pgenericpartNode3); + } + nodeList.add(ptypeNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new14() /* reduce AGenericPart */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PGenericPart pgenericpartNode1; + { + // Block + TLb tlbNode2; + PGenericTypes pgenerictypesNode3; + TRb trbNode4; + tlbNode2 = (TLb)nodeArrayList1.get(0); + pgenerictypesNode3 = (PGenericTypes)nodeArrayList2.get(0); + trbNode4 = (TRb)nodeArrayList3.get(0); + + pgenericpartNode1 = new AGenericPart(tlbNode2, pgenerictypesNode3, trbNode4); + } + nodeList.add(pgenericpartNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new15() /* reduce AAgenerictypes1GenericTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PGenericTypes pgenerictypesNode1; + { + // Block + PType ptypeNode2; + LinkedList listNode3 = new LinkedList(); + ptypeNode2 = (PType)nodeArrayList1.get(0); + { + // Block + } + + pgenerictypesNode1 = new AGenericTypes(ptypeNode2, listNode3); + } + nodeList.add(pgenerictypesNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new16() /* reduce AAgenerictypes2GenericTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PGenericTypes pgenerictypesNode1; + { + // Block + PType ptypeNode2; + LinkedList listNode4 = new LinkedList(); + ptypeNode2 = (PType)nodeArrayList1.get(0); + { + // Block + LinkedList listNode3 = new LinkedList(); + listNode3 = (LinkedList)nodeArrayList2.get(0); + if(listNode3 != null) + { + listNode4.addAll(listNode3); + } + } + + pgenerictypesNode1 = new AGenericTypes(ptypeNode2, listNode4); + } + nodeList.add(pgenerictypesNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new17() /* reduce AAdditionalTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PAdditionalTypes padditionaltypesNode1; + { + // Block + TComma tcommaNode2; + PType ptypeNode3; + tcommaNode2 = (TComma)nodeArrayList1.get(0); + ptypeNode3 = (PType)nodeArrayList2.get(0); + + padditionaltypesNode1 = new AAdditionalTypes(tcommaNode2, ptypeNode3); + } + nodeList.add(padditionaltypesNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new18() /* reduce AAsuperdecls1SuperDecls */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PSuperDecls psuperdeclsNode1; + { + // Block + TKsuper tksuperNode2; + PSuperType psupertypeNode3; + LinkedList listNode4 = new LinkedList(); + tksuperNode2 = (TKsuper)nodeArrayList1.get(0); + psupertypeNode3 = (PSuperType)nodeArrayList2.get(0); + { + // Block + } + + psuperdeclsNode1 = new ASuperDecls(tksuperNode2, psupertypeNode3, listNode4); + } + nodeList.add(psuperdeclsNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new19() /* reduce AAsuperdecls2SuperDecls */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PSuperDecls psuperdeclsNode1; + { + // Block + TKsuper tksuperNode2; + PSuperType psupertypeNode3; + LinkedList listNode5 = new LinkedList(); + tksuperNode2 = (TKsuper)nodeArrayList1.get(0); + psupertypeNode3 = (PSuperType)nodeArrayList2.get(0); + { + // Block + LinkedList listNode4 = new LinkedList(); + listNode4 = (LinkedList)nodeArrayList3.get(0); + if(listNode4 != null) + { + listNode5.addAll(listNode4); + } + } + + psuperdeclsNode1 = new ASuperDecls(tksuperNode2, psupertypeNode3, listNode5); + } + nodeList.add(psuperdeclsNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new20() /* reduce AAdditionalSupers */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PAdditionalSupers padditionalsupersNode1; + { + // Block + TComma tcommaNode2; + PSuperType psupertypeNode3; + tcommaNode2 = (TComma)nodeArrayList1.get(0); + psupertypeNode3 = (PSuperType)nodeArrayList2.get(0); + + padditionalsupersNode1 = new AAdditionalSupers(tcommaNode2, psupertypeNode3); + } + nodeList.add(padditionalsupersNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new21() /* reduce AAsupertype1SuperType */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PSuperType psupertypeNode1; + { + // Block + TName tnameNode2; + @SuppressWarnings("unused") Object nullNode3 = null; + tnameNode2 = (TName)nodeArrayList1.get(0); + + psupertypeNode1 = new ASuperType(tnameNode2, null); + } + nodeList.add(psupertypeNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new22() /* reduce AAsupertype2SuperType */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PSuperType psupertypeNode1; + { + // Block + TName tnameNode2; + PSuperGenericPart psupergenericpartNode3; + tnameNode2 = (TName)nodeArrayList1.get(0); + psupergenericpartNode3 = (PSuperGenericPart)nodeArrayList2.get(0); + + psupertypeNode1 = new ASuperType(tnameNode2, psupergenericpartNode3); + } + nodeList.add(psupertypeNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new23() /* reduce ASuperGenericPart */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PSuperGenericPart psupergenericpartNode1; + { + // Block + TLb tlbNode2; + PSuperGenericTypes psupergenerictypesNode3; + TRb trbNode4; + tlbNode2 = (TLb)nodeArrayList1.get(0); + psupergenerictypesNode3 = (PSuperGenericTypes)nodeArrayList2.get(0); + trbNode4 = (TRb)nodeArrayList3.get(0); + + psupergenericpartNode1 = new ASuperGenericPart(tlbNode2, psupergenerictypesNode3, trbNode4); + } + nodeList.add(psupergenericpartNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new24() /* reduce AAsupergenerictypes1SuperGenericTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PSuperGenericTypes psupergenerictypesNode1; + { + // Block + PSuperType psupertypeNode2; + LinkedList listNode3 = new LinkedList(); + psupertypeNode2 = (PSuperType)nodeArrayList1.get(0); + { + // Block + } + + psupergenerictypesNode1 = new ASuperGenericTypes(psupertypeNode2, listNode3); + } + nodeList.add(psupergenerictypesNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new25() /* reduce AAsupergenerictypes2SuperGenericTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PSuperGenericTypes psupergenerictypesNode1; + { + // Block + PSuperType psupertypeNode2; + LinkedList listNode4 = new LinkedList(); + psupertypeNode2 = (PSuperType)nodeArrayList1.get(0); + { + // Block + LinkedList listNode3 = new LinkedList(); + listNode3 = (LinkedList)nodeArrayList2.get(0); + if(listNode3 != null) + { + listNode4.addAll(listNode3); + } + } + + psupergenerictypesNode1 = new ASuperGenericTypes(psupertypeNode2, listNode4); + } + nodeList.add(psupergenerictypesNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new26() /* reduce ASuperAdditionalTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PSuperAdditionalTypes psuperadditionaltypesNode1; + { + // Block + TComma tcommaNode2; + PSuperType psupertypeNode3; + tcommaNode2 = (TComma)nodeArrayList1.get(0); + psupertypeNode3 = (PSuperType)nodeArrayList2.get(0); + + psuperadditionaltypesNode1 = new ASuperAdditionalTypes(tcommaNode2, psupertypeNode3); + } + nodeList.add(psuperadditionaltypesNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new27() /* reduce AIsaInstr */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + PInstr pinstrNode1; + { + // Block + PType ptypeNode2; + TKisa tkisaNode3; + PType ptypeNode4; + ptypeNode2 = (PType)nodeArrayList1.get(0); + tkisaNode3 = (TKisa)nodeArrayList2.get(0); + ptypeNode4 = (PType)nodeArrayList3.get(0); + + pinstrNode1 = new AIsaInstr(ptypeNode2, tkisaNode3, ptypeNode4); + } + nodeList.add(pinstrNode1); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new28() /* reduce ATerminal$ClassDecl */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode2 = new LinkedList(); + { + // Block + PClassDecl pclassdeclNode1; + pclassdeclNode1 = (PClassDecl)nodeArrayList1.get(0); + if(pclassdeclNode1 != null) + { + listNode2.add(pclassdeclNode1); + } + } + nodeList.add(listNode2); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new29() /* reduce ANonTerminal$ClassDecl */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode3 = new LinkedList(); + { + // Block + LinkedList listNode1 = new LinkedList(); + PClassDecl pclassdeclNode2; + listNode1 = (LinkedList)nodeArrayList1.get(0); + pclassdeclNode2 = (PClassDecl)nodeArrayList2.get(0); + if(listNode1 != null) + { + listNode3.addAll(listNode1); + } + if(pclassdeclNode2 != null) + { + listNode3.add(pclassdeclNode2); + } + } + nodeList.add(listNode3); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new30() /* reduce ATerminal$Instr */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode2 = new LinkedList(); + { + // Block + PInstr pinstrNode1; + pinstrNode1 = (PInstr)nodeArrayList1.get(0); + if(pinstrNode1 != null) + { + listNode2.add(pinstrNode1); + } + } + nodeList.add(listNode2); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new31() /* reduce ANonTerminal$Instr */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode3 = new LinkedList(); + { + // Block + LinkedList listNode1 = new LinkedList(); + PInstr pinstrNode2; + listNode1 = (LinkedList)nodeArrayList1.get(0); + pinstrNode2 = (PInstr)nodeArrayList2.get(0); + if(listNode1 != null) + { + listNode3.addAll(listNode1); + } + if(pinstrNode2 != null) + { + listNode3.add(pinstrNode2); + } + } + nodeList.add(listNode3); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new32() /* reduce ATerminal$FormalDecl */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode2 = new LinkedList(); + { + // Block + PFormalDecl pformaldeclNode1; + pformaldeclNode1 = (PFormalDecl)nodeArrayList1.get(0); + if(pformaldeclNode1 != null) + { + listNode2.add(pformaldeclNode1); + } + } + nodeList.add(listNode2); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new33() /* reduce ANonTerminal$FormalDecl */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode3 = new LinkedList(); + { + // Block + LinkedList listNode1 = new LinkedList(); + PFormalDecl pformaldeclNode2; + listNode1 = (LinkedList)nodeArrayList1.get(0); + pformaldeclNode2 = (PFormalDecl)nodeArrayList2.get(0); + if(listNode1 != null) + { + listNode3.addAll(listNode1); + } + if(pformaldeclNode2 != null) + { + listNode3.add(pformaldeclNode2); + } + } + nodeList.add(listNode3); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new34() /* reduce ATerminal$AdditionalFormalTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode2 = new LinkedList(); + { + // Block + PAdditionalFormalTypes padditionalformaltypesNode1; + padditionalformaltypesNode1 = (PAdditionalFormalTypes)nodeArrayList1.get(0); + if(padditionalformaltypesNode1 != null) + { + listNode2.add(padditionalformaltypesNode1); + } + } + nodeList.add(listNode2); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new35() /* reduce ANonTerminal$AdditionalFormalTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode3 = new LinkedList(); + { + // Block + LinkedList listNode1 = new LinkedList(); + PAdditionalFormalTypes padditionalformaltypesNode2; + listNode1 = (LinkedList)nodeArrayList1.get(0); + padditionalformaltypesNode2 = (PAdditionalFormalTypes)nodeArrayList2.get(0); + if(listNode1 != null) + { + listNode3.addAll(listNode1); + } + if(padditionalformaltypesNode2 != null) + { + listNode3.add(padditionalformaltypesNode2); + } + } + nodeList.add(listNode3); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new36() /* reduce ATerminal$AdditionalTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode2 = new LinkedList(); + { + // Block + PAdditionalTypes padditionaltypesNode1; + padditionaltypesNode1 = (PAdditionalTypes)nodeArrayList1.get(0); + if(padditionaltypesNode1 != null) + { + listNode2.add(padditionaltypesNode1); + } + } + nodeList.add(listNode2); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new37() /* reduce ANonTerminal$AdditionalTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode3 = new LinkedList(); + { + // Block + LinkedList listNode1 = new LinkedList(); + PAdditionalTypes padditionaltypesNode2; + listNode1 = (LinkedList)nodeArrayList1.get(0); + padditionaltypesNode2 = (PAdditionalTypes)nodeArrayList2.get(0); + if(listNode1 != null) + { + listNode3.addAll(listNode1); + } + if(padditionaltypesNode2 != null) + { + listNode3.add(padditionaltypesNode2); + } + } + nodeList.add(listNode3); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new38() /* reduce ATerminal$AdditionalSupers */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode2 = new LinkedList(); + { + // Block + PAdditionalSupers padditionalsupersNode1; + padditionalsupersNode1 = (PAdditionalSupers)nodeArrayList1.get(0); + if(padditionalsupersNode1 != null) + { + listNode2.add(padditionalsupersNode1); + } + } + nodeList.add(listNode2); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new39() /* reduce ANonTerminal$AdditionalSupers */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode3 = new LinkedList(); + { + // Block + LinkedList listNode1 = new LinkedList(); + PAdditionalSupers padditionalsupersNode2; + listNode1 = (LinkedList)nodeArrayList1.get(0); + padditionalsupersNode2 = (PAdditionalSupers)nodeArrayList2.get(0); + if(listNode1 != null) + { + listNode3.addAll(listNode1); + } + if(padditionalsupersNode2 != null) + { + listNode3.add(padditionalsupersNode2); + } + } + nodeList.add(listNode3); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new40() /* reduce ATerminal$SuperAdditionalTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode2 = new LinkedList(); + { + // Block + PSuperAdditionalTypes psuperadditionaltypesNode1; + psuperadditionaltypesNode1 = (PSuperAdditionalTypes)nodeArrayList1.get(0); + if(psuperadditionaltypesNode1 != null) + { + listNode2.add(psuperadditionaltypesNode1); + } + } + nodeList.add(listNode2); + return nodeList; + } + + + + @SuppressWarnings("unchecked") + ArrayList new41() /* reduce ANonTerminal$SuperAdditionalTypes */ + { + @SuppressWarnings("hiding") ArrayList nodeList = new ArrayList(); + + @SuppressWarnings("unused") ArrayList nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList nodeArrayList1 = pop(); + LinkedList listNode3 = new LinkedList(); + { + // Block + LinkedList listNode1 = new LinkedList(); + PSuperAdditionalTypes psuperadditionaltypesNode2; + listNode1 = (LinkedList)nodeArrayList1.get(0); + psuperadditionaltypesNode2 = (PSuperAdditionalTypes)nodeArrayList2.get(0); + if(listNode1 != null) + { + listNode3.addAll(listNode1); + } + if(psuperadditionaltypesNode2 != null) + { + listNode3.add(psuperadditionaltypesNode2); + } + } + nodeList.add(listNode3); + return nodeList; + } + + + + private static int[][][] actionTable; +/* { + {{-1, REDUCE, 0}, {5, SHIFT, 1}, {8, SHIFT, 2}, }, + {{-1, ERROR, 1}, {8, SHIFT, 9}, }, + {{-1, REDUCE, 12}, {1, SHIFT, 10}, }, + {{-1, ERROR, 3}, {9, ACCEPT, -1}, }, + {{-1, REDUCE, 28}, }, + {{-1, ERROR, 5}, {4, SHIFT, 12}, }, + {{-1, REDUCE, 30}, }, + {{-1, REDUCE, 1}, {5, SHIFT, 1}, {8, SHIFT, 2}, }, + {{-1, REDUCE, 2}, {8, SHIFT, 2}, }, + {{-1, ERROR, 9}, {1, SHIFT, 16}, {3, SHIFT, 17}, {6, SHIFT, 18}, }, + {{-1, ERROR, 10}, {8, SHIFT, 2}, }, + {{-1, REDUCE, 13}, }, + {{-1, ERROR, 12}, {8, SHIFT, 2}, }, + {{-1, REDUCE, 29}, }, + {{-1, REDUCE, 3}, {8, SHIFT, 2}, }, + {{-1, REDUCE, 31}, }, + {{-1, ERROR, 16}, {8, SHIFT, 24}, }, + {{-1, REDUCE, 4}, }, + {{-1, ERROR, 18}, {8, SHIFT, 27}, }, + {{-1, ERROR, 19}, {3, SHIFT, 29}, {6, SHIFT, 18}, }, + {{-1, ERROR, 20}, {3, SHIFT, 31}, }, + {{-1, REDUCE, 15}, {0, SHIFT, 32}, }, + {{-1, ERROR, 22}, {2, SHIFT, 35}, }, + {{-1, REDUCE, 27}, }, + {{-1, REDUCE, 9}, {0, SHIFT, 36}, }, + {{-1, REDUCE, 32}, }, + {{-1, ERROR, 26}, {2, SHIFT, 39}, {8, SHIFT, 24}, }, + {{-1, REDUCE, 21}, {1, SHIFT, 41}, }, + {{-1, REDUCE, 18}, {0, SHIFT, 43}, }, + {{-1, REDUCE, 5}, }, + {{-1, ERROR, 30}, {3, SHIFT, 46}, }, + {{-1, REDUCE, 6}, }, + {{-1, ERROR, 32}, {8, SHIFT, 2}, }, + {{-1, REDUCE, 36}, }, + {{-1, REDUCE, 16}, {0, SHIFT, 32}, }, + {{-1, REDUCE, 14}, }, + {{-1, ERROR, 36}, {8, SHIFT, 49}, }, + {{-1, REDUCE, 34}, }, + {{-1, REDUCE, 10}, {0, SHIFT, 36}, }, + {{-1, REDUCE, 8}, }, + {{-1, REDUCE, 33}, }, + {{-1, ERROR, 41}, {8, SHIFT, 27}, }, + {{-1, REDUCE, 22}, }, + {{-1, ERROR, 43}, {8, SHIFT, 27}, }, + {{-1, REDUCE, 38}, }, + {{-1, REDUCE, 19}, {0, SHIFT, 43}, }, + {{-1, REDUCE, 7}, }, + {{-1, REDUCE, 17}, }, + {{-1, REDUCE, 37}, }, + {{-1, REDUCE, 11}, }, + {{-1, REDUCE, 35}, }, + {{-1, REDUCE, 24}, {0, SHIFT, 55}, }, + {{-1, ERROR, 52}, {2, SHIFT, 58}, }, + {{-1, REDUCE, 20}, }, + {{-1, REDUCE, 39}, }, + {{-1, ERROR, 55}, {8, SHIFT, 27}, }, + {{-1, REDUCE, 40}, }, + {{-1, REDUCE, 25}, {0, SHIFT, 55}, }, + {{-1, REDUCE, 23}, }, + {{-1, REDUCE, 26}, }, + {{-1, REDUCE, 41}, }, + };*/ + private static int[][][] gotoTable; +/* { + {{-1, 3}, }, + {{-1, 4}, {7, 13}, }, + {{-1, 19}, }, + {{-1, 25}, {26, 40}, }, + {{-1, 37}, {38, 50}, }, + {{-1, 5}, {10, 21}, {12, 23}, {32, 47}, }, + {{-1, 11}, }, + {{-1, 22}, }, + {{-1, 33}, {34, 48}, }, + {{-1, 20}, {19, 30}, }, + {{-1, 44}, {45, 54}, }, + {{-1, 28}, {41, 51}, {43, 53}, {55, 59}, }, + {{-1, 42}, }, + {{-1, 52}, }, + {{-1, 56}, {57, 60}, }, + {{-1, 6}, {8, 15}, {14, 15}, }, + {{-1, 7}, }, + {{-1, 8}, {7, 14}, }, + {{-1, 26}, }, + {{-1, 38}, }, + {{-1, 34}, }, + {{-1, 45}, }, + {{-1, 57}, }, + };*/ + private static String[] errorMessages; +/* { + "expecting: 'class', name, EOF", + "expecting: name", + "expecting: ',', '[', ']', 'isa', name, EOF", + "expecting: EOF", + "expecting: 'isa'", + "expecting: name, EOF", + "expecting: '[', 'end', 'super'", + "expecting: ',', ']', 'isa', name, EOF", + "expecting: 'end', 'super'", + "expecting: 'end'", + "expecting: ',', ']'", + "expecting: ']'", + "expecting: ',', ']', name", + "expecting: ']', name", + "expecting: ',', '[', ']', 'end'", + "expecting: ',', 'end'", + "expecting: ',', ']', 'end'", + };*/ + private static int[] errors; +/* { + 0, 1, 2, 3, 0, 4, 5, 0, 5, 6, 1, 7, 1, 0, 5, 5, 1, 0, 1, 8, 9, 10, 11, 5, 12, 13, 13, 14, 15, 0, 9, 0, 1, 10, 10, 7, 1, 12, 12, 8, 13, 1, 16, 1, 15, 15, 0, 10, 10, 12, 12, 10, 11, 15, 15, 1, 10, 10, 16, 10, 10, + };*/ + + static + { + try + { + DataInputStream s = new DataInputStream( + new BufferedInputStream( + Parser.class.getResourceAsStream("parser.dat"))); + + // read actionTable + int length = s.readInt(); + Parser.actionTable = new int[length][][]; + for(int i = 0; i < Parser.actionTable.length; i++) + { + length = s.readInt(); + Parser.actionTable[i] = new int[length][3]; + for(int j = 0; j < Parser.actionTable[i].length; j++) + { + for(int k = 0; k < 3; k++) + { + Parser.actionTable[i][j][k] = s.readInt(); + } + } + } + + // read gotoTable + length = s.readInt(); + gotoTable = new int[length][][]; + for(int i = 0; i < gotoTable.length; i++) + { + length = s.readInt(); + gotoTable[i] = new int[length][2]; + for(int j = 0; j < gotoTable[i].length; j++) + { + for(int k = 0; k < 2; k++) + { + gotoTable[i][j][k] = s.readInt(); + } + } + } + + // read errorMessages + length = s.readInt(); + errorMessages = new String[length]; + for(int i = 0; i < errorMessages.length; i++) + { + length = s.readInt(); + StringBuffer buffer = new StringBuffer(); + + for(int j = 0; j < length; j++) + { + buffer.append(s.readChar()); + } + errorMessages[i] = buffer.toString(); + } + + // read errors + length = s.readInt(); + errors = new int[length]; + for(int i = 0; i < errors.length; i++) + { + errors[i] = s.readInt(); + } + + s.close(); + } + catch(Exception e) + { + throw new RuntimeException("The file \"parser.dat\" is either missing or corrupted."); + } + } +} diff --git a/src/minigen/syntax3/parser/ParserException.java b/src/minigen/syntax3/parser/ParserException.java new file mode 100644 index 0000000..95ee7bc --- /dev/null +++ b/src/minigen/syntax3/parser/ParserException.java @@ -0,0 +1,22 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.parser; + +import minigen.syntax3.node.*; + +@SuppressWarnings("serial") +public class ParserException extends Exception +{ + Token token; + + public ParserException(@SuppressWarnings("hiding") Token token, String message) + { + super(message); + this.token = token; + } + + public Token getToken() + { + return this.token; + } +} diff --git a/src/minigen/syntax3/parser/State.java b/src/minigen/syntax3/parser/State.java new file mode 100644 index 0000000..0471b34 --- /dev/null +++ b/src/minigen/syntax3/parser/State.java @@ -0,0 +1,17 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.parser; + +import java.util.ArrayList; + +final class State +{ + int state; + ArrayList nodes; + + State(@SuppressWarnings("hiding") int state, @SuppressWarnings("hiding") ArrayList nodes) + { + this.state = state; + this.nodes = nodes; + } +} diff --git a/src/minigen/syntax3/parser/TokenIndex.java b/src/minigen/syntax3/parser/TokenIndex.java new file mode 100644 index 0000000..d7bc986 --- /dev/null +++ b/src/minigen/syntax3/parser/TokenIndex.java @@ -0,0 +1,71 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package minigen.syntax3.parser; + +import minigen.syntax3.node.*; +import minigen.syntax3.analysis.*; + +class TokenIndex extends AnalysisAdapter +{ + int index; + + @Override + public void caseTComma(@SuppressWarnings("unused") TComma node) + { + this.index = 0; + } + + @Override + public void caseTLb(@SuppressWarnings("unused") TLb node) + { + this.index = 1; + } + + @Override + public void caseTRb(@SuppressWarnings("unused") TRb node) + { + this.index = 2; + } + + @Override + public void caseTKend(@SuppressWarnings("unused") TKend node) + { + this.index = 3; + } + + @Override + public void caseTKisa(@SuppressWarnings("unused") TKisa node) + { + this.index = 4; + } + + @Override + public void caseTKclass(@SuppressWarnings("unused") TKclass node) + { + this.index = 5; + } + + @Override + public void caseTKsuper(@SuppressWarnings("unused") TKsuper node) + { + this.index = 6; + } + + @Override + public void caseTKnew(@SuppressWarnings("unused") TKnew node) + { + this.index = 7; + } + + @Override + public void caseTName(@SuppressWarnings("unused") TName node) + { + this.index = 8; + } + + @Override + public void caseEOF(@SuppressWarnings("unused") EOF node) + { + this.index = 9; + } +} diff --git a/src/minigen/syntax3/parser/parser.dat b/src/minigen/syntax3/parser/parser.dat new file mode 100644 index 0000000..7e7e97e Binary files /dev/null and b/src/minigen/syntax3/parser/parser.dat differ