Diff of /c99.y [501682] .. [c307d5]  Maximize  Restore

Switch to side-by-side view

--- a/c99.y
+++ b/c99.y
@@ -24,8 +24,6 @@
 
 
 /* fifo to store expression strings */
-#define NULL 0
-
 #define STMT_SIZE 128
 #define FIFO_SIZE 20
 
@@ -63,7 +61,8 @@
 // map c datatype to iec (standard and userdefined)
 char *maptype(char *ctype);
 
-
+// lex/yacc functions
+extern int yylex (void);
 %}
 
 %%
@@ -106,9 +105,9 @@
 unary_expression
 	: postfix_expression
 	| INC_OP unary_expression
-	{ sprintf($<str>$, "%s %s",$<str>1, $<str>2); }
+	{ sprintf($<str>$, "(%s:=%s+1)",$<str>2, $<str>2); }
 	| DEC_OP unary_expression
-	{ sprintf($<str>$, "%s %s",$<str>1, $<str>2); }
+	{ sprintf($<str>$, "(%s:=%s-1)",$<str>2, $<str>2); }
 	| unary_operator cast_expression
 	{ sprintf($<str>$, "%s^",$<str>2); }
 	| SIZEOF unary_expression
@@ -139,7 +138,7 @@
 	| multiplicative_expression '/' cast_expression
 	{ sprintf($<str>$, "%s / %s",$<str>1, $<str>3); }
 	| multiplicative_expression '%' cast_expression
-	{ sprintf($<str>$, "%s % %s",$<str>1, $<str>3); }
+	{ sprintf($<str>$, "%s %s",$<str>1, $<str>3); }
 	;
 
 additive_expression
@@ -588,6 +587,7 @@
 	| DO statement WHILE '(' expression ')' ';'
 	| FOR '(' expression_statement expression_statement ')' statement
 	| FOR '(' expression_statement expression_statement expression ')' statement
+	{ sprintf($<str>$, "%s\nWHILE %s DO\n%s\n%s;\nEND_WHILE\n",$<str>3, $<str>4, $<str>7, $<str>5); }
 	| FOR '(' declaration expression_statement ')' statement
 	| FOR '(' declaration expression_statement expression ')' statement
 	;
@@ -620,10 +620,10 @@
 		char *p;
 		while( (p=fifo_pop(decl_all)) != NULL)
 		{
-			printf(p);
+			printf("%s", p);
 			printf("%s;\n", $<str>1);
 		}
-		printf($<str>3);
+		printf("%s", $<str>3);
 		strcpy($<str>$, "");
 	}
 	;