Diff of /c2iec.y [f05709] .. [77aa95]  Maximize  Restore

Switch to side-by-side view

--- a/c2iec.y
+++ b/c2iec.y
@@ -20,7 +20,7 @@
 #include <stdio.h>
 
 // get tail of a string
-#define TAIL(str) (&str[strlen(str)-1])
+#define TAIL(str) (&str[strlen(str)])
 
 
 /* fifo to store expression strings */
@@ -317,6 +317,10 @@
 
 struct_or_union_specifier
 	: struct_or_union IDENTIFIER '{' struct_declaration_list '}'
+	{
+		printf("TYPE %s:\nSTRUCT\n %s\nEND_STRUCT\nEND_TYPE\n", $<str>2, $<str>4);
+		strcpy($<str>$, "");
+	}
 	| struct_or_union '{' struct_declaration_list '}'
 	| struct_or_union IDENTIFIER
 	;
@@ -334,13 +338,23 @@
 
 struct_declaration
 	: specifier_qualifier_list struct_declarator_list ';'
-	{ sprintf($<str>$, "%s %s",$<str>1, $<str>2); }
+	{
+		char *p;
+		while( (p=fifo_pop(decl_all)) != NULL)
+		{
+			strcpy($<str>$, "");
+			sprintf(TAIL($<str>$), p, $<str>1);
+//			printf(p, $<str>1);
+//			strcpy($<str>$, "");
+		}
+	}
 	;
 
 specifier_qualifier_list
 	: type_specifier specifier_qualifier_list
 	{ sprintf($<str>$, "%s %s",$<str>1, $<str>2); }
 	| type_specifier
+	{ strcpy($<str>$, maptype($<str>1)); }
 	| type_qualifier specifier_qualifier_list
 	{ sprintf($<str>$, "%s %s",$<str>1, $<str>2); }
 	| type_qualifier
@@ -725,6 +739,10 @@
 		return "UDINT";
 	if (!strcmp(ctype, "unsigned LINT"))
 		return "ULINT";
+	if (!strcmp(ctype, "struct"))
+		return "STRUCT";
+	if (!strcmp(ctype, ""))
+		return "";
 	printf("maptype: not found: %s\n", ctype);
 	return ctype;
 }