--- a/stage1_2/iec.y Thu Nov 15 15:43:34 2007 +0100
+++ b/stage1_2/iec.y Fri Nov 16 13:45:14 2007 +0100
@@ -1,5 +1,5 @@
/*
- * (c) 2003 Mario de Sousa
+ * (c) 2003-2007 Mario de Sousa
*
* Offered to the public under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of the
@@ -15,7 +15,7 @@
*/
/*
- * An IEC 61131-3 IL and ST compiler.
+ * An IEC 61131-3 IL, ST and SFC compiler.
*
* Based on the
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
@@ -27,9 +27,9 @@
* =======
*
* This file contains the syntax definition of the textual
- * languages IL and ST. The syntax parser, comprising the
- * 2nd stage of the overall compiler, is generated by runing
- * bison on this file.
+ * languages IL and ST, as well as the textual version of SFC.
+ * The syntax parser, comprising the 2nd stage of the overall
+ * compiler, is generated by runing bison on this file.
*/
@@ -172,10 +172,13 @@
symbol_c *leaf;
list_c *list;
char *ID; /* token value */
+/*
struct {
symbol_c *first;
symbol_c *second;
- } tmp_symbol; /* used as a temorary reference to symbols by:
+ } tmp_symbol;
+*/
+/* used as a temorary reference to symbols by:
il_simple_operator_clash_il_operand
*/
}
@@ -973,7 +976,7 @@
%type <leaf> label
%type <leaf> il_simple_operation
// helper symbol for il_simple_operation
-%type <tmp_symbol> il_simple_operator_clash_il_operand
+//%type <tmp_symbol> il_simple_operator_clash_il_operand
%type <leaf> il_expression
%type <leaf> il_jump_operation
%type <leaf> il_fb_call
@@ -982,6 +985,8 @@
%type <leaf> il_expr_operator_clash_eol_list
%type <leaf> il_operand
%type <list> il_operand_list
+// helper symbol for il_simple_operation
+%type <list> il_operand_list2
%type <list> simple_instr_list
%type <leaf> il_simple_instruction
%type <list> il_param_list
@@ -3288,6 +3293,21 @@
*/
standard_function_name_expression_clashes:
+ AND {$$ = new identifier_c(strdup("AND"), locloc(@$));}
+| OR {$$ = new identifier_c(strdup("OR"), locloc(@$));}
+| XOR {$$ = new identifier_c(strdup("XOR"), locloc(@$));}
+| ADD {$$ = new identifier_c(strdup("ADD"), locloc(@$));}
+| SUB {$$ = new identifier_c(strdup("SUB"), locloc(@$));}
+| MUL {$$ = new identifier_c(strdup("MUL"), locloc(@$));}
+| DIV {$$ = new identifier_c(strdup("DIV"), locloc(@$));}
+| MOD {$$ = new identifier_c(strdup("MOD"), locloc(@$));}
+| GT {$$ = new identifier_c(strdup("GT"), locloc(@$));}
+| GE {$$ = new identifier_c(strdup("GE"), locloc(@$));}
+| EQ {$$ = new identifier_c(strdup("EQ"), locloc(@$));}
+| LT {$$ = new identifier_c(strdup("LT"), locloc(@$));}
+| LE {$$ = new identifier_c(strdup("LE"), locloc(@$));}
+| NE {$$ = new identifier_c(strdup("NE"), locloc(@$));}
+/*
AND_operator {$$ = il_operator_c_2_identifier_c($1);}
//NOTE: AND2 (corresponding to the source code string '&') does not clash
// with a standard function name, so should be commented out!
@@ -3305,6 +3325,7 @@
| LT_operator {$$ = il_operator_c_2_identifier_c($1);}
| LE_operator {$$ = il_operator_c_2_identifier_c($1);}
| NE_operator {$$ = il_operator_c_2_identifier_c($1);}
+*/
;
@@ -4360,8 +4381,12 @@
{$$ = new il_simple_operation_c($1, NULL, locloc(@$));}
| il_simple_operator_noclash il_operand
{$$ = new il_simple_operation_c($1, $2, locloc(@$));}
+/*
| il_simple_operator_clash_il_operand
{$$ = new il_simple_operation_c($1.first, $1.second, locloc(@$));}
+*/
+| il_simple_operator_clash il_operand
+ {$$ = new il_simple_operation_c($1, $2, locloc(@$));}
/* NOTE: the line
* | il_simple_operator
* already contains the 'NOT' operator, as well as all the
@@ -4411,25 +4436,29 @@
*/
| function_name_no_clashes il_operand_list
{$$ = new il_function_call_c($1, $2, locloc(@$));}
+/*
| il_simple_operator_clash_il_operand ',' il_operand_list
{list_c *list = new il_operand_list_c(locloc(@$));
list->add_element($1.second);
FOR_EACH_ELEMENT(elem, $3, {list->add_element(elem);})
$$ = new il_function_call_c(il_operator_c_2_identifier_c($1.first), list, locloc(@$));
- /* TODO: free the memory used up by the no longer used $3 object! */
- /* I don't do it now because I would have to test the change, and am
- * currently frying bigger fish... (Mario)
- */
- /* free($3); */
}
-;
-
-
-
+*/
+| il_simple_operator_clash il_operand_list2
+ {
+ $$ = new il_function_call_c($1, $2, locloc(@$));
+ }
+;
+
+
+
+/*
il_simple_operator_clash_il_operand:
il_simple_operator_clash il_operand
{$$.first = $1; $$.second = $2;}
;
+*/
+
@@ -4558,7 +4587,15 @@
il_operand_list:
il_operand
{$$ = new il_operand_list_c(locloc(@$)); $$->add_element($1);}
-| il_operand_list ',' il_operand
+| il_operand_list2
+;
+
+
+/* List with 2 or more il_operands */
+il_operand_list2:
+ il_operand ',' il_operand
+ {$$ = new il_operand_list_c(locloc(@$)); $$->add_element($1); $$->add_element($3);}
+| il_operand_list2 ',' il_operand
{$$ = $1; $$->add_element($3);}
;