Diff of /c2iec.y [aff3bf] .. [8e3d7b]  Maximize  Restore

Switch to side-by-side view

--- a/c2iec.y
+++ b/c2iec.y
@@ -68,6 +68,17 @@
 
 // convert input string to upper case
 char *strUpper(char *szStr);
+
+// terminate string after identifier boundary
+char *strIdentifier(char *szStr);
+
+// add symbol name to symbol table
+#define SYM_SIZE 64
+#define SYM_COUNT 64
+int s_iSymTabCount = 0;
+static char s_szSymTab[SYM_COUNT][SYM_SIZE];
+void addSym(char *szSym);
+int isSym(char *szSym);
 
 // lex/yacc functions
 extern int yylex (void);
@@ -252,6 +263,18 @@
 declaration
 	: declaration_specifiers ';'
 	{ sprintf($<str>$, "%s %s\n",$<str>1, $<str>2); }
+	| TYPEDEF declaration_specifiers init_declarator_list ';'
+	{
+		char *p;
+		while( (p=fifo_pop(decl_all)) != NULL)
+			/* noop */;
+
+		printf("TYPE ");
+		printf($<str>3, $<str>2);
+		addSym(strIdentifier($<str>3));
+		printf("END_TYPE\n\n");
+		strcpy($<str>$, "");
+	}
 	| declaration_specifiers init_declarator_list ';'
 	{
 		char *p;
@@ -371,6 +394,12 @@
 	| unnamed_struct_or_union_specifier ';'
 	;
 
+// as a lexxer hack, I added a special case for typedefs
+// to the declaration rule
+specifier_qualifier_list
+	: TYPEDEF type_specifier specifier_qualifier_list
+	{ sprintf($<str>$, "lexxer hack - typedef found\n"); }
+
 specifier_qualifier_list
 	: type_specifier specifier_qualifier_list
 	{ sprintf($<str>$, "%s %s",$<str>1, $<str>2); }
@@ -811,3 +840,46 @@
 	}
 	return szStr;
 }
+
+char *strIdentifier(char *szStr)
+{
+	char *p;
+	p = szStr;
+	while (*p != 0)
+	{
+		if ( (*p >= 'a' && *p <= 'z')
+		  || (*p >= 'A' && *p <= 'Z')
+		  || (*p >= '0' && *p <= '9')
+		  || (*p == '_') )
+		{
+			p++;
+		}
+		else
+		{
+			*p = '\0';
+			return szStr;
+		}
+	}
+	return szStr;
+}
+
+void addSym(char *szSym)
+{
+	int i;
+	i = s_iSymTabCount++;
+	strcpy(s_szSymTab[i], szSym);
+}
+
+int isSym(char *szSym)
+{
+	int i;
+	for (i=0; i < s_iSymTabCount; i++)
+	{
+		if (!strcmp(s_szSymTab[i], szSym))
+		{
+			return 1;
+		}
+	}
+	return 0;
+}
+