Browse Source

Added proper support for enumeration types in module trees

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@8631 8c9fc860-2736-0410-a75d-ab315db34111
negelef 6 years ago
parent
commit
460ed37683
2 changed files with 33 additions and 25 deletions
  1. 28 17
      source/ModuleParser.Mod
  2. 5 8
      source/PETModuleTree.Mod

+ 28 - 17
source/ModuleParser.Mod

@@ -92,7 +92,7 @@ TYPE
 		record*: Record;
 		pointer*: Pointer;
 		object*: Object;
-		enum*: Enum;
+		enumeration*: Enumeration;
 		cell*: Cell;
 		port*: Port;
 		procedure*: Procedure;
@@ -123,9 +123,10 @@ TYPE
 		type*: Type;
 	END Pointer;
 
-	Enum* = OBJECT(Node)
-	VAR identList*: IdentList;
-	END Enum;
+	Enumeration* = OBJECT(Node)
+	VAR
+		enumeratorList*: ConstDecl;
+	END Enumeration;
 
 	Port*= OBJECT(Node)
 	END Port;
@@ -828,7 +829,7 @@ TYPE
 			| FoxScanner.Object: NextToken; NEW(type.object, type); ObjectP(type.object);
 			| FoxScanner.Port: NextToken; NEW(type.port, type); PortP(type.port);
 			| FoxScanner.Cell, FoxScanner.CellNet: NextToken; NEW(type.cell, type); CellP(type.cell);
-			| FoxScanner.Enum: NextToken; NEW(type.enum, type); EnumP(type.enum);
+			| FoxScanner.Enum: NextToken; NEW(type.enumeration, type); EnumerationP(type.enumeration);
 			| FoxScanner.Procedure, FoxScanner.Operator: NextToken; NEW(type.procedure, type); ProcedureP(type.procedure);
 			| FoxScanner.Identifier: NEW(type.qualident, type); QualidentP(type.qualident);
 			| FoxScanner.Address, FoxScanner.Size: NEW(type.qualident, type); NEW(type.qualident.ident);
@@ -933,23 +934,33 @@ TYPE
 			TypeP(pointer.type);
 		END PointerP;
 
-		PROCEDURE EnumP(enum: Enum);
-		VAR identDef: IdentDef; identList: IdentList;
+		PROCEDURE EnumerationP(enumeration: Enumeration);
+		VAR identDef: IdentDef; enumerator: ConstDecl;
 		BEGIN
-			NEW(enum.identList, enum);
-			NEW(enum.identList.identDef);
-			IdentDefP(enum.identList.identDef);
-			SysFlag;
+			NEW(enumerator, enumeration);
+			EnumeratorP(enumerator);
+			enumeration.enumeratorList := enumerator;
 			WHILE token.symbol = FoxScanner.Comma DO
 				NextToken;	(* avoids endless loop *)
-				NEW(identDef);
-				IdentDefP(identDef);
-				NEW(identList, enum);
-				identList.identDef := identDef;
-				AppendLast(enum.identList, identList);
+				NEW(enumerator, enumeration);
+				EnumeratorP(enumerator);
+				AppendLast(enumeration.enumeratorList, enumerator);
 			END;
 			Check(FoxScanner.End);
-		END EnumP;
+		END EnumerationP;
+
+		PROCEDURE EnumeratorP(enumerator: ConstDecl);
+		BEGIN
+			NEW(enumerator.identDef);
+			IdentDefP(enumerator.identDef);
+			IF token.symbol = FoxScanner.Equal THEN
+				NextToken;
+				(* NEW(enumerator.constExpr);
+				ExprP(enumerator.constExpr); *)
+				NEW(enumerator.expr);
+				ConstExprP(FoxScanner.Comma, FoxScanner.End, enumerator.expr);
+			END;
+		END EnumeratorP;
 
 		PROCEDURE PortP(port: Port);
 		BEGIN

+ 5 - 8
source/PETModuleTree.Mod

@@ -657,8 +657,8 @@ TYPE
 					AddObject(parent, type.object, anonymous, TRUE);
 				ELSIF type.procedure # NIL THEN
 					AddProcedure(parent, type.procedure);
-				ELSIF type.enum # NIL THEN
-					AddEnum(parent, type.enum);
+				ELSIF type.enumeration # NIL THEN
+					AddEnumeration(parent, type.enumeration);
 				ELSIF type.cell # NIL THEN
 					AddCell(parent, type.cell, anonymous)
 				ELSIF type.port # NIL THEN
@@ -684,13 +684,10 @@ TYPE
 			END;
 		END AddRecord;
 
-		PROCEDURE AddEnum(parent: WMTrees.TreeNode; enum: ModuleParser.Enum);
-		VAR p: WMTrees.TreeNode; num: LONGINT;
+		PROCEDURE AddEnumeration(parent: WMTrees.TreeNode; enumeration: ModuleParser.Enumeration);
 		BEGIN
-			IF enum # NIL THEN
-				AddIdentList(parent, enum.identList,num);
-			END;
-		END AddEnum;
+			AddConstDecl(parent, enumeration.enumeratorList);
+		END AddEnumeration;
 
 		PROCEDURE AddFieldDecl(parent: WMTrees.TreeNode; fieldDecl: ModuleParser.FieldDecl);
 		VAR newNode: WMTrees.TreeNode; n, l: ModuleParser.NodeList;