Updates to grammar...
authorbdemsky <bdemsky>
Thu, 8 Jul 2004 03:50:19 +0000 (03:50 +0000)
committerbdemsky <bdemsky>
Thu, 8 Jul 2004 03:50:19 +0000 (03:50 +0000)
Repair/RepairCompiler/MCC/CDL.cup
Repair/RepairCompiler/MCC/IR/SemanticChecker.java
Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java
Repair/RepairCompiler/MCC/IR/TypeDescriptor.java
Repair/RepairCompiler/MCC/Lexer.lex
Repair/RepairCompiler/MCC/MDL.cup
Repair/RepairCompiler/MCC/SDL.cup
Repair/RepairCompiler/MCC/TDL.cup

index 4206e84..2f7f2da 100755 (executable)
@@ -175,6 +175,7 @@ parser code {:
     terminal LABEL;
     terminal INT;
     terminal SUBTYPE;
+    terminal SUBCLASS;
     terminal OF;
 
     terminal SEMICOLON;
index c35feaf..4dacc0b 100755 (executable)
@@ -1070,6 +1070,19 @@ public class SemanticChecker {
 
             /* lookup the type to get the type descriptor */
             type.setSuperType(lookupType(subtype, CREATE_MISSING));
+        } else if (pn.getChild("subclass") != null) {
+            // has a subtype, lets try to resolve it
+            String subclass = pn.getChild("subclass").getTerminal();
+           
+            if (subclass.equals(typename)) {
+                // Semantic Error: cyclic inheritance
+                er.report(pn, "Cyclic inheritance prohibited");
+                ok = false;
+            }
+
+            /* lookup the type to get the type descriptor */
+            type.setSuperType(lookupType(subclass, CREATE_MISSING));
+            type.setSubClass(true);
         }
 
         // set the current type so that the recursive parses on the labels
index 347d1f9..4a2b55a 100755 (executable)
@@ -29,6 +29,10 @@ public class StructureTypeDescriptor extends TypeDescriptor {
         return fields.keys();
     }
     
+    public void setSubClass(boolean b) {
+       this.subclass=b;
+    }
+
     public Expr getSizeExpr() {
         return getOffsetExpr(null);
     }
index f71fe4f..6609229 100755 (executable)
@@ -9,6 +9,8 @@ package MCC.IR;
 public abstract class TypeDescriptor extends Descriptor {
     static int counter=0;
     int idnum;
+    boolean subclass;
+
 
     public int getId() {
        return idnum;
@@ -18,6 +20,7 @@ public abstract class TypeDescriptor extends Descriptor {
         super(name);
        if (!(this instanceof MissingTypeDescriptor))
            idnum=counter++;
+       subclass=false;
     }
 
     public boolean isSubtypeOf(TypeDescriptor td) {
index 6e630c0..ed6f239 100755 (executable)
@@ -82,6 +82,7 @@ CHAR=(\\\"|\\\'|\\\\|\\t|\\n|[\x20-\x21\x23-\x26\x28-\x5B\x5D-\x7E])
 <YYINITIAL> byte                        { return tok(Sym.BYTE, yytext()); }
 
 <YYINITIAL> subtype                    { return tok(Sym.SUBTYPE, yytext()); }
+<YYINITIAL> subclass                   { return tok(Sym.SUBCLASS, yytext()); }
 <YYINITIAL> of                                 { return tok(Sym.OF, yytext()); }
 
 <YYINITIAL> ";"                                { return tok(Sym.SEMICOLON, yytext()); }
index c7b00d0..54d3aeb 100755 (executable)
@@ -181,6 +181,7 @@ parser code {:
     terminal LABEL;
     terminal INT;
     terminal SUBTYPE;
+    terminal SUBCLASS;
     terminal OF;
 
     terminal SEMICOLON;
index 9792ebd..be328fe 100755 (executable)
@@ -164,6 +164,7 @@ parser code {:
     terminal LABEL;
     terminal INT;
     terminal SUBTYPE;
+    terminal SUBCLASS;
     terminal OF;
 
     terminal SEMICOLON;
index 5fbed22..0ae3eb5 100755 (executable)
@@ -162,6 +162,7 @@ parser code {:
     terminal LABEL;
     terminal INT;
     terminal SUBTYPE;
+    terminal SUBCLASS;
     terminal OF;
 
     terminal SEMICOLON;
@@ -256,7 +257,7 @@ structure ::=
        ;
 
 optsubtype ::= 
-          
+               /* subtype */
        SUBTYPE OF ID:type
        {:
        debugMessage(PRODSTRING);
@@ -264,6 +265,16 @@ optsubtype ::=
        subtype.addChild(type);
        RESULT = subtype;
        :}
+
+       | /* subclass */
+
+       SUBCLASS OF ID:type
+       {:
+       debugMessage(PRODSTRING);
+       ParseNode subtype = new ParseNode("subclass", parser.curLine(3));
+       subtype.addChild(type);
+       RESULT = subtype;
+       :}
        
        | /* nothing */
        {: