--- a/c2iec.y
+++ b/c2iec.y
@@ -82,6 +82,9 @@
 
 // convert input string to upper case
 char *strUpper(char *szStr);
+
+// check if string a starts with string b
+int strStartsWith(const char *a, const char *b);
 
 // terminate string after identifier boundary
 char *strIdentifier(char *szStr);
@@ -320,17 +323,31 @@
 			printf(p, $<str>1);
 			isFuncDecl = 1;
 		}
-		while( (p=fifo_pop(decl_param)) != NULL)
-		{
+		if (!fifo_empty(decl_param))
+		{
+		    printf("\nVAR_IN_OUT\n");
+		    while( (p=fifo_pop(decl_param)) != NULL)
+		    {
 			printf(p, $<str>1);
 //			isFuncDecl = 0;
-		}
-		while( (p=fifo_pop(decl_all)) != NULL)
-		{
-			printf(p, $<str>1);
-			isFuncDecl = 0;
+		    }
+		    printf("\nEND_VAR\n");
+		}
+		if (!fifo_empty(decl_all))
+		{
+		    printf("\nVAR\n");
+		    while( (p=fifo_pop(decl_all)) != NULL)
+		    {
+			if (!strStartsWith(p, getFunctionName()))
+			{
+			    printf(p, $<str>1);
+			    isFuncDecl = 0;
+			}
+		    }
+		    printf("\nEND_VAR\n");
 		}
 		strcpy($<str>$, "");
+
 		if (isFuncDecl)
 		    printf("\nEND_FUNCTION\n\n");
 	}
@@ -978,6 +995,13 @@
 	return szStr;
 }
 
+int strStartsWith(const char *a, const char *b)
+{
+    if (strlen(b) > 0 && strncmp(a, b, strlen(b)) == 0)
+	return 1;
+    return 0;
+}
+
 char *strIdentifier(char *szStr)
 {
 	char *p;