stage1_2/iec.y
changeset 68 b0a43002dcac
parent 52 f44458d1fa29
child 73 0e623bbdee95
equal deleted inserted replaced
67:08097122a922 68:b0a43002dcac
    77 #include "../absyntax/absyntax.hh"
    77 #include "../absyntax/absyntax.hh"
    78 
    78 
    79 /* file with declaration of token constants. Generated by bison! */
    79 /* file with declaration of token constants. Generated by bison! */
    80 // #include "iec.y.hh"
    80 // #include "iec.y.hh"
    81 
    81 
       
    82 /* The interface through which bison and flex interact. */
    82 #include "stage1_2_priv.hh"
    83 #include "stage1_2_priv.hh"
    83 
    84 
    84 
    85 
    85 /* an ugly hack!!
    86 /* an ugly hack!!
    86  * We will probably not need it when we decide
    87  * We will probably not need it when we decide
    99   for(int i = 0; i < list->n; i++) {			\
   100   for(int i = 0; i < list->n; i++) {			\
   100     elem = list->elements[i];				\
   101     elem = list->elements[i];				\
   101     code;						\
   102     code;						\
   102   }							\
   103   }							\
   103 }
   104 }
       
   105 
       
   106 
       
   107 
       
   108 /* Macros used to pass the line and column locations when
       
   109  * creating a new object for the abstract syntax tree.
       
   110  */
       
   111 #define locloc(foo) foo.first_line, foo.first_column, foo.last_line, foo.last_column
       
   112 #define   locf(foo) foo.first_line, foo.first_column
       
   113 #define   locl(foo) foo.last_line,  foo.last_column
       
   114 
   104 
   115 
   105 
   116 
   106 /* A macro for printing out internal parser errors... */
   117 /* A macro for printing out internal parser errors... */
   107 #define ERROR error_exit(__FILE__,__LINE__)
   118 #define ERROR error_exit(__FILE__,__LINE__)
   108 /* function defined in main.cc */
   119 /* function defined in main.cc */
   171                                      transaction_tmp
   182                                      transaction_tmp
   172                                      action_tmp
   183                                      action_tmp
   173                              */
   184                              */
   174 }
   185 }
   175 
   186 
   176 
   187 /*
       
   188  TODO: DO we need to define a destructor do free
       
   189        memory when recovering from errors, or do the
       
   190        class destructors already handle this?
       
   191        Following is example on how to define
       
   192        detructors, using the syntax:
       
   193        %destructor { CODE } SYMBOLS
       
   194 %union
       
   195       {
       
   196         char *string;
       
   197       }
       
   198       %token <string> STRING
       
   199       %type  <string> string
       
   200       %destructor { free ($$); } STRING string
       
   201 */
   177 
   202 
   178 
   203 
   179 
   204 
   180 
   205 
   181 /*****************************/
   206 /*****************************/
   198  * to do the coaxing...
   223  * to do the coaxing...
   199  */
   224  */
   200 %token BOGUS_TOKEN_ID
   225 %token BOGUS_TOKEN_ID
   201 
   226 
   202 
   227 
   203 
   228 %type <leaf>	start
   204 %{
       
   205 /* The interface through which bison and flex interact. */
       
   206 /* May only be included after the definition of BOGUS_TOKEN_ID */
       
   207 #include "stage1_2_priv.hh"
       
   208 %}
       
   209 
       
   210 
       
   211 %type <leaf> start
       
   212 
   229 
   213 %type <leaf>	any_identifier
   230 %type <leaf>	any_identifier
   214 
   231 
   215 %token <ID>	prev_declared_variable_name_token
   232 %token <ID>	prev_declared_variable_name_token
   216 %token <ID>	prev_declared_fb_name_token
   233 %token <ID>	prev_declared_fb_name_token
   707 
   724 
   708 
   725 
   709 /***********************/
   726 /***********************/
   710 /* B 1.5.1 - Functions */
   727 /* B 1.5.1 - Functions */
   711 /***********************/
   728 /***********************/
   712 //%type  <leaf>	function_name
   729 // %type  <leaf>	function_name
   713 /* helper symbol for IL language */
   730 /* helper symbol for IL language */
   714 %type  <leaf>	function_name_no_clashes
   731 %type  <leaf>	function_name_no_clashes
   715 %type  <leaf>	function_name_simpleop_clashes
   732 %type  <leaf>	function_name_simpleop_clashes
   716 //%type  <leaf>	function_name_expression_clashes
   733 //%type  <leaf>	function_name_expression_clashes
   717 /* helper symbols for ST language */
   734 /* helper symbols for ST language */
  1271   library	{$$ = $1;}
  1288   library	{$$ = $1;}
  1272 ;
  1289 ;
  1273 
  1290 
  1274 /* the pragmas... */
  1291 /* the pragmas... */
  1275 pragma:
  1292 pragma:
  1276   pragma_token	{$$ = new pragma_c($1);}
  1293   pragma_token	{$$ = new pragma_c($1, locloc(@$));}
  1277 
  1294 
  1278 
  1295 
  1279 
  1296 
  1280 /* NOTE:
  1297 /* NOTE:
  1281  *       short version:
  1298  *       short version:
  1336 ;
  1353 ;
  1337 
  1354 
  1338 
  1355 
  1339 
  1356 
  1340 
  1357 
  1341 prev_declared_variable_name: prev_declared_variable_name_token {$$ = new identifier_c($1);};
  1358 prev_declared_variable_name: prev_declared_variable_name_token {$$ = new identifier_c($1, locloc(@$));};
  1342 prev_declared_fb_name: prev_declared_fb_name_token {$$ = new identifier_c($1);};
  1359 prev_declared_fb_name: prev_declared_fb_name_token {$$ = new identifier_c($1, locloc(@$));};
  1343 
  1360 
  1344 prev_declared_simple_type_name: prev_declared_simple_type_name_token {$$ = new identifier_c($1);};
  1361 prev_declared_simple_type_name: prev_declared_simple_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1345 prev_declared_subrange_type_name: prev_declared_subrange_type_name_token {$$ = new identifier_c($1);};
  1362 prev_declared_subrange_type_name: prev_declared_subrange_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1346 prev_declared_enumerated_type_name: prev_declared_enumerated_type_name_token {$$ = new identifier_c($1);};
  1363 prev_declared_enumerated_type_name: prev_declared_enumerated_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1347 prev_declared_array_type_name: prev_declared_array_type_name_token {$$ = new identifier_c($1);};
  1364 prev_declared_array_type_name: prev_declared_array_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1348 prev_declared_structure_type_name: prev_declared_structure_type_name_token {$$ = new identifier_c($1);};
  1365 prev_declared_structure_type_name: prev_declared_structure_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1349 prev_declared_string_type_name: prev_declared_string_type_name_token {$$ = new identifier_c($1);};
  1366 prev_declared_string_type_name: prev_declared_string_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1350 
  1367 
  1351 prev_declared_derived_function_name: prev_declared_derived_function_name_token {$$ = new identifier_c($1);};
  1368 prev_declared_derived_function_name: prev_declared_derived_function_name_token {$$ = new identifier_c($1, locloc(@$));};
  1352 prev_declared_derived_function_block_name: prev_declared_derived_function_block_name_token {$$ = new identifier_c($1);};
  1369 prev_declared_derived_function_block_name: prev_declared_derived_function_block_name_token {$$ = new identifier_c($1, locloc(@$));};
  1353 prev_declared_program_type_name: prev_declared_program_type_name_token {$$ = new identifier_c($1);};
  1370 prev_declared_program_type_name: prev_declared_program_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1354 
  1371 
  1355 
  1372 
  1356 
  1373 
  1357 
  1374 
  1358 
  1375 
  1367 	}
  1384 	}
  1368 | library library_element_declaration
  1385 | library library_element_declaration
  1369 	{$$ = $1; $$->add_element($2);}
  1386 	{$$ = $1; $$->add_element($2);}
  1370 | library error
  1387 | library error
  1371 	{$$ = NULL;
  1388 	{$$ = NULL;
  1372 	 print_err_msg(current_filename, @2.last_line, "unknown error.");
  1389 	 print_err_msg(current_filename, @2.first_line, "unknown error.");
  1373 	 /* yychar */
       
  1374 	 yyerrok;
  1390 	 yyerrok;
  1375 	}
  1391 	}
  1376 ;
  1392 ;
  1377 
  1393 
  1378 
  1394 
  1493  *          - WHILE...DO...END_WHILE
  1509  *          - WHILE...DO...END_WHILE
  1494  *          - WITH
  1510  *          - WITH
  1495  */
  1511  */
  1496 
  1512 
  1497 identifier:
  1513 identifier:
  1498   identifier_token	{$$ = new identifier_c($1);}
  1514   identifier_token	{$$ = new identifier_c($1, locloc(@$));}
  1499 /*  Make sure that all tokens (names) not defined as keywords are included here...
  1515 /*  Make sure that all tokens (names) not defined as keywords are included here...
  1500  * I (Mario) have already done this, but if any changes are made to this file,
  1516  * I (Mario) have already done this, but if any changes are made to this file,
  1501  * this list MUST be kept consistent!!
  1517  * this list MUST be kept consistent!!
  1502  */
  1518  */
  1503 /**/
  1519 /**/
  1504 | PRIORITY		{$$ = new identifier_c(strdup("PRIORITY"));}
  1520 | PRIORITY		{$$ = new identifier_c(strdup("PRIORITY"), locloc(@$));}
  1505 | SINGLE		{$$ = new identifier_c(strdup("SINGLE"));}
  1521 | SINGLE		{$$ = new identifier_c(strdup("SINGLE"), locloc(@$));}
  1506 | INTERVAL		{$$ = new identifier_c(strdup("INTERVAL"));}
  1522 | INTERVAL		{$$ = new identifier_c(strdup("INTERVAL"), locloc(@$));}
  1507 /**/
  1523 /**/
  1508 | LD_operator		{$$ = il_operator_c_2_identifier_c($1);}
  1524 | LD_operator		{$$ = il_operator_c_2_identifier_c($1);}
  1509 | LDN_operator		{$$ = il_operator_c_2_identifier_c($1);}
  1525 | LDN_operator		{$$ = il_operator_c_2_identifier_c($1);}
  1510 | ST_operator		{$$ = il_operator_c_2_identifier_c($1);}
  1526 | ST_operator		{$$ = il_operator_c_2_identifier_c($1);}
  1511 | STN_operator		{$$ = il_operator_c_2_identifier_c($1);}
  1527 | STN_operator		{$$ = il_operator_c_2_identifier_c($1);}
  1665  *      We now redefine real and fixed_point to be
  1681  *      We now redefine real and fixed_point to be
  1666  *        fixed_point: fixed_point_token | integer
  1682  *        fixed_point: fixed_point_token | integer
  1667  *        real: real_token | fixed_point_token
  1683  *        real: real_token | fixed_point_token
  1668  */
  1684  */
  1669 real:
  1685 real:
  1670   real_token		{$$ = new real_c($1);}
  1686   real_token		{$$ = new real_c($1, locloc(@$));}
  1671 | fixed_point_token	{$$ = new real_c($1);}
  1687 | fixed_point_token	{$$ = new real_c($1, locloc(@$));}
  1672 ;
  1688 ;
  1673 
  1689 
  1674 integer:	integer_token		{$$ = new integer_c($1);};
  1690 integer:	integer_token		{$$ = new integer_c($1, locloc(@$));};
  1675 binary_integer:	binary_integer_token	{$$ = new binary_integer_c($1);};
  1691 binary_integer:	binary_integer_token	{$$ = new binary_integer_c($1, locloc(@$));};
  1676 octal_integer:	octal_integer_token	{$$ = new octal_integer_c($1);};
  1692 octal_integer:	octal_integer_token	{$$ = new octal_integer_c($1, locloc(@$));};
  1677 hex_integer:	hex_integer_token	{$$ = new hex_integer_c($1);};
  1693 hex_integer:	hex_integer_token	{$$ = new hex_integer_c($1, locloc(@$));};
  1678 
  1694 
  1679 numeric_literal:
  1695 numeric_literal:
  1680   integer_literal
  1696   integer_literal
  1681 | real_literal
  1697 | real_literal
  1682 ;
  1698 ;
  1688 ;
  1704 ;
  1689 
  1705 
  1690 
  1706 
  1691 integer_literal:
  1707 integer_literal:
  1692   integer_type_name '#' signed_integer
  1708   integer_type_name '#' signed_integer
  1693 	{$$ = new integer_literal_c($1, $3);}
  1709 	{$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));}
  1694 | integer_type_name '#' binary_integer
  1710 | integer_type_name '#' binary_integer
  1695 	{$$ = new integer_literal_c($1, $3);}
  1711 	{$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));}
  1696 | integer_type_name '#' octal_integer
  1712 | integer_type_name '#' octal_integer
  1697 	{$$ = new integer_literal_c($1, $3);}
  1713 	{$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));}
  1698 | integer_type_name '#' hex_integer
  1714 | integer_type_name '#' hex_integer
  1699 	{$$ = new integer_literal_c($1, $3);}
  1715 	{$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));}
  1700 /* NOTE: see note in the definition of constant for reason
  1716 /* NOTE: see note in the definition of constant for reason
  1701  * why signed_integer, binary_integer, octal_integer
  1717  * why signed_integer, binary_integer, octal_integer
  1702  * and hex_integer are missing here!
  1718  * and hex_integer are missing here!
  1703  */
  1719  */
  1704 ;
  1720 ;
  1705 
  1721 
  1706 signed_integer:
  1722 signed_integer:
  1707   integer
  1723   integer
  1708 | '+' integer   {$$ = $2;}
  1724 | '+' integer   {$$ = $2;}
  1709 | '-' integer	{$$ = new neg_expression_c($2);}
  1725 | '-' integer	{$$ = new neg_expression_c($2, locloc(@$));}
  1710 ;
  1726 ;
  1711 
  1727 
  1712 /* a helper symbol for non_negative_constant */
  1728 /* a helper symbol for non_negative_constant */
  1713 /* A integer without any preceding '-', but may
  1729 /* A integer without any preceding '-', but may
  1714  * include a preceding '+' !
  1730  * include a preceding '+' !
  1720 
  1736 
  1721 
  1737 
  1722 real_literal:
  1738 real_literal:
  1723   signed_real
  1739   signed_real
  1724 | real_type_name '#' signed_real
  1740 | real_type_name '#' signed_real
  1725 	{$$ = new real_literal_c($1, $3);}
  1741 	{$$ = new real_literal_c($1, $3, locf(@1), locl(@3));}
  1726 ;
  1742 ;
  1727 
  1743 
  1728 /* helper symbol for non_negative_numeric_literal */
  1744 /* helper symbol for non_negative_numeric_literal */
  1729 non_negative_real_literal:
  1745 non_negative_real_literal:
  1730   non_negative_signed_real
  1746   non_negative_signed_real
  1731 | real_type_name '#' signed_real
  1747 | real_type_name '#' signed_real
  1732 	{$$ = new real_literal_c($1, $3);}
  1748 	{$$ = new real_literal_c($1, $3, locf(@1), locl(@3));}
  1733 ;
  1749 ;
  1734 
  1750 
  1735 signed_real:
  1751 signed_real:
  1736   real
  1752   real
  1737 | '+' real	{$$ = $2;}
  1753 | '+' real	{$$ = $2;}
  1738 | '-' real	{$$ = new neg_expression_c($2);}
  1754 | '-' real	{$$ = new neg_expression_c($2, locloc(@2));}
  1739 ;
  1755 ;
  1740 
  1756 
  1741 /* helper symbol for non_negative_real_literal */
  1757 /* helper symbol for non_negative_real_literal */
  1742 non_negative_signed_real:
  1758 non_negative_signed_real:
  1743   real
  1759   real
  1745 ;
  1761 ;
  1746 
  1762 
  1747 
  1763 
  1748 bit_string_literal:
  1764 bit_string_literal:
  1749   bit_string_type_name '#' integer  /* i.e. unsigned_integer */
  1765   bit_string_type_name '#' integer  /* i.e. unsigned_integer */
  1750 	{$$ = new bit_string_literal_c($1, $3);}
  1766 	{$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));}
  1751 | bit_string_type_name '#' binary_integer
  1767 | bit_string_type_name '#' binary_integer
  1752 	{$$ = new bit_string_literal_c($1, $3);}
  1768 	{$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));}
  1753 | bit_string_type_name '#' octal_integer
  1769 | bit_string_type_name '#' octal_integer
  1754 	{$$ = new bit_string_literal_c($1, $3);}
  1770 	{$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));}
  1755 | bit_string_type_name '#' hex_integer
  1771 | bit_string_type_name '#' hex_integer
  1756 	{$$ = new bit_string_literal_c($1, $3);}
  1772 	{$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));}
  1757 /* NOTE: see note in the definition of constant for reason
  1773 /* NOTE: see note in the definition of constant for reason
  1758  * why unsigned_integer, binary_integer, octal_integer
  1774  * why unsigned_integer, binary_integer, octal_integer
  1759  * and hex_integer are missing here!
  1775  * and hex_integer are missing here!
  1760  */
  1776  */
  1761 /* NOTE: see note under the B 1.2.1 section of token
  1777 /* NOTE: see note under the B 1.2.1 section of token
  1765  */
  1781  */
  1766 ;
  1782 ;
  1767 
  1783 
  1768 
  1784 
  1769 boolean_literal:
  1785 boolean_literal:
  1770   TRUE	{$$ = new boolean_literal_c(new bool_type_name_c(),
  1786   TRUE	{$$ = new boolean_literal_c(new bool_type_name_c(locloc(@$)),
  1771   				    new boolean_true_c());}
  1787   				    new boolean_true_c(locloc(@$)),
  1772 | FALSE	{$$ = new boolean_literal_c(new bool_type_name_c(),
  1788 				    locloc(@$));}
  1773 				    new boolean_false_c());}
  1789 | FALSE	{$$ = new boolean_literal_c(new bool_type_name_c(locloc(@$)),
       
  1790 				    new boolean_false_c(locloc(@$)),
       
  1791 				    locloc(@$));}
  1774 /*
  1792 /*
  1775 |	BOOL '#' '1' {}
  1793 |	BOOL '#' '1' {}
  1776 |	BOOL '#' '0' {}
  1794 |	BOOL '#' '0' {}
  1777 */
  1795 */
  1778 /* NOTE: the rules
  1796 /* NOTE: the rules
  1808 /*******************************/
  1826 /*******************************/
  1809 /* B 1.2.2 - Character Strings */
  1827 /* B 1.2.2 - Character Strings */
  1810 /*******************************/
  1828 /*******************************/
  1811 /* Transform the tokens given us by flex into leafs */
  1829 /* Transform the tokens given us by flex into leafs */
  1812 single_byte_character_string:	single_byte_character_string_token
  1830 single_byte_character_string:	single_byte_character_string_token
  1813 	{$$ = new single_byte_character_string_c($1);};
  1831 	{$$ = new single_byte_character_string_c($1, locloc(@$));};
  1814 
  1832 
  1815 double_byte_character_string:	double_byte_character_string_token
  1833 double_byte_character_string:	double_byte_character_string_token
  1816 	{$$ = new double_byte_character_string_c($1);};
  1834 	{$$ = new double_byte_character_string_c($1, locloc(@$));};
  1817 
  1835 
  1818 
  1836 
  1819 character_string:
  1837 character_string:
  1820   single_byte_character_string
  1838   single_byte_character_string
  1821 | double_byte_character_string
  1839 | double_byte_character_string
  1850  *
  1868  *
  1851  *       We therefore have flex returning the token T_SHARP
  1869  *       We therefore have flex returning the token T_SHARP
  1852  *       when it comes across 'T#'
  1870  *       when it comes across 'T#'
  1853  */
  1871  */
  1854   TIME '#' interval
  1872   TIME '#' interval
  1855 	{$$ = new duration_c(NULL, $3);}
  1873 	{$$ = new duration_c(NULL, $3, locloc(@$));}
  1856 | TIME '#' '-' interval
  1874 | TIME '#' '-' interval
  1857 	{$$ = new duration_c(new neg_time_c(), $4);}
  1875 	{$$ = new duration_c(new neg_time_c(locloc(@$)), $4, locloc(@$));}
  1858 | T_SHARP interval
  1876 | T_SHARP interval
  1859 	{$$ = new duration_c(NULL, $2);}
  1877 	{$$ = new duration_c(NULL, $2, locloc(@$));}
  1860 | T_SHARP '-' interval
  1878 | T_SHARP '-' interval
  1861 	{$$ = new duration_c(new neg_time_c(), $3);}
  1879 	{$$ = new duration_c(new neg_time_c(locloc(@$)), $3, locloc(@$));}
  1862 ;
  1880 ;
  1863 
  1881 
  1864 
  1882 
  1865 interval:
  1883 interval:
  1866   days
  1884   days
  1868 | minutes
  1886 | minutes
  1869 | seconds
  1887 | seconds
  1870 | milliseconds
  1888 | milliseconds
  1871 ;
  1889 ;
  1872 
  1890 
  1873 integer_d:  integer_d_token  {$$ = new integer_c($1);};
  1891 integer_d:  integer_d_token  {$$ = new integer_c($1, locloc(@$));};
  1874 integer_h:  integer_h_token  {$$ = new integer_c($1);};
  1892 integer_h:  integer_h_token  {$$ = new integer_c($1, locloc(@$));};
  1875 integer_m:  integer_m_token  {$$ = new integer_c($1);};
  1893 integer_m:  integer_m_token  {$$ = new integer_c($1, locloc(@$));};
  1876 integer_s:  integer_s_token  {$$ = new integer_c($1);};
  1894 integer_s:  integer_s_token  {$$ = new integer_c($1, locloc(@$));};
  1877 integer_ms: integer_ms_token {$$ = new integer_c($1);};
  1895 integer_ms: integer_ms_token {$$ = new integer_c($1, locloc(@$));};
  1878 
  1896 
  1879 fixed_point_d:
  1897 fixed_point_d:
  1880   fixed_point_d_token
  1898   fixed_point_d_token
  1881 	{$$ = new fixed_point_c($1);}
  1899 	{$$ = new fixed_point_c($1, locloc(@$));}
  1882 | integer_d
  1900 | integer_d
  1883 ;
  1901 ;
  1884 
  1902 
  1885 fixed_point_h:
  1903 fixed_point_h:
  1886   fixed_point_h_token
  1904   fixed_point_h_token
  1887 	{$$ = new fixed_point_c($1);}
  1905 	{$$ = new fixed_point_c($1, locloc(@$));}
  1888 | integer_h
  1906 | integer_h
  1889 ;
  1907 ;
  1890 
  1908 
  1891 fixed_point_m:
  1909 fixed_point_m:
  1892   fixed_point_m_token
  1910   fixed_point_m_token
  1893 	{$$ = new fixed_point_c($1);}
  1911 	{$$ = new fixed_point_c($1, locloc(@$));}
  1894 | integer_m
  1912 | integer_m
  1895 ;
  1913 ;
  1896 
  1914 
  1897 fixed_point_s:
  1915 fixed_point_s:
  1898   fixed_point_s_token
  1916   fixed_point_s_token
  1899 	{$$ = new fixed_point_c($1);}
  1917 	{$$ = new fixed_point_c($1, locloc(@$));}
  1900 | integer_s
  1918 | integer_s
  1901 ;
  1919 ;
  1902 
  1920 
  1903 fixed_point_ms:
  1921 fixed_point_ms:
  1904   fixed_point_ms_token
  1922   fixed_point_ms_token
  1905 	{$$ = new fixed_point_c($1);}
  1923 	{$$ = new fixed_point_c($1, locloc(@$));}
  1906 | integer_ms
  1924 | integer_ms
  1907 ;
  1925 ;
  1908 
  1926 
  1909 
  1927 
  1910 fixed_point:
  1928 fixed_point:
  1911   fixed_point_token
  1929   fixed_point_token
  1912 	{$$ = new fixed_point_c($1);}
  1930 	{$$ = new fixed_point_c($1, locloc(@$));}
  1913 | integer
  1931 | integer
  1914 ;
  1932 ;
  1915 
  1933 
  1916 
  1934 
  1917 days:
  1935 days:
  1918 /*  fixed_point ('d') */
  1936 /*  fixed_point ('d') */
  1919   fixed_point_d
  1937   fixed_point_d
  1920 	{$$ = new days_c($1, NULL);}
  1938 	{$$ = new days_c($1, NULL, locloc(@$));}
  1921 /*| integer ('d') ['_'] hours */
  1939 /*| integer ('d') ['_'] hours */
  1922 | integer_d hours
  1940 | integer_d hours
  1923 	{$$ = new days_c($1, $2);}
  1941 	{$$ = new days_c($1, $2, locloc(@$));}
  1924 | integer_d '_' hours
  1942 | integer_d '_' hours
  1925 	{$$ = new days_c($1, $3);}
  1943 	{$$ = new days_c($1, $3, locloc(@$));}
  1926 ;
  1944 ;
  1927 
  1945 
  1928 
  1946 
  1929 hours:
  1947 hours:
  1930 /*  fixed_point ('h') */
  1948 /*  fixed_point ('h') */
  1931   fixed_point_h
  1949   fixed_point_h
  1932 	{$$ = new hours_c($1, NULL);}
  1950 	{$$ = new hours_c($1, NULL, locloc(@$));}
  1933 /*| integer ('h') ['_'] minutes */
  1951 /*| integer ('h') ['_'] minutes */
  1934 | integer_h minutes
  1952 | integer_h minutes
  1935 	{$$ = new hours_c($1, $2);}
  1953 	{$$ = new hours_c($1, $2, locloc(@$));}
  1936 | integer_h '_' minutes
  1954 | integer_h '_' minutes
  1937 	{$$ = new hours_c($1, $3);}
  1955 	{$$ = new hours_c($1, $3, locloc(@$));}
  1938 ;
  1956 ;
  1939 
  1957 
  1940 minutes:
  1958 minutes:
  1941 /*  fixed_point ('m') */
  1959 /*  fixed_point ('m') */
  1942   fixed_point_m
  1960   fixed_point_m
  1943 	{$$ = new minutes_c($1, NULL);}
  1961 	{$$ = new minutes_c($1, NULL, locloc(@$));}
  1944 /*| integer ('m') ['_'] seconds */
  1962 /*| integer ('m') ['_'] seconds */
  1945 | integer_m seconds
  1963 | integer_m seconds
  1946 	{$$ = new minutes_c($1, $2);}
  1964 	{$$ = new minutes_c($1, $2, locloc(@$));}
  1947 | integer_m '_' seconds
  1965 | integer_m '_' seconds
  1948 	{$$ = new minutes_c($1, $3);}
  1966 	{$$ = new minutes_c($1, $3, locloc(@$));}
  1949 ;
  1967 ;
  1950 
  1968 
  1951 seconds:
  1969 seconds:
  1952 /*  fixed_point ('s') */
  1970 /*  fixed_point ('s') */
  1953   fixed_point_s
  1971   fixed_point_s
  1954 	{$$ = new seconds_c($1, NULL);}
  1972 	{$$ = new seconds_c($1, NULL, locloc(@$));}
  1955 /*| integer ('s') ['_'] milliseconds */
  1973 /*| integer ('s') ['_'] milliseconds */
  1956 | integer_s milliseconds
  1974 | integer_s milliseconds
  1957 	{$$ = new seconds_c($1, $2);}
  1975 	{$$ = new seconds_c($1, $2, locloc(@$));}
  1958 | integer_s '_' milliseconds
  1976 | integer_s '_' milliseconds
  1959 	{$$ = new seconds_c($1, $3);}
  1977 	{$$ = new seconds_c($1, $3, locloc(@$));}
  1960 ;
  1978 ;
  1961 
  1979 
  1962 milliseconds:
  1980 milliseconds:
  1963 /*  fixed_point ('ms') */
  1981 /*  fixed_point ('ms') */
  1964   fixed_point_ms
  1982   fixed_point_ms
  1965 	{$$ = new milliseconds_c($1);}
  1983 	{$$ = new milliseconds_c($1, locloc(@$));}
  1966 ;
  1984 ;
  1967 
  1985 
  1968 
  1986 
  1969 
  1987 
  1970 /************************************/
  1988 /************************************/
  1971 /* B 1.2.3.2 - Time of day and Date */
  1989 /* B 1.2.3.2 - Time of day and Date */
  1972 /************************************/
  1990 /************************************/
  1973 time_of_day:
  1991 time_of_day:
  1974   TIME_OF_DAY '#' daytime
  1992   TIME_OF_DAY '#' daytime
  1975 	{$$ = new time_of_day_c($3);}
  1993 	{$$ = new time_of_day_c($3, locloc(@$));}
  1976 ;
  1994 ;
  1977 
  1995 
  1978 
  1996 
  1979 daytime:
  1997 daytime:
  1980   day_hour ':' day_minute ':' day_second
  1998   day_hour ':' day_minute ':' day_second
  1981 	{$$ = new daytime_c($1, $3, $5);}
  1999 	{$$ = new daytime_c($1, $3, $5, locloc(@$));}
  1982 ;
  2000 ;
  1983 
  2001 
  1984 
  2002 
  1985 day_hour: integer;
  2003 day_hour: integer;
  1986 day_minute: integer;
  2004 day_minute: integer;
  1987 day_second: fixed_point;
  2005 day_second: fixed_point;
  1988 
  2006 
  1989 
  2007 
  1990 date:
  2008 date:
  1991   DATE '#' date_literal
  2009   DATE '#' date_literal
  1992 	{$$ = new date_c($3);}
  2010 	{$$ = new date_c($3, locloc(@$));}
  1993 | D_SHARP date_literal
  2011 | D_SHARP date_literal
  1994 	{$$ = new date_c($2);}
  2012 	{$$ = new date_c($2, locloc(@$));}
  1995 ;
  2013 ;
  1996 
  2014 
  1997 
  2015 
  1998 date_literal:
  2016 date_literal:
  1999   year '-' month '-' day
  2017   year '-' month '-' day
  2000 	{$$ = new date_literal_c($1, $3, $5);}
  2018 	{$$ = new date_literal_c($1, $3, $5, locloc(@$));}
  2001 ;
  2019 ;
  2002 
  2020 
  2003 
  2021 
  2004 year: integer;
  2022 year: integer;
  2005 month: integer;
  2023 month: integer;
  2006 day: integer;
  2024 day: integer;
  2007 
  2025 
  2008 
  2026 
  2009 date_and_time:
  2027 date_and_time:
  2010   DATE_AND_TIME '#' date_literal '-' daytime
  2028   DATE_AND_TIME '#' date_literal '-' daytime
  2011 	{$$ = new date_and_time_c($3, $5);}
  2029 	{$$ = new date_and_time_c($3, $5, locloc(@$));}
  2012 ;
  2030 ;
  2013 
  2031 
  2014 
  2032 
  2015 
  2033 
  2016 
  2034 
  2040 elementary_type_name:
  2058 elementary_type_name:
  2041   numeric_type_name
  2059   numeric_type_name
  2042 | date_type_name
  2060 | date_type_name
  2043 | bit_string_type_name
  2061 | bit_string_type_name
  2044 | elementary_string_type_name
  2062 | elementary_string_type_name
  2045 | TIME		{$$ = new time_type_name_c();}
  2063 | TIME		{$$ = new time_type_name_c(locloc(@$));}
  2046 | BOOL		{$$ = new bool_type_name_c();}
  2064 | BOOL		{$$ = new bool_type_name_c(locloc(@$));}
  2047 /* NOTE: see note under the B 1.2.1 section of token
  2065 /* NOTE: see note under the B 1.2.1 section of token
  2048  * and grouping type definition for reason why BOOL
  2066  * and grouping type definition for reason why BOOL
  2049  * was added to this definition.
  2067  * was added to this definition.
  2050  */
  2068  */
  2051 ;
  2069 ;
  2059   signed_integer_type_name
  2077   signed_integer_type_name
  2060 | unsigned_integer_type_name
  2078 | unsigned_integer_type_name
  2061 ;
  2079 ;
  2062 
  2080 
  2063 signed_integer_type_name:
  2081 signed_integer_type_name:
  2064   SINT	{$$ = new sint_type_name_c();}
  2082   SINT	{$$ = new sint_type_name_c(locloc(@$));}
  2065 | INT	{$$ = new int_type_name_c();}
  2083 | INT	{$$ = new int_type_name_c(locloc(@$));}
  2066 | DINT	{$$ = new dint_type_name_c();}
  2084 | DINT	{$$ = new dint_type_name_c(locloc(@$));}
  2067 | LINT	{$$ = new lint_type_name_c();}
  2085 | LINT	{$$ = new lint_type_name_c(locloc(@$));}
  2068 ;
  2086 ;
  2069 
  2087 
  2070 unsigned_integer_type_name:
  2088 unsigned_integer_type_name:
  2071   USINT	{$$ = new usint_type_name_c();}
  2089   USINT	{$$ = new usint_type_name_c(locloc(@$));}
  2072 | UINT	{$$ = new uint_type_name_c();}
  2090 | UINT	{$$ = new uint_type_name_c(locloc(@$));}
  2073 | UDINT	{$$ = new udint_type_name_c();}
  2091 | UDINT	{$$ = new udint_type_name_c(locloc(@$));}
  2074 | ULINT	{$$ = new ulint_type_name_c();}
  2092 | ULINT	{$$ = new ulint_type_name_c(locloc(@$));}
  2075 ;
  2093 ;
  2076 
  2094 
  2077 real_type_name:
  2095 real_type_name:
  2078   REAL	{$$ = new real_type_name_c();}
  2096   REAL	{$$ = new real_type_name_c(locloc(@$));}
  2079 | LREAL	{$$ = new lreal_type_name_c();}
  2097 | LREAL	{$$ = new lreal_type_name_c(locloc(@$));}
  2080 ;
  2098 ;
  2081 
  2099 
  2082 date_type_name:
  2100 date_type_name:
  2083   DATE		{$$ = new date_type_name_c();}
  2101   DATE		{$$ = new date_type_name_c(locloc(@$));}
  2084 | TIME_OF_DAY	{$$ = new tod_type_name_c();}
  2102 | TIME_OF_DAY	{$$ = new tod_type_name_c(locloc(@$));}
  2085 | TOD		{$$ = new tod_type_name_c();}
  2103 | TOD		{$$ = new tod_type_name_c(locloc(@$));}
  2086 | DATE_AND_TIME	{$$ = new dt_type_name_c();}
  2104 | DATE_AND_TIME	{$$ = new dt_type_name_c(locloc(@$));}
  2087 | DT		{$$ = new dt_type_name_c();}
  2105 | DT		{$$ = new dt_type_name_c(locloc(@$));}
  2088 ;
  2106 ;
  2089 
  2107 
  2090 
  2108 
  2091 bit_string_type_name:
  2109 bit_string_type_name:
  2092   BYTE	{$$ = new byte_type_name_c();}
  2110   BYTE	{$$ = new byte_type_name_c(locloc(@$));}
  2093 | WORD	{$$ = new word_type_name_c();}
  2111 | WORD	{$$ = new word_type_name_c(locloc(@$));}
  2094 | DWORD	{$$ = new dword_type_name_c();}
  2112 | DWORD	{$$ = new dword_type_name_c(locloc(@$));}
  2095 | LWORD	{$$ = new lword_type_name_c();}
  2113 | LWORD	{$$ = new lword_type_name_c(locloc(@$));}
  2096 /* NOTE: see note under the B 1.2.1 section of token
  2114 /* NOTE: see note under the B 1.2.1 section of token
  2097  * and grouping type definition for reason why the BOOL
  2115  * and grouping type definition for reason why the BOOL
  2098  * was omitted from this definition.
  2116  * was omitted from this definition.
  2099  */
  2117  */
  2100 ;
  2118 ;
  2107  * but we want to create the equivalent abstract syntax
  2125  * but we want to create the equivalent abstract syntax
  2108  * in a single location of this file, in order to make
  2126  * in a single location of this file, in order to make
  2109  * possible future changes easier to edit...
  2127  * possible future changes easier to edit...
  2110  */
  2128  */
  2111 elementary_string_type_name:
  2129 elementary_string_type_name:
  2112   STRING	{$$ = new string_type_name_c();}
  2130   STRING	{$$ = new string_type_name_c(locloc(@$));}
  2113 | WSTRING	{$$ = new wstring_type_name_c();}
  2131 | WSTRING	{$$ = new wstring_type_name_c(locloc(@$));}
  2114 ;
  2132 ;
  2115 
  2133 
  2116 
  2134 
  2117 
  2135 
  2118 /********************************/
  2136 /********************************/
  2119 /* B 1.3.2 - Generic data types */
  2137 /* B 1.3.2 - Generic data types */
  2120 /********************************/
  2138 /********************************/
  2121 /* Strangely, the following symbol does seem to be required! */
  2139 /* Strangely, the following symbol does not seem to be required! */
  2122 /*
  2140 /*
  2123 generic_type_name:
  2141 generic_type_name:
  2124   ANY
  2142   ANY
  2125 | ANY_DERIVED
  2143 | ANY_DERIVED
  2126 | ANY_ELEMENTARY
  2144 | ANY_ELEMENTARY
  2139 /* B 1.3.3 - Derived data types */
  2157 /* B 1.3.3 - Derived data types */
  2140 /********************************/
  2158 /********************************/
  2141 
  2159 
  2142 derived_type_name:
  2160 derived_type_name:
  2143   single_element_type_name
  2161   single_element_type_name
  2144 | prev_declared_array_type_name	{$$ = $1;}
  2162 | prev_declared_array_type_name
  2145 | prev_declared_structure_type_name	{$$ = $1;}
  2163 | prev_declared_structure_type_name
  2146 | prev_declared_string_type_name	{$$ = $1;}
  2164 | prev_declared_string_type_name
  2147 ;
  2165 ;
  2148 
  2166 
  2149 single_element_type_name:
  2167 single_element_type_name:
  2150   prev_declared_simple_type_name		{$$ = $1;}
  2168   prev_declared_simple_type_name
  2151 /* Include the following if arrays of function blocks are to be allowed!
  2169 /* Include the following if arrays of function blocks are to be allowed!
  2152  * Since the standard does not allow them,
  2170  * Since the standard does not allow them,
  2153  * we leave it commented out for the time being...
  2171  * we leave it commented out for the time being...
  2154  */
  2172  */
  2155 //| prev_declared_derived_function_block_name	{$$ = $1;}
  2173 //| prev_declared_derived_function_block_name
  2156 | prev_declared_subrange_type_name		{$$ = $1;}
  2174 | prev_declared_subrange_type_name
  2157 | prev_declared_enumerated_type_name		{$$ = $1;}
  2175 | prev_declared_enumerated_type_name
  2158 ;
  2176 ;
  2159 
  2177 
  2160 /* NOTE: in order to remove a reduce/reduce conflict,
  2178 /* NOTE: in order to remove a reduce/reduce conflict,
  2161  *       all occurences of simple_type_name, etc...
  2179  *       all occurences of simple_type_name, etc...
  2162  *       have been replaced with identifier!
  2180  *       have been replaced with identifier!
  2169 structure_type_name: identifier;
  2187 structure_type_name: identifier;
  2170 */
  2188 */
  2171 
  2189 
  2172 data_type_declaration:
  2190 data_type_declaration:
  2173   TYPE type_declaration_list END_TYPE
  2191   TYPE type_declaration_list END_TYPE
  2174 	{$$ = new data_type_declaration_c($2);}
  2192 	{$$ = new data_type_declaration_c($2, locloc(@$));}
  2175 ;
  2193 ;
  2176 
  2194 
  2177 /* helper symbol for data_type_declaration */
  2195 /* helper symbol for data_type_declaration */
  2178 type_declaration_list:
  2196 type_declaration_list:
  2179   type_declaration ';'
  2197   type_declaration ';'
  2180 	{$$ = new type_declaration_list_c(); $$->add_element($1);}
  2198 	{$$ = new type_declaration_list_c(locloc(@$)); $$->add_element($1);}
  2181 | type_declaration_list type_declaration ';'
  2199 | type_declaration_list type_declaration ';'
  2182 	{$$ = $1; $$->add_element($2);}
  2200 	{$$ = $1; $$->add_element($2);}
  2183 ;
  2201 ;
  2184 
  2202 
  2185 type_declaration:
  2203 type_declaration:
  2196 ;
  2214 ;
  2197 
  2215 
  2198 simple_type_declaration:
  2216 simple_type_declaration:
  2199 /*  simple_type_name ':' simple_spec_init */
  2217 /*  simple_type_name ':' simple_spec_init */
  2200   identifier ':' simple_spec_init
  2218   identifier ':' simple_spec_init
  2201 	{$$ = new simple_type_declaration_c($1, $3);
  2219 	{$$ = new simple_type_declaration_c($1, $3, locloc(@$));
  2202 	 library_element_symtable.insert($1, prev_declared_simple_type_name_token);
  2220 	 library_element_symtable.insert($1, prev_declared_simple_type_name_token);
  2203 	}
  2221 	}
  2204 ;
  2222 ;
  2205 
  2223 
  2206 
  2224 
  2207 simple_spec_init:
  2225 simple_spec_init:
  2208   simple_specification
  2226   simple_specification
  2209   /* The following line was changed so that we wouldn't
  2227   /* The following commented line was changed to the 
       
  2228    * next two lines so that we wouldn't
  2210    * have the first element of a simple_spec_init_c()
  2229    * have the first element of a simple_spec_init_c()
  2211    * pointing to another simple_spec_init_c!
  2230    * pointing to another simple_spec_init_c!
  2212    */
  2231    */
  2213 /*
  2232 /*
  2214 | simple_specification ASSIGN constant
  2233 | simple_specification ASSIGN constant
  2215 	{$$ = new simple_spec_init_c($1, $3);}
  2234 	{$$ = new simple_spec_init_c($1, $3);}
  2216 */
  2235 */
  2217 | elementary_type_name ASSIGN constant
  2236 | elementary_type_name ASSIGN constant
  2218 	{$$ = new simple_spec_init_c($1, $3);}
  2237 	{$$ = new simple_spec_init_c($1, $3, locloc(@$));}
  2219 | prev_declared_simple_type_name ASSIGN constant
  2238 | prev_declared_simple_type_name ASSIGN constant
  2220 	{$$ = new simple_spec_init_c($1, $3);}
  2239 	{$$ = new simple_spec_init_c($1, $3, locloc(@$));}
  2221 ;
  2240 ;
  2222 
  2241 
  2223 /* When converting to C/C++, we need to know whether
  2242 /* When converting to C/C++, we need to know whether
  2224  * the elementary_type_name is being used in a variable
  2243  * the elementary_type_name is being used in a variable
  2225  * declaration or elsewhere (ex. declaration of a derived
  2244  * declaration or elsewhere (ex. declaration of a derived
  2232  * constituent components...
  2251  * constituent components...
  2233  */
  2252  */
  2234 simple_specification:
  2253 simple_specification:
  2235 // elementary_type_name | simple_type_name
  2254 // elementary_type_name | simple_type_name
  2236   elementary_type_name
  2255   elementary_type_name
  2237 	{$$ = new simple_spec_init_c($1, NULL);}
  2256 	{$$ = new simple_spec_init_c($1, NULL, locloc(@$));}
  2238 | prev_declared_simple_type_name
  2257 | prev_declared_simple_type_name
  2239 	{$$ = new simple_spec_init_c($1, NULL);}
  2258 	{$$ = new simple_spec_init_c($1, NULL, locloc(@$));}
  2240 ;
  2259 ;
  2241 
  2260 
  2242 
  2261 
  2243 subrange_type_declaration:
  2262 subrange_type_declaration:
  2244 /*  subrange_type_name ':' subrange_spec_init */
  2263 /*  subrange_type_name ':' subrange_spec_init */
  2245   identifier ':' subrange_spec_init
  2264   identifier ':' subrange_spec_init
  2246 	{$$ = new subrange_type_declaration_c($1, $3);
  2265 	{$$ = new subrange_type_declaration_c($1, $3, locloc(@$));
  2247 	 library_element_symtable.insert($1, prev_declared_subrange_type_name_token);
  2266 	 library_element_symtable.insert($1, prev_declared_subrange_type_name_token);
  2248 	}
  2267 	}
  2249 ;
  2268 ;
  2250 
  2269 
  2251 subrange_spec_init:
  2270 subrange_spec_init:
  2252   subrange_specification
  2271   subrange_specification
  2253 	{$$ = new subrange_spec_init_c($1, NULL);}
  2272 	{$$ = new subrange_spec_init_c($1, NULL, locloc(@$));}
  2254 | subrange_specification ASSIGN signed_integer
  2273 | subrange_specification ASSIGN signed_integer
  2255 	{$$ = new subrange_spec_init_c($1, $3);}
  2274 	{$$ = new subrange_spec_init_c($1, $3, locloc(@$));}
  2256 ;
  2275 ;
  2257 
  2276 
  2258 subrange_specification:
  2277 subrange_specification:
  2259   integer_type_name '(' subrange')'
  2278   integer_type_name '(' subrange')'
  2260 	{$$ = new subrange_specification_c($1, $3);}
  2279 	{$$ = new subrange_specification_c($1, $3, locloc(@$));}
  2261 | prev_declared_subrange_type_name	{$$ = $1;}
  2280 | prev_declared_subrange_type_name
  2262 ;
  2281 ;
  2263 
  2282 
  2264 
  2283 
  2265 subrange:
  2284 subrange:
  2266   signed_integer DOTDOT signed_integer
  2285   signed_integer DOTDOT signed_integer
  2267 	{$$ = new subrange_c($1, $3);}
  2286 	{$$ = new subrange_c($1, $3, locloc(@$));}
  2268 ;
  2287 ;
  2269 
  2288 
  2270 enumerated_type_declaration:
  2289 enumerated_type_declaration:
  2271 /*  enumerated_type_name ':' enumerated_spec_init */
  2290 /*  enumerated_type_name ':' enumerated_spec_init */
  2272   identifier ':' enumerated_spec_init
  2291   identifier ':' enumerated_spec_init
  2273 	{$$ = new enumerated_type_declaration_c($1, $3);
  2292 	{$$ = new enumerated_type_declaration_c($1, $3, locloc(@$));
  2274 	 library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);
  2293 	 library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);
  2275 	}
  2294 	}
  2276 ;
  2295 ;
  2277 
  2296 
  2278 
  2297 
  2279 enumerated_spec_init:
  2298 enumerated_spec_init:
  2280   enumerated_specification
  2299   enumerated_specification
  2281 	{$$ = new enumerated_spec_init_c($1, NULL);}
  2300 	{$$ = new enumerated_spec_init_c($1, NULL, locloc(@$));}
  2282 | enumerated_specification ASSIGN enumerated_value
  2301 | enumerated_specification ASSIGN enumerated_value
  2283 	{$$ = new enumerated_spec_init_c($1, $3);}
  2302 	{$$ = new enumerated_spec_init_c($1, $3, locloc(@$));}
  2284 ;
  2303 ;
  2285 
  2304 
  2286 enumerated_specification:
  2305 enumerated_specification:
  2287   '(' enumerated_value_list ')'
  2306   '(' enumerated_value_list ')'
  2288 	{$$ = $2;}
  2307 	{$$ = $2;}
  2289 | prev_declared_enumerated_type_name	{$$ = $1;}
  2308 | prev_declared_enumerated_type_name
  2290 ;
  2309 ;
  2291 
  2310 
  2292 /* helper symbol for enumerated_specification */
  2311 /* helper symbol for enumerated_specification */
  2293 enumerated_value_list:
  2312 enumerated_value_list:
  2294   enumerated_value
  2313   enumerated_value
  2295 	{$$ = new enumerated_value_list_c(); $$->add_element($1);}
  2314 	{$$ = new enumerated_value_list_c(locloc(@$)); $$->add_element($1);}
  2296 | enumerated_value_list ',' enumerated_value
  2315 | enumerated_value_list ',' enumerated_value
  2297 	{$$ = $1; $$->add_element($3);}
  2316 	{$$ = $1; $$->add_element($3);}
  2298 ;
  2317 ;
  2299 
  2318 
  2300 
  2319 
  2301 enumerated_value:
  2320 enumerated_value:
  2302   identifier
  2321   identifier
  2303 	{$$ = $1;}
       
  2304 | prev_declared_enumerated_type_name '#' any_identifier
  2322 | prev_declared_enumerated_type_name '#' any_identifier
  2305 	{$$ = new enumerated_value_c($1, $3);}
  2323 	{$$ = new enumerated_value_c($1, $3, locloc(@$));}
  2306 ;
  2324 ;
  2307 
  2325 
  2308 
  2326 
  2309 enumerated_value_without_identifier:
  2327 enumerated_value_without_identifier:
  2310   prev_declared_enumerated_type_name '#' any_identifier
  2328   prev_declared_enumerated_type_name '#' any_identifier
  2311 	{$$ = new enumerated_value_c($1, $3);}
  2329 	{$$ = new enumerated_value_c($1, $3, locloc(@$));}
  2312 ;
  2330 ;
  2313 
  2331 
  2314 
  2332 
  2315 array_type_declaration:
  2333 array_type_declaration:
  2316 /*  array_type_name ':' array_spec_init */
  2334 /*  array_type_name ':' array_spec_init */
  2317   identifier ':' array_spec_init
  2335   identifier ':' array_spec_init
  2318 	{$$ = new array_type_declaration_c($1, $3);
  2336 	{$$ = new array_type_declaration_c($1, $3, locloc(@$));
  2319 	 library_element_symtable.insert($1, prev_declared_array_type_name_token);
  2337 	 library_element_symtable.insert($1, prev_declared_array_type_name_token);
  2320 	}
  2338 	}
  2321 ;
  2339 ;
  2322 
  2340 
  2323 array_spec_init:
  2341 array_spec_init:
  2324   array_specification
  2342   array_specification
  2325 	{$$ = new array_spec_init_c($1, NULL);}
  2343 	{$$ = new array_spec_init_c($1, NULL, locloc(@$));}
  2326 | array_specification ASSIGN array_initialization
  2344 | array_specification ASSIGN array_initialization
  2327 	{$$ = new array_spec_init_c($1, $3);}
  2345 	{$$ = new array_spec_init_c($1, $3, locloc(@$));}
  2328 ;
  2346 ;
  2329 
  2347 
  2330 
  2348 
  2331 array_specification:
  2349 array_specification:
  2332   prev_declared_array_type_name
  2350   prev_declared_array_type_name
  2333 	{$$ = $1;}
       
  2334 | ARRAY '[' array_subrange_list ']' OF non_generic_type_name
  2351 | ARRAY '[' array_subrange_list ']' OF non_generic_type_name
  2335 	{$$ = new array_specification_c($3, $6);}
  2352 	{$$ = new array_specification_c($3, $6, locloc(@$));}
  2336 ;
  2353 ;
  2337 
  2354 
  2338 /* helper symbol for array_specification */
  2355 /* helper symbol for array_specification */
  2339 array_subrange_list:
  2356 array_subrange_list:
  2340   subrange
  2357   subrange
  2341 	{$$ = new array_subrange_list_c(); $$->add_element($1);}
  2358 	{$$ = new array_subrange_list_c(locloc(@$)); $$->add_element($1);}
  2342 | array_subrange_list ',' subrange
  2359 | array_subrange_list ',' subrange
  2343 	{$$ = $1; $$->add_element($1);}
  2360 	{$$ = $1; $$->add_element($1);}
  2344 ;
  2361 ;
  2345 
  2362 
  2346 
  2363 
  2351 
  2368 
  2352 
  2369 
  2353 /* helper symbol for array_initialization */
  2370 /* helper symbol for array_initialization */
  2354 array_initial_elements_list:
  2371 array_initial_elements_list:
  2355   array_initial_elements
  2372   array_initial_elements
  2356 	{$$ = new array_initial_elements_list_c(); $$->add_element($1);}
  2373 	{$$ = new array_initial_elements_list_c(locloc(@$)); $$->add_element($1);}
  2357 | array_initial_elements_list ',' array_initial_elements
  2374 | array_initial_elements_list ',' array_initial_elements
  2358 	{$$ = $1; $$->add_element($3);}
  2375 	{$$ = $1; $$->add_element($3);}
  2359 ;
  2376 ;
  2360 
  2377 
  2361 
  2378 
  2362 array_initial_elements:
  2379 array_initial_elements:
  2363   array_initial_element
  2380   array_initial_element
  2364 | integer '(' ')'
  2381 | integer '(' ')'
  2365 | integer '(' array_initial_element ')'
  2382 | integer '(' array_initial_element ')'
  2366 	{$$ = new array_initial_elements_c($1, $3);}
  2383 	{$$ = new array_initial_elements_c($1, $3, locloc(@$));}
  2367 ;
  2384 ;
  2368 
  2385 
  2369 
  2386 
  2370 array_initial_element:
  2387 array_initial_element:
  2371   constant
  2388   constant
  2377 
  2394 
  2378 
  2395 
  2379 structure_type_declaration:
  2396 structure_type_declaration:
  2380 /*  structure_type_name ':' structure_specification */
  2397 /*  structure_type_name ':' structure_specification */
  2381   identifier ':' structure_specification
  2398   identifier ':' structure_specification
  2382 	{$$ = new structure_type_declaration_c($1, $3);
  2399 	{$$ = new structure_type_declaration_c($1, $3, locloc(@$));
  2383 	 library_element_symtable.insert($1, prev_declared_structure_type_name_token);
  2400 	 library_element_symtable.insert($1, prev_declared_structure_type_name_token);
  2384 	}
  2401 	}
  2385 ;
  2402 ;
  2386 
  2403 
  2387 
  2404 
  2391 ;
  2408 ;
  2392 
  2409 
  2393 
  2410 
  2394 initialized_structure:
  2411 initialized_structure:
  2395   prev_declared_structure_type_name
  2412   prev_declared_structure_type_name
  2396 	{$$ = new initialized_structure_c($1, NULL);}
  2413 	{$$ = new initialized_structure_c($1, NULL, locloc(@$));}
  2397 | prev_declared_structure_type_name ASSIGN structure_initialization
  2414 | prev_declared_structure_type_name ASSIGN structure_initialization
  2398 	{$$ = new initialized_structure_c($1, $3);}
  2415 	{$$ = new initialized_structure_c($1, $3, locloc(@$));}
  2399 ;
  2416 ;
  2400 
  2417 
  2401 
  2418 
  2402 structure_declaration:
  2419 structure_declaration:
  2403   STRUCT structure_element_declaration_list END_STRUCT
  2420   STRUCT structure_element_declaration_list END_STRUCT
  2405 ;
  2422 ;
  2406 
  2423 
  2407 /* helper symbol for structure_declaration */
  2424 /* helper symbol for structure_declaration */
  2408 structure_element_declaration_list:
  2425 structure_element_declaration_list:
  2409   structure_element_declaration ';'
  2426   structure_element_declaration ';'
  2410 	{$$ = new structure_element_declaration_list_c(); $$->add_element($1);}
  2427 	{$$ = new structure_element_declaration_list_c(locloc(@$)); $$->add_element($1);}
  2411 | structure_element_declaration_list structure_element_declaration ';'
  2428 | structure_element_declaration_list structure_element_declaration ';'
  2412 	{$$ = $1; $$->add_element($2);}
  2429 	{$$ = $1; $$->add_element($2);}
  2413 ;
  2430 ;
  2414 
  2431 
  2415 
  2432 
  2416 structure_element_declaration:
  2433 structure_element_declaration:
  2417   structure_element_name ':' simple_spec_init
  2434   structure_element_name ':' simple_spec_init
  2418 	{$$ = new structure_element_declaration_c($1, $3);}
  2435 	{$$ = new structure_element_declaration_c($1, $3, locloc(@$));}
  2419 | structure_element_name ':' subrange_spec_init
  2436 | structure_element_name ':' subrange_spec_init
  2420 	{$$ = new structure_element_declaration_c($1, $3);}
  2437 	{$$ = new structure_element_declaration_c($1, $3, locloc(@$));}
  2421 | structure_element_name ':' enumerated_spec_init
  2438 | structure_element_name ':' enumerated_spec_init
  2422 	{$$ = new structure_element_declaration_c($1, $3);}
  2439 	{$$ = new structure_element_declaration_c($1, $3, locloc(@$));}
  2423 | structure_element_name ':' array_spec_init
  2440 | structure_element_name ':' array_spec_init
  2424 	{$$ = new structure_element_declaration_c($1, $3);}
  2441 	{$$ = new structure_element_declaration_c($1, $3, locloc(@$));}
  2425 | structure_element_name ':' initialized_structure
  2442 | structure_element_name ':' initialized_structure
  2426 	{$$ = new structure_element_declaration_c($1, $3);}
  2443 	{$$ = new structure_element_declaration_c($1, $3, locloc(@$));}
  2427 ;
  2444 ;
  2428 
  2445 
  2429 
  2446 
  2430 structure_element_name: any_identifier;
  2447 structure_element_name: any_identifier;
  2431 
  2448 
  2436 ;
  2453 ;
  2437 
  2454 
  2438 /* helper symbol for structure_initialization */
  2455 /* helper symbol for structure_initialization */
  2439 structure_element_initialization_list:
  2456 structure_element_initialization_list:
  2440   structure_element_initialization
  2457   structure_element_initialization
  2441 	{$$ = new structure_element_initialization_list_c(); $$->add_element($1);}
  2458 	{$$ = new structure_element_initialization_list_c(locloc(@$)); $$->add_element($1);}
  2442 | structure_element_initialization_list ',' structure_element_initialization
  2459 | structure_element_initialization_list ',' structure_element_initialization
  2443 	{$$ = $1; $$->add_element($3);}
  2460 	{$$ = $1; $$->add_element($3);}
  2444 ;
  2461 ;
  2445 
  2462 
  2446 
  2463 
  2447 structure_element_initialization:
  2464 structure_element_initialization:
  2448   structure_element_name ASSIGN constant
  2465   structure_element_name ASSIGN constant
  2449 	{$$ = new structure_element_initialization_c($1, $3);}
  2466 	{$$ = new structure_element_initialization_c($1, $3, locloc(@$));}
  2450 | structure_element_name ASSIGN enumerated_value
  2467 | structure_element_name ASSIGN enumerated_value
  2451 	{$$ = new structure_element_initialization_c($1, $3);}
  2468 	{$$ = new structure_element_initialization_c($1, $3, locloc(@$));}
  2452 | structure_element_name ASSIGN array_initialization
  2469 | structure_element_name ASSIGN array_initialization
  2453 	{$$ = new structure_element_initialization_c($1, $3);}
  2470 	{$$ = new structure_element_initialization_c($1, $3, locloc(@$));}
  2454 | structure_element_name ASSIGN structure_initialization
  2471 | structure_element_name ASSIGN structure_initialization
  2455 	{$$ = new structure_element_initialization_c($1, $3);}
  2472 	{$$ = new structure_element_initialization_c($1, $3, locloc(@$));}
  2456 ;
  2473 ;
  2457 
  2474 
  2458 /* NOTE: in order to remove a reduce/reduce conflict,
  2475 /* NOTE: in order to remove a reduce/reduce conflict,
  2459  *       all occurences of string_type_name
  2476  *       all occurences of string_type_name
  2460  *       have been replaced with identifier!
  2477  *       have been replaced with identifier!
  2464 */
  2481 */
  2465 
  2482 
  2466 string_type_declaration:
  2483 string_type_declaration:
  2467 /*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
  2484 /*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
  2468   identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init
  2485   identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init
  2469 	{$$ = new string_type_declaration_c($1, $3, $4, $5);
  2486 	{$$ = new string_type_declaration_c($1, $3, $4, $5, locloc(@$));
  2470 	 library_element_symtable.insert($1, prev_declared_string_type_name_token);
  2487 	 library_element_symtable.insert($1, prev_declared_string_type_name_token);
  2471 	}
  2488 	}
  2472 ;
  2489 ;
  2473 
  2490 
  2474 
  2491 
  2515 | direct_variable
  2532 | direct_variable
  2516 ;
  2533 ;
  2517 
  2534 
  2518 
  2535 
  2519 symbolic_variable:
  2536 symbolic_variable:
  2520 /* NOTE: To be entirely correct, variable_name should be replacemed by
  2537 /* NOTE: To be entirely correct, variable_name must be replacemed by
  2521  *         prev_declared_variable_name | prev_declared_fb_name | prev_declared_global_var_name
  2538  *         prev_declared_variable_name | prev_declared_fb_name | prev_declared_global_var_name
  2522  */
  2539  */
  2523  identifier
  2540  identifier
  2524 	{$$ = new symbolic_variable_c($1);}
  2541 	{$$ = new symbolic_variable_c($1, locloc(@$));}
  2525 | prev_declared_fb_name
  2542 | prev_declared_fb_name
  2526 	{$$ = new symbolic_variable_c($1);}
  2543 	{$$ = new symbolic_variable_c($1, locloc(@$));}
  2527 | prev_declared_global_var_name
  2544 | prev_declared_global_var_name
  2528 	{$$ = new symbolic_variable_c($1);}
  2545 	{$$ = new symbolic_variable_c($1, locloc(@$));}
  2529 | prev_declared_variable_name
  2546 | prev_declared_variable_name
  2530 	{$$ = new symbolic_variable_c($1);}
  2547 	{$$ = new symbolic_variable_c($1, locloc(@$));}
  2531 | multi_element_variable
  2548 | multi_element_variable
  2532 ;
  2549 ;
  2533 
  2550 
  2534 
  2551 
  2535 /* NOTE: in section B 1.7, when configuring a program, symbolic_variable
  2552 /* NOTE: in section B 1.7, when configuring a program, symbolic_variable
  2542  *       variables, function blocks, etc...
  2559  *       variables, function blocks, etc...
  2543  */
  2560  */
  2544 any_symbolic_variable:
  2561 any_symbolic_variable:
  2545 // variable_name -> replaced by any_identifier
  2562 // variable_name -> replaced by any_identifier
  2546   any_identifier
  2563   any_identifier
  2547 	{$$ = new symbolic_variable_c($1);}
  2564 	{$$ = new symbolic_variable_c($1, locloc(@$));}
  2548 | any_multi_element_variable
  2565 | any_multi_element_variable
  2549 ;
  2566 ;
  2550 
  2567 
  2551 
  2568 
  2552 /* for yet undeclared variable names ! */
  2569 /* for yet undeclared variable names ! */
  2557 
  2574 
  2558 
  2575 
  2559 /********************************************/
  2576 /********************************************/
  2560 /* B.1.4.1   Directly Represented Variables */
  2577 /* B.1.4.1   Directly Represented Variables */
  2561 /********************************************/
  2578 /********************************************/
  2562 direct_variable: direct_variable_token	{$$ = new direct_variable_c($1);};
  2579 direct_variable: direct_variable_token	{$$ = new direct_variable_c($1, locloc(@$));};
  2563 
  2580 
  2564 
  2581 
  2565 
  2582 
  2566 
  2583 
  2567 /*************************************/
  2584 /*************************************/
  2579 ;
  2596 ;
  2580 
  2597 
  2581 
  2598 
  2582 array_variable:
  2599 array_variable:
  2583   subscripted_variable '[' subscript_list ']'
  2600   subscripted_variable '[' subscript_list ']'
  2584 	{$$ = new array_variable_c($1, $3);}
  2601 	{$$ = new array_variable_c($1, $3, locloc(@$));}
  2585 ;
  2602 ;
  2586 
  2603 
  2587 /* please see note above any_symbolic_variable */
  2604 /* please see note above any_symbolic_variable */
  2588 any_array_variable:
  2605 any_array_variable:
  2589   any_subscripted_variable '[' subscript_list ']'
  2606   any_subscripted_variable '[' subscript_list ']'
  2590 	{$$ = new array_variable_c($1, $3);}
  2607 	{$$ = new array_variable_c($1, $3, locloc(@$));}
  2591 ;
  2608 ;
  2592 
  2609 
  2593 
  2610 
  2594 subscripted_variable:
  2611 subscripted_variable:
  2595   symbolic_variable
  2612   symbolic_variable
  2602 ;
  2619 ;
  2603 
  2620 
  2604 
  2621 
  2605 subscript_list:
  2622 subscript_list:
  2606   subscript
  2623   subscript
  2607 	{$$ = new subscript_list_c(); $$->add_element($1);}
  2624 	{$$ = new subscript_list_c(locloc(@$)); $$->add_element($1);}
  2608 | subscript_list ',' subscript
  2625 | subscript_list ',' subscript
  2609 	{$$ = $1; $$->add_element($3);}
  2626 	{$$ = $1; $$->add_element($3);}
  2610 ;
  2627 ;
  2611 
  2628 
  2612 
  2629 
  2613 subscript:  expression;
  2630 subscript:  expression;
  2614 
  2631 
  2615 
  2632 
  2616 structured_variable:
  2633 structured_variable:
  2617   record_variable '.' field_selector
  2634   record_variable '.' field_selector
  2618 	{$$ = new structured_variable_c($1, $3);}
  2635 	{$$ = new structured_variable_c($1, $3, locloc(@$));}
  2619 ;
  2636 ;
  2620 
  2637 
  2621 
  2638 
  2622 /* please see note above any_symbolic_variable */
  2639 /* please see note above any_symbolic_variable */
  2623 any_structured_variable:
  2640 any_structured_variable:
  2624   any_record_variable '.' field_selector
  2641   any_record_variable '.' field_selector
  2625 	{$$ = new structured_variable_c($1, $3);}
  2642 	{$$ = new structured_variable_c($1, $3, locloc(@$));}
  2626 ;
  2643 ;
  2627 
  2644 
  2628 
  2645 
  2629 
  2646 
  2630 record_variable:
  2647 record_variable:
  2648 /******************************************/
  2665 /******************************************/
  2649 /* B 1.4.3 - Declaration & Initialisation */
  2666 /* B 1.4.3 - Declaration & Initialisation */
  2650 /******************************************/
  2667 /******************************************/
  2651 input_declarations:
  2668 input_declarations:
  2652   VAR_INPUT            input_declaration_list END_VAR
  2669   VAR_INPUT            input_declaration_list END_VAR
  2653 	{$$ = new input_declarations_c(NULL, $2);}
  2670 	{$$ = new input_declarations_c(NULL, $2, locloc(@$));}
  2654 | VAR_INPUT RETAIN     input_declaration_list END_VAR
  2671 | VAR_INPUT RETAIN     input_declaration_list END_VAR
  2655 	{$$ = new input_declarations_c(new retain_option_c(), $3);}
  2672 	{$$ = new input_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));}
  2656 | VAR_INPUT NON_RETAIN input_declaration_list END_VAR
  2673 | VAR_INPUT NON_RETAIN input_declaration_list END_VAR
  2657 	{$$ = new input_declarations_c(new non_retain_option_c(), $3);}
  2674 	{$$ = new input_declarations_c(new non_retain_option_c(locloc(@2)), $3, locloc(@$));}
  2658 ;
  2675 ;
  2659 
  2676 
  2660 /* helper symbol for input_declarations */
  2677 /* helper symbol for input_declarations */
  2661 input_declaration_list:
  2678 input_declaration_list:
  2662   input_declaration ';'
  2679   input_declaration ';'
  2663 	{$$ = new input_declaration_list_c(); $$->add_element($1);}
  2680 	{$$ = new input_declaration_list_c(locloc(@$)); $$->add_element($1);}
  2664 | input_declaration_list input_declaration ';'
  2681 | input_declaration_list input_declaration ';'
  2665 	{$$ = $1; $$->add_element($2);}
  2682 	{$$ = $1; $$->add_element($2);}
  2666 ;
  2683 ;
  2667 
  2684 
  2668 
  2685 
  2672 ;
  2689 ;
  2673 
  2690 
  2674 
  2691 
  2675 edge_declaration:
  2692 edge_declaration:
  2676   var1_list ':' BOOL R_EDGE
  2693   var1_list ':' BOOL R_EDGE
  2677 	{$$ = new edge_declaration_c(new raising_edge_option_c(), $1);}
  2694 	{$$ = new edge_declaration_c(new raising_edge_option_c(locloc(@3)), $1, locloc(@$));}
  2678 | var1_list ':' BOOL F_EDGE
  2695 | var1_list ':' BOOL F_EDGE
  2679 	{$$ = new edge_declaration_c(new falling_edge_option_c(), $1);}
  2696 	{$$ = new edge_declaration_c(new falling_edge_option_c(locloc(@3)), $1, locloc(@$));}
  2680 ;
  2697 ;
  2681 
  2698 
  2682 
  2699 
  2683 var_init_decl:
  2700 var_init_decl:
  2684   var1_init_decl
  2701   var1_init_decl
  2691 
  2708 
  2692 
  2709 
  2693 
  2710 
  2694 var1_init_decl:
  2711 var1_init_decl:
  2695   var1_list ':' simple_spec_init
  2712   var1_list ':' simple_spec_init
  2696 	{$$ = new var1_init_decl_c($1, $3);}
  2713 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  2697 | var1_list ':' subrange_spec_init
  2714 | var1_list ':' subrange_spec_init
  2698 	{$$ = new var1_init_decl_c($1, $3);}
  2715 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  2699 | var1_list ':' enumerated_spec_init
  2716 | var1_list ':' enumerated_spec_init
  2700 	{$$ = new var1_init_decl_c($1, $3);}
  2717 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  2701 ;
  2718 ;
  2702 
  2719 
  2703 
  2720 
  2704 var1_list:
  2721 var1_list:
  2705   variable_name
  2722   variable_name
  2706 	{$$ = new var1_list_c(); $$->add_element($1);
  2723 	{$$ = new var1_list_c(locloc(@$)); $$->add_element($1);
  2707 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2724 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2708 	}
  2725 	}
  2709  | var1_list ',' variable_name
  2726  | var1_list ',' variable_name
  2710 	{$$ = $1; $$->add_element($3);
  2727 	{$$ = $1; $$->add_element($3);
  2711 	 variable_name_symtable.insert($3, prev_declared_variable_name_token);
  2728 	 variable_name_symtable.insert($3, prev_declared_variable_name_token);
  2714 
  2731 
  2715 
  2732 
  2716 
  2733 
  2717 array_var_init_decl:
  2734 array_var_init_decl:
  2718  var1_list ':' array_spec_init
  2735  var1_list ':' array_spec_init
  2719 	{$$ = new array_var_init_decl_c($1, $3);}
  2736 	{$$ = new array_var_init_decl_c($1, $3, locloc(@$));}
  2720 ;
  2737 ;
  2721 
  2738 
  2722 
  2739 
  2723 structured_var_init_decl:
  2740 structured_var_init_decl:
  2724   var1_list ':' initialized_structure
  2741   var1_list ':' initialized_structure
  2725 	{$$ = new structured_var_init_decl_c($1, $3);}
  2742 	{$$ = new structured_var_init_decl_c($1, $3, locloc(@$));}
  2726 ;
  2743 ;
  2727 
  2744 
  2728 
  2745 
  2729 /* NOTE: see notes above fb_name_list and var1_list
  2746 /* NOTE: see notes above fb_name_list and var1_list
  2730  *       for reason why ':' was removed from this rule!
  2747  *       for reason why ':' was removed from this rule!
  2732  *       the ':' was moved to var1_list and fb_name_list!
  2749  *       the ':' was moved to var1_list and fb_name_list!
  2733  */
  2750  */
  2734 fb_name_decl:
  2751 fb_name_decl:
  2735 /*  fb_name_list ':' function_block_type_name */
  2752 /*  fb_name_list ':' function_block_type_name */
  2736   fb_name_list_with_colon function_block_type_name
  2753   fb_name_list_with_colon function_block_type_name
  2737 	{$$ = new fb_name_decl_c($1, $2, NULL);}
  2754 	{$$ = new fb_name_decl_c($1, $2, NULL, locloc(@$));}
  2738 /*| fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
  2755 /*| fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
  2739 | fb_name_list_with_colon function_block_type_name ASSIGN structure_initialization
  2756 | fb_name_list_with_colon function_block_type_name ASSIGN structure_initialization
  2740 	{$$ = new fb_name_decl_c($1, $2, $4);}
  2757 	{$$ = new fb_name_decl_c($1, $2, $4, locloc(@$));}
  2741 ;
  2758 ;
  2742 
  2759 
  2743 
  2760 
  2744 
  2761 
  2745 /* NOTE: In order to remove a reduce/reduce conflict between
  2762 /* NOTE: In order to remove a reduce/reduce conflict between
  2767 ;
  2784 ;
  2768 */
  2785 */
  2769 
  2786 
  2770 fb_name_list_with_colon:
  2787 fb_name_list_with_colon:
  2771   var1_list_with_colon
  2788   var1_list_with_colon
  2772 	{$$ = new fb_name_list_c();
  2789 	{$$ = new fb_name_list_c(locloc(@$));
  2773 	 /* fill up the new fb_name_list_c object with the references
  2790 	 /* fill up the new fb_name_list_c object with the references
  2774 	  * contained in the var1_list_c object.
  2791 	  * contained in the var1_list_c object.
  2775 	  */
  2792 	  */
  2776 	 FOR_EACH_ELEMENT(elem, $1, {$$->add_element(elem);});
  2793 	 FOR_EACH_ELEMENT(elem, $1, {$$->add_element(elem);});
  2777 	 delete $1;
  2794 	 delete $1;
  2793 
  2810 
  2794 
  2811 
  2795 
  2812 
  2796 output_declarations:
  2813 output_declarations:
  2797   VAR_OUTPUT var_init_decl_list END_VAR
  2814   VAR_OUTPUT var_init_decl_list END_VAR
  2798 	{$$ = new output_declarations_c(NULL, $2);}
  2815 	{$$ = new output_declarations_c(NULL, $2, locloc(@$));}
  2799 | VAR_OUTPUT RETAIN var_init_decl_list END_VAR
  2816 | VAR_OUTPUT RETAIN var_init_decl_list END_VAR
  2800 	{$$ = new output_declarations_c(new retain_option_c(), $3);}
  2817 	{$$ = new output_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));}
  2801 | VAR_OUTPUT NON_RETAIN var_init_decl_list END_VAR
  2818 | VAR_OUTPUT NON_RETAIN var_init_decl_list END_VAR
  2802 	{$$ = new output_declarations_c(new non_retain_option_c(), $3);}
  2819 	{$$ = new output_declarations_c(new non_retain_option_c(locloc(@2)), $3, locloc(@$));}
  2803 ;
  2820 ;
  2804 
  2821 
  2805 
  2822 
  2806 
  2823 
  2807 input_output_declarations:
  2824 input_output_declarations:
  2808   VAR_IN_OUT var_declaration_list END_VAR
  2825   VAR_IN_OUT var_declaration_list END_VAR
  2809 	{$$ = new input_output_declarations_c($2);}
  2826 	{$$ = new input_output_declarations_c($2, locloc(@$));}
  2810 ;
  2827 ;
  2811 
  2828 
  2812 
  2829 
  2813 
  2830 
  2814 /* helper symbol for input_output_declarations */
  2831 /* helper symbol for input_output_declarations */
  2815 var_declaration_list:
  2832 var_declaration_list:
  2816   var_declaration ';'
  2833   var_declaration ';'
  2817 	{$$ = new var_declaration_list_c(); $$->add_element($1);}
  2834 	{$$ = new var_declaration_list_c(locloc(@$)); $$->add_element($1);}
  2818 | var_declaration_list var_declaration ';'
  2835 | var_declaration_list var_declaration ';'
  2819 	{$$ = $1; $$->add_element($2);}
  2836 	{$$ = $1; $$->add_element($2);}
  2820 ;
  2837 ;
  2821 
  2838 
  2822 
  2839 
  2833 | string_var_declaration
  2850 | string_var_declaration
  2834 ;
  2851 ;
  2835 
  2852 
  2836 var1_declaration:
  2853 var1_declaration:
  2837   var1_list  ':' simple_specification
  2854   var1_list  ':' simple_specification
  2838 	{$$ = new var1_init_decl_c($1, $3);}
  2855 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  2839 | var1_list  ':' subrange_specification
  2856 | var1_list  ':' subrange_specification
  2840 	{$$ = new var1_init_decl_c($1, $3);}
  2857 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  2841 | var1_list  ':' enumerated_specification
  2858 | var1_list  ':' enumerated_specification
  2842 	{$$ = new var1_init_decl_c($1, $3);}
  2859 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  2843 ;
  2860 ;
  2844 
  2861 
  2845 
  2862 
  2846 
  2863 
  2847 array_var_declaration:
  2864 array_var_declaration:
  2848   var1_list ':' array_specification
  2865   var1_list ':' array_specification
  2849 	{$$ = new array_var_declaration_c($1, $3);}
  2866 	{$$ = new array_var_declaration_c($1, $3, locloc(@$));}
  2850 ;
  2867 ;
  2851 
  2868 
  2852 structured_var_declaration:
  2869 structured_var_declaration:
  2853   var1_list ':' prev_declared_structure_type_name
  2870   var1_list ':' prev_declared_structure_type_name
  2854 	{$$ = new structured_var_declaration_c($1, $3);}
  2871 	{$$ = new structured_var_declaration_c($1, $3, locloc(@$));}
  2855 ;
  2872 ;
  2856 
  2873 
  2857 
  2874 
  2858 var_declarations:
  2875 var_declarations:
  2859   VAR var_init_decl_list END_VAR
  2876   VAR var_init_decl_list END_VAR
  2860 	{$$ = new var_declarations_c(NULL, $2);}
  2877 	{$$ = new var_declarations_c(NULL, $2, locloc(@$));}
  2861 | VAR CONSTANT var_init_decl_list END_VAR
  2878 | VAR CONSTANT var_init_decl_list END_VAR
  2862 	{$$ = new var_declarations_c(new constant_option_c(), $3);}
  2879 	{$$ = new var_declarations_c(new constant_option_c(locloc(@2)), $3, locloc(@$));}
  2863 ;
  2880 ;
  2864 
  2881 
  2865 
  2882 
  2866 retentive_var_declarations:
  2883 retentive_var_declarations:
  2867   VAR RETAIN var_init_decl_list END_VAR
  2884   VAR RETAIN var_init_decl_list END_VAR
  2868 	{$$ = new retentive_var_declarations_c($3);}
  2885 	{$$ = new retentive_var_declarations_c($3, locloc(@$));}
  2869 ;
  2886 ;
  2870 
  2887 
  2871 
  2888 
  2872 located_var_declarations:
  2889 located_var_declarations:
  2873   VAR  located_var_decl_list END_VAR
  2890   VAR  located_var_decl_list END_VAR
  2874 	{$$ = new located_var_declarations_c(NULL, $2);}
  2891 	{$$ = new located_var_declarations_c(NULL, $2, locloc(@$));}
  2875 | VAR CONSTANT located_var_decl_list END_VAR
  2892 | VAR CONSTANT located_var_decl_list END_VAR
  2876 	{$$ = new located_var_declarations_c(new constant_option_c(), $3);}
  2893 	{$$ = new located_var_declarations_c(new constant_option_c(locloc(@2)), $3, locloc(@$));}
  2877 | VAR RETAIN located_var_decl_list END_VAR
  2894 | VAR RETAIN located_var_decl_list END_VAR
  2878 	{$$ = new located_var_declarations_c(new retain_option_c(), $3);}
  2895 	{$$ = new located_var_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));}
  2879 | VAR NON_RETAIN located_var_decl_list END_VAR
  2896 | VAR NON_RETAIN located_var_decl_list END_VAR
  2880 	{$$ = new located_var_declarations_c(new non_retain_option_c(), $3);}
  2897 	{$$ = new located_var_declarations_c(new non_retain_option_c(locloc(@2)), $3, locloc(@$));}
  2881 ;
  2898 ;
  2882 
  2899 
  2883 
  2900 
  2884 /* helper symbol for located_var_declarations */
  2901 /* helper symbol for located_var_declarations */
  2885 located_var_decl_list:
  2902 located_var_decl_list:
  2886   located_var_decl ';'
  2903   located_var_decl ';'
  2887 	{$$ = new located_var_decl_list_c(); $$->add_element($1);}
  2904 	{$$ = new located_var_decl_list_c(locloc(@$)); $$->add_element($1);}
  2888 | located_var_decl_list located_var_decl ';'
  2905 | located_var_decl_list located_var_decl ';'
  2889 	{$$ = $1; $$->add_element($2);}
  2906 	{$$ = $1; $$->add_element($2);}
  2890 ;
  2907 ;
  2891 
  2908 
  2892 
  2909 
  2893 located_var_decl:
  2910 located_var_decl:
  2894   variable_name location ':' located_var_spec_init
  2911   variable_name location ':' located_var_spec_init
  2895 	{$$ = new located_var_decl_c($1, $2, $4);
  2912 	{$$ = new located_var_decl_c($1, $2, $4, locloc(@$));
  2896 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2913 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2897 	}
  2914 	}
  2898 | location ':' located_var_spec_init
  2915 | location ':' located_var_spec_init
  2899 	{$$ = new located_var_decl_c(NULL, $1, $3);}
  2916 	{$$ = new located_var_decl_c(NULL, $1, $3, locloc(@$));}
  2900 ;
  2917 ;
  2901 
  2918 
  2902 
  2919 
  2903 
  2920 
  2904 
  2921 
  2905 external_var_declarations:
  2922 external_var_declarations:
  2906   VAR_EXTERNAL external_declaration_list END_VAR
  2923   VAR_EXTERNAL external_declaration_list END_VAR
  2907 	{$$ = new external_var_declarations_c(NULL, $2);}
  2924 	{$$ = new external_var_declarations_c(NULL, $2, locloc(@$));}
  2908 | VAR_EXTERNAL CONSTANT external_declaration_list END_VAR
  2925 | VAR_EXTERNAL CONSTANT external_declaration_list END_VAR
  2909 	{$$ = new external_var_declarations_c(new constant_option_c(), $3);}
  2926 	{$$ = new external_var_declarations_c(new constant_option_c(locloc(@2)), $3, locloc(@$));}
  2910 ;
  2927 ;
  2911 
  2928 
  2912 /* helper symbol for external_var_declarations */
  2929 /* helper symbol for external_var_declarations */
  2913 external_declaration_list:
  2930 external_declaration_list:
  2914   external_declaration ';'
  2931   external_declaration ';'
  2915 	{$$ = new external_declaration_list_c(); $$->add_element($1);}
  2932 	{$$ = new external_declaration_list_c(locloc(@$)); $$->add_element($1);}
  2916 | external_declaration_list external_declaration';'
  2933 | external_declaration_list external_declaration';'
  2917 	{$$ = $1; $$->add_element($2);}
  2934 	{$$ = $1; $$->add_element($2);}
  2918 ;
  2935 ;
  2919 
  2936 
  2920 
  2937 
  2921 external_declaration:
  2938 external_declaration:
  2922   global_var_name ':' simple_specification
  2939   global_var_name ':' simple_specification
  2923 	{$$ = new external_declaration_c($1, $3);
  2940 	{$$ = new external_declaration_c($1, $3, locloc(@$));
  2924 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2941 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2925 	}
  2942 	}
  2926 | global_var_name ':' subrange_specification
  2943 | global_var_name ':' subrange_specification
  2927 	{$$ = new external_declaration_c($1, $3);
  2944 	{$$ = new external_declaration_c($1, $3, locloc(@$));
  2928 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2945 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2929 	}
  2946 	}
  2930 | global_var_name ':' enumerated_specification
  2947 | global_var_name ':' enumerated_specification
  2931 	{$$ = new external_declaration_c($1, $3);
  2948 	{$$ = new external_declaration_c($1, $3, locloc(@$));
  2932 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2949 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2933 	}
  2950 	}
  2934 | global_var_name ':' array_specification
  2951 | global_var_name ':' array_specification
  2935 	{$$ = new external_declaration_c($1, $3);
  2952 	{$$ = new external_declaration_c($1, $3, locloc(@$));
  2936 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2953 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2937 	}
  2954 	}
  2938 | global_var_name ':' prev_declared_structure_type_name
  2955 | global_var_name ':' prev_declared_structure_type_name
  2939 	{$$ = new external_declaration_c($1, $3);
  2956 	{$$ = new external_declaration_c($1, $3, locloc(@$));
  2940 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2957 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  2941 	}
  2958 	}
  2942 | global_var_name ':' function_block_type_name
  2959 | global_var_name ':' function_block_type_name
  2943 	{$$ = new external_declaration_c($1, $3);
  2960 	{$$ = new external_declaration_c($1, $3, locloc(@$));
  2944 	 variable_name_symtable.insert($1, prev_declared_fb_name_token);
  2961 	 variable_name_symtable.insert($1, prev_declared_fb_name_token);
  2945 	}
  2962 	}
  2946 ;
  2963 ;
  2947 
  2964 
  2948 
  2965 
  2949 global_var_name: identifier;
  2966 global_var_name: identifier;
  2950 
  2967 
  2951 
  2968 
  2952 global_var_declarations:
  2969 global_var_declarations:
  2953   VAR_GLOBAL global_var_decl_list END_VAR
  2970   VAR_GLOBAL global_var_decl_list END_VAR
  2954 	{$$ = new global_var_declarations_c(NULL, $2);}
  2971 	{$$ = new global_var_declarations_c(NULL, $2, locloc(@$));}
  2955 | VAR_GLOBAL CONSTANT global_var_decl_list END_VAR
  2972 | VAR_GLOBAL CONSTANT global_var_decl_list END_VAR
  2956 	{$$ = new global_var_declarations_c(new constant_option_c(), $3);}
  2973 	{$$ = new global_var_declarations_c(new constant_option_c(locloc(@2)), $3, locloc(@$));}
  2957 | VAR_GLOBAL RETAIN global_var_decl_list END_VAR
  2974 | VAR_GLOBAL RETAIN global_var_decl_list END_VAR
  2958 	{$$ = new global_var_declarations_c(new retain_option_c(), $3);}
  2975 	{$$ = new global_var_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));}
  2959 ;
  2976 ;
  2960 
  2977 
  2961 
  2978 
  2962 /* helper symbol for global_var_declarations */
  2979 /* helper symbol for global_var_declarations */
  2963 global_var_decl_list:
  2980 global_var_decl_list:
  2964   global_var_decl ';'
  2981   global_var_decl ';'
  2965 	{$$ = new global_var_decl_list_c(); $$->add_element($1);}
  2982 	{$$ = new global_var_decl_list_c(locloc(@$)); $$->add_element($1);}
  2966 | global_var_decl_list global_var_decl ';'
  2983 | global_var_decl_list global_var_decl ';'
  2967 	{$$ = $1; $$->add_element($2);}
  2984 	{$$ = $1; $$->add_element($2);}
  2968 ;
  2985 ;
  2969 
  2986 
  2970 
  2987 
  2971 global_var_decl:
  2988 global_var_decl:
  2972   global_var_spec ':'
  2989   global_var_spec ':'
  2973 	{$$ = new global_var_decl_c($1, NULL);}
  2990 	{$$ = new global_var_decl_c($1, NULL, locloc(@$));}
  2974 | global_var_spec ':' located_var_spec_init
  2991 | global_var_spec ':' located_var_spec_init
  2975 	{$$ = new global_var_decl_c($1, $3);}
  2992 	{$$ = new global_var_decl_c($1, $3, locloc(@$));}
  2976 | global_var_spec ':' function_block_type_name
  2993 | global_var_spec ':' function_block_type_name
  2977 	{$$ = new global_var_decl_c($1, $3);}
  2994 	{$$ = new global_var_decl_c($1, $3, locloc(@$));}
  2978 ;
  2995 ;
  2979 
  2996 
  2980 
  2997 
  2981 global_var_spec:
  2998 global_var_spec:
  2982   global_var_list	{$$ = $1;}
  2999   global_var_list	{$$ = $1;}
  2983 | location
  3000 | location
  2984 	{$$ = new global_var_spec_c(NULL, $1);}
  3001 	{$$ = new global_var_spec_c(NULL, $1, locloc(@$));}
  2985 | global_var_name location
  3002 | global_var_name location
  2986 	{$$ = new global_var_spec_c($1, $2);
  3003 	{$$ = new global_var_spec_c($1, $2, locloc(@$));
  2987 	 variable_name_symtable.insert($1, prev_declared_global_var_name_token);
  3004 	 variable_name_symtable.insert($1, prev_declared_global_var_name_token);
  2988 	}
  3005 	}
  2989 
  3006 
  2990 ;
  3007 ;
  2991 
  3008 
  3001 ;
  3018 ;
  3002 
  3019 
  3003 
  3020 
  3004 location:
  3021 location:
  3005   AT direct_variable
  3022   AT direct_variable
  3006 	{$$ = new location_c($2);}
  3023 	{$$ = new location_c($2, locloc(@$));}
  3007 ;
  3024 ;
  3008 
  3025 
  3009 
  3026 
  3010 
  3027 
  3011 global_var_list:
  3028 global_var_list:
  3012   global_var_name
  3029   global_var_name
  3013 	{$$ = new global_var_list_c(); $$->add_element($1);
  3030 	{$$ = new global_var_list_c(locloc(@$)); $$->add_element($1);
  3014 	 variable_name_symtable.insert($1, prev_declared_global_var_name_token);
  3031 	 variable_name_symtable.insert($1, prev_declared_global_var_name_token);
  3015 	}
  3032 	}
  3016 | global_var_list ',' global_var_name
  3033 | global_var_list ',' global_var_name
  3017 	{$$ = $1; $$->add_element($3);
  3034 	{$$ = $1; $$->add_element($3);
  3018 	 variable_name_symtable.insert($3, prev_declared_global_var_name_token);
  3035 	 variable_name_symtable.insert($3, prev_declared_global_var_name_token);
  3026 | double_byte_string_var_declaration
  3043 | double_byte_string_var_declaration
  3027 ;
  3044 ;
  3028 
  3045 
  3029 single_byte_string_var_declaration:
  3046 single_byte_string_var_declaration:
  3030   var1_list ':' single_byte_string_spec
  3047   var1_list ':' single_byte_string_spec
  3031 	{$$ = new single_byte_string_var_declaration_c($1, $3);}
  3048 	{$$ = new single_byte_string_var_declaration_c($1, $3, locloc(@$));}
  3032 ;
  3049 ;
  3033 
  3050 
  3034 /* NOTE: The constructs
  3051 /* NOTE: The constructs
  3035  *
  3052  *
  3036  *       [W]STRING
  3053  *       [W]STRING
  3066 single_byte_string_spec:
  3083 single_byte_string_spec:
  3067 /*  STRING
  3084 /*  STRING
  3068 	{$$ = new single_byte_string_spec_c(NULL, NULL);}
  3085 	{$$ = new single_byte_string_spec_c(NULL, NULL);}
  3069 */
  3086 */
  3070   STRING '[' integer ']'
  3087   STRING '[' integer ']'
  3071 	{$$ = new single_byte_string_spec_c($3, NULL);}
  3088 	{$$ = new single_byte_string_spec_c($3, NULL, locloc(@$));}
  3072 /*
  3089 /*
  3073 | STRING ASSIGN single_byte_character_string
  3090 | STRING ASSIGN single_byte_character_string
  3074 	{$$ = new single_byte_string_spec_c(NULL, $3);}
  3091 	{$$ = new single_byte_string_spec_c(NULL, $3, locloc(@$));}
  3075 */
  3092 */
  3076 | STRING '[' integer ']' ASSIGN single_byte_character_string
  3093 | STRING '[' integer ']' ASSIGN single_byte_character_string
  3077 	{$$ = new single_byte_string_spec_c($3, $6);}
  3094 	{$$ = new single_byte_string_spec_c($3, $6, locloc(@$));}
  3078 ;
  3095 ;
  3079 
  3096 
  3080 
  3097 
  3081 double_byte_string_var_declaration:
  3098 double_byte_string_var_declaration:
  3082   var1_list ':' double_byte_string_spec
  3099   var1_list ':' double_byte_string_spec
  3083 	{$$ = new double_byte_string_var_declaration_c($1, $3);}
  3100 	{$$ = new double_byte_string_var_declaration_c($1, $3, locloc(@$));}
  3084 ;
  3101 ;
  3085 
  3102 
  3086 double_byte_string_spec:
  3103 double_byte_string_spec:
  3087 /*  WSTRING
  3104 /*  WSTRING
  3088 	{$$ = new double_byte_string_spec_c(NULL, NULL);}
  3105 	{$$ = new double_byte_string_spec_c(NULL, NULL, locloc(@$));}
  3089 */
  3106 */
  3090   WSTRING '[' integer ']'
  3107   WSTRING '[' integer ']'
  3091 	{$$ = new double_byte_string_spec_c($3, NULL);}
  3108 	{$$ = new double_byte_string_spec_c($3, NULL, locloc(@$));}
  3092 /*
  3109 /*
  3093 | WSTRING ASSIGN double_byte_character_string
  3110 | WSTRING ASSIGN double_byte_character_string
  3094 	{$$ = new double_byte_string_spec_c(NULL, $3);}
  3111 	{$$ = new double_byte_string_spec_c(NULL, $3, locloc(@$));}
  3095 */
  3112 */
  3096 | WSTRING '[' integer ']' ASSIGN double_byte_character_string
  3113 | WSTRING '[' integer ']' ASSIGN double_byte_character_string
  3097 	{$$ = new double_byte_string_spec_c($3, $6);}
  3114 	{$$ = new double_byte_string_spec_c($3, $6, locloc(@$));}
  3098 ;
  3115 ;
  3099 
  3116 
  3100 
  3117 
  3101 
  3118 
  3102 incompl_located_var_declarations:
  3119 incompl_located_var_declarations:
  3103   VAR            incompl_located_var_decl_list END_VAR
  3120   VAR            incompl_located_var_decl_list END_VAR
  3104 	{$$ = new incompl_located_var_declarations_c(NULL, $2);}
  3121 	{$$ = new incompl_located_var_declarations_c(NULL, $2, locloc(@$));}
  3105 | VAR     RETAIN incompl_located_var_decl_list END_VAR
  3122 | VAR     RETAIN incompl_located_var_decl_list END_VAR
  3106 	{$$ = new incompl_located_var_declarations_c(new retain_option_c(), $3);}
  3123 	{$$ = new incompl_located_var_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));}
  3107 | VAR NON_RETAIN incompl_located_var_decl_list END_VAR
  3124 | VAR NON_RETAIN incompl_located_var_decl_list END_VAR
  3108 	{$$ = new incompl_located_var_declarations_c(new non_retain_option_c(), $3);}
  3125 	{$$ = new incompl_located_var_declarations_c(new non_retain_option_c(locloc(@2)), $3, locloc(@$));}
  3109 ;
  3126 ;
  3110 
  3127 
  3111 /* helper symbol for incompl_located_var_declarations */
  3128 /* helper symbol for incompl_located_var_declarations */
  3112 incompl_located_var_decl_list:
  3129 incompl_located_var_decl_list:
  3113   incompl_located_var_decl ';'
  3130   incompl_located_var_decl ';'
  3114 	{$$ = new incompl_located_var_decl_list_c(); $$->add_element($1);}
  3131 	{$$ = new incompl_located_var_decl_list_c(locloc(@$)); $$->add_element($1);}
  3115 | incompl_located_var_decl_list incompl_located_var_decl ';'
  3132 | incompl_located_var_decl_list incompl_located_var_decl ';'
  3116 	{$$ = $1; $$->add_element($2);}
  3133 	{$$ = $1; $$->add_element($2);}
  3117 ;
  3134 ;
  3118 
  3135 
  3119 
  3136 
  3120 incompl_located_var_decl:
  3137 incompl_located_var_decl:
  3121   variable_name incompl_location ':' var_spec
  3138   variable_name incompl_location ':' var_spec
  3122 	{$$ = new incompl_located_var_decl_c($1, $2, $4);}
  3139 	{$$ = new incompl_located_var_decl_c($1, $2, $4, locloc(@$));}
  3123 ;
  3140 ;
  3124 
  3141 
  3125 
  3142 
  3126 incompl_location:
  3143 incompl_location:
  3127   AT incompl_location_token
  3144   AT incompl_location_token
  3128 	{$$ = new incompl_location_c($2);}
  3145 	{$$ = new incompl_location_c($2, locloc(@$));}
  3129 ;
  3146 ;
  3130 
  3147 
  3131 
  3148 
  3132 var_spec:
  3149 var_spec:
  3133   simple_specification
  3150   simple_specification
  3149  *       were removed as they are already contained
  3166  *       were removed as they are already contained
  3150  *       within a simple_specification.
  3167  *       within a simple_specification.
  3151  */
  3168  */
  3152 string_spec:
  3169 string_spec:
  3153 /*  STRING
  3170 /*  STRING
  3154 	{$$ = new single_byte_string_spec_c(NULL, NULL);}
  3171 	{$$ = new single_byte_string_spec_c(NULL, NULL, locloc(@$));}
  3155 */
  3172 */
  3156   STRING '[' integer ']'
  3173   STRING '[' integer ']'
  3157 	{$$ = new single_byte_string_spec_c($3, NULL);}
  3174 	{$$ = new single_byte_string_spec_c($3, NULL, locloc(@$));}
  3158 /*
  3175 /*
  3159 | WSTRING
  3176 | WSTRING
  3160 	{$$ = new double_byte_string_spec_c(NULL, NULL);}
  3177 	{$$ = new double_byte_string_spec_c(NULL, NULL, locloc(@$));}
  3161 */
  3178 */
  3162 | WSTRING '[' integer ']'
  3179 | WSTRING '[' integer ']'
  3163 	{$$ = new double_byte_string_spec_c($3, NULL);}
  3180 	{$$ = new double_byte_string_spec_c($3, NULL, locloc(@$));}
  3164 ;
  3181 ;
  3165 
  3182 
  3166 
  3183 
  3167 
  3184 
  3168 
  3185 
  3171  *  - output_declarations
  3188  *  - output_declarations
  3172  *  - var_declarations
  3189  *  - var_declarations
  3173  */
  3190  */
  3174 var_init_decl_list:
  3191 var_init_decl_list:
  3175   var_init_decl ';'
  3192   var_init_decl ';'
  3176 	{$$ = new var_init_decl_list_c(); $$->add_element($1);}
  3193 	{$$ = new var_init_decl_list_c(locloc(@$)); $$->add_element($1);}
  3177 | var_init_decl_list var_init_decl ';'
  3194 | var_init_decl_list var_init_decl ';'
  3178 	{$$ = $1; $$->add_element($2);}
  3195 	{$$ = $1; $$->add_element($2);}
  3179 ;
  3196 ;
  3180 
  3197 
  3181 
  3198 
  3182 
  3199 
  3183 
  3200 
  3184 /***********************/
  3201 /***********************/
  3185 /* B 1.5.1 - Functions */
  3202 /* B 1.5.1 - Functions */
  3186 /***********************/
  3203 /***********************/
       
  3204 /*
       
  3205 function_name:
       
  3206   prev_declared_derived_function_name
       
  3207 | standard_function_name 
       
  3208 ;
       
  3209 */
       
  3210 
  3187 /* The following rules should be set such as:
  3211 /* The following rules should be set such as:
  3188  * function_name: function_name_no_clashes | function_name_simpleop_clashes | function_name_expression_clashes
  3212  * function_name: function_name_no_clashes | function_name_simpleop_clashes | function_name_expression_clashes
  3189  * function_name: function_name_no_NOT_clashes | function_name_NOT_clashes;
  3213  * function_name: function_name_no_NOT_clashes | function_name_NOT_clashes;
  3190  */
  3214  */
  3191 
  3215 
  3194 //function_name_expression_clashes: standard_function_name_expression_clashes;
  3218 //function_name_expression_clashes: standard_function_name_expression_clashes;
  3195 
  3219 
  3196 function_name_no_NOT_clashes: prev_declared_derived_function_name | standard_function_name_no_NOT_clashes;
  3220 function_name_no_NOT_clashes: prev_declared_derived_function_name | standard_function_name_no_NOT_clashes;
  3197 //function_name_NOT_clashes: standard_function_name_NOT_clashes;
  3221 //function_name_NOT_clashes: standard_function_name_NOT_clashes;
  3198 
  3222 
  3199 /*
       
  3200 function_name:
       
  3201   prev_declared_derived_function_name
       
  3202 | standard_function_name
       
  3203 ;
       
  3204 */
       
  3205 
  3223 
  3206 /* NOTE: The list of standard function names
  3224 /* NOTE: The list of standard function names
  3207  *       includes the standard functions MOD(), NOT()
  3225  *       includes the standard functions MOD(), NOT()
  3208  *
  3226  *
  3209  *       Strangely enough, MOD and NOT are reserved keywords,
  3227  *       Strangely enough, MOD and NOT are reserved keywords,
  3272 //| standard_function_name_simpleop_only_clashes
  3290 //| standard_function_name_simpleop_only_clashes
  3273 ;
  3291 ;
  3274 
  3292 
  3275 standard_function_name_no_clashes:
  3293 standard_function_name_no_clashes:
  3276   standard_function_name_token
  3294   standard_function_name_token
  3277 	{$$ = new identifier_c($1);}
  3295 	{$$ = new identifier_c($1, locloc(@$));}
  3278 ;
  3296 ;
  3279 
  3297 
  3280 
  3298 
  3281 standard_function_name_simpleop_clashes:
  3299 standard_function_name_simpleop_clashes:
  3282   standard_function_name_NOT_clashes
  3300   standard_function_name_NOT_clashes
  3283 //| standard_function_name_simpleop_only_clashes
  3301 //| standard_function_name_simpleop_only_clashes
  3284 ;
  3302 ;
  3285 
  3303 
  3286 standard_function_name_NOT_clashes:
  3304 standard_function_name_NOT_clashes:
  3287   NOT
  3305   NOT
  3288 	{$$ = new identifier_c(strdup("NOT"));}
  3306 	{$$ = new identifier_c(strdup("NOT"), locloc(@$));}
  3289 ;
  3307 ;
  3290 
  3308 
  3291 /* Add here any other IL simple operators that collide
  3309 /* Add here any other IL simple operators that collide
  3292  * with standard function names!
  3310  * with standard function names!
  3293  * Don't forget to uncomment the equivalent lines in
  3311  * Don't forget to uncomment the equivalent lines in
  3332 
  3350 
  3333 
  3351 
  3334 function_declaration:
  3352 function_declaration:
  3335 /*  FUNCTION derived_function_name ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
  3353 /*  FUNCTION derived_function_name ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
  3336   function_name_declaration ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION
  3354   function_name_declaration ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION
  3337 	{$$ = new function_declaration_c($1, $3, $4, $5);
  3355 	{$$ = new function_declaration_c($1, $3, $4, $5, locloc(@$));
  3338 	 variable_name_symtable.pop();
  3356 	 variable_name_symtable.pop();
  3339 	 if (allow_function_overloading) {
  3357 	 if (allow_function_overloading) {
  3340 	   switch (library_element_symtable.find_value($1)) {
  3358 	   switch (library_element_symtable.find_value($1)) {
  3341 	     case prev_declared_derived_function_name_token:
  3359 	     case prev_declared_derived_function_name_token:
  3342 	       /* do nothing, already in map. */
  3360 	       /* do nothing, already in map. */
  3353 	   library_element_symtable.insert($1, prev_declared_derived_function_name_token);
  3371 	   library_element_symtable.insert($1, prev_declared_derived_function_name_token);
  3354 	 }
  3372 	 }
  3355 	}
  3373 	}
  3356 /* | FUNCTION derived_function_name ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
  3374 /* | FUNCTION derived_function_name ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
  3357 | function_name_declaration ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION
  3375 | function_name_declaration ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION
  3358 	{$$ = new function_declaration_c($1, $3, $4, $5);
  3376 	{$$ = new function_declaration_c($1, $3, $4, $5, locloc(@$));
  3359 	 variable_name_symtable.pop();
  3377 	 variable_name_symtable.pop();
  3360 	 if (allow_function_overloading) {
  3378 	 if (allow_function_overloading) {
  3361 	   switch (library_element_symtable.find_value($1)) {
  3379 	   switch (library_element_symtable.find_value($1)) {
  3362 	     case prev_declared_derived_function_name_token: /* do nothing, already in map. */ break;
  3380 	     case prev_declared_derived_function_name_token: /* do nothing, already in map. */ break;
  3363 	     case BOGUS_TOKEN_ID: library_element_symtable.insert($1, prev_declared_derived_function_name_token); break;
  3381 	     case BOGUS_TOKEN_ID: library_element_symtable.insert($1, prev_declared_derived_function_name_token); break;
  3365 	   }
  3383 	   }
  3366 	 } else {
  3384 	 } else {
  3367 	   library_element_symtable.insert($1, prev_declared_derived_function_name_token);
  3385 	   library_element_symtable.insert($1, prev_declared_derived_function_name_token);
  3368 	 }
  3386 	 }
  3369 	}
  3387 	}
  3370 ;
  3388 /* ERROR_CHECK_BEGIN */
       
  3389 | FUNCTION error END_FUNCTION
       
  3390 	{$$ = NULL;
       
  3391 	 print_err_msg(current_filename, @2.first_line, "error in function declaration.");
       
  3392 	 /* yychar */
       
  3393 	 yyerrok;
       
  3394 	}
       
  3395 /* ERROR_CHECK_END */
       
  3396 ;
       
  3397 
       
  3398 
  3371 
  3399 
  3372 /* helper symbol for function_declaration */
  3400 /* helper symbol for function_declaration */
  3373 /* NOTE: due to reduce/reduce conflicts between identifiers
  3401 /* NOTE: due to reduce/reduce conflicts between identifiers
  3374  *       being reduced to either a variable or an enumerator value,
  3402  *       being reduced to either a variable or an enumerator value,
  3375  *       we were forced to keep a symbol table of the names
  3403  *       we were forced to keep a symbol table of the names
  3416 
  3444 
  3417 
  3445 
  3418 /* intermediate helper symbol for function_declaration */
  3446 /* intermediate helper symbol for function_declaration */
  3419 io_OR_function_var_declarations_list:
  3447 io_OR_function_var_declarations_list:
  3420   /* empty */
  3448   /* empty */
  3421 	{$$ = new var_declarations_list_c();}
  3449 	{$$ = new var_declarations_list_c(locloc(@$));}
  3422 | io_OR_function_var_declarations_list io_var_declarations
  3450 | io_OR_function_var_declarations_list io_var_declarations
  3423 	{$$ = $1; $$->add_element($2);}
  3451 	{$$ = $1; $$->add_element($2);}
  3424 | io_OR_function_var_declarations_list function_var_decls
  3452 | io_OR_function_var_declarations_list function_var_decls
  3425 	{$$ = $1; $$->add_element($2);}
  3453 	{$$ = $1; $$->add_element($2);}
  3426 ;
  3454 ;
  3433 ;
  3461 ;
  3434 
  3462 
  3435 
  3463 
  3436 function_var_decls:
  3464 function_var_decls:
  3437   VAR CONSTANT var2_init_decl_list END_VAR
  3465   VAR CONSTANT var2_init_decl_list END_VAR
  3438 	{$$ = new function_var_decls_c(new constant_option_c(), $3);}
  3466 	{$$ = new function_var_decls_c(new constant_option_c(locloc(@2)), $3, locloc(@$));}
  3439 | VAR var2_init_decl_list END_VAR
  3467 | VAR var2_init_decl_list END_VAR
  3440 	{$$ = new function_var_decls_c(NULL, $2);}
  3468 	{$$ = new function_var_decls_c(NULL, $2, locloc(@$));}
  3441 ;
  3469 ;
  3442 
  3470 
  3443 /* intermediate helper symbol for function_var_decls */
  3471 /* intermediate helper symbol for function_var_decls */
  3444 var2_init_decl_list:
  3472 var2_init_decl_list:
  3445   var2_init_decl ';'
  3473   var2_init_decl ';'
  3446 	{$$ = new var2_init_decl_list_c(); $$->add_element($1);}
  3474 	{$$ = new var2_init_decl_list_c(locloc(@$)); $$->add_element($1);}
  3447 | var2_init_decl_list var2_init_decl ';'
  3475 | var2_init_decl_list var2_init_decl ';'
  3448 	{$$ = $1; $$->add_element($2);}
  3476 	{$$ = $1; $$->add_element($2);}
  3449 ;
  3477 ;
  3450 
  3478 
  3451 
  3479 
  3475   prev_declared_derived_function_block_name
  3503   prev_declared_derived_function_block_name
  3476 | standard_function_block_name
  3504 | standard_function_block_name
  3477 ;
  3505 ;
  3478 
  3506 
  3479 
  3507 
  3480 standard_function_block_name: standard_function_block_name_token {$$ = new identifier_c($1);};
  3508 standard_function_block_name: standard_function_block_name_token {$$ = new identifier_c($1, locloc(@$));};
  3481 
  3509 
  3482 derived_function_block_name: identifier;
  3510 derived_function_block_name: identifier;
  3483 
  3511 
  3484 
  3512 
  3485 function_block_declaration:
  3513 function_block_declaration:
  3486   FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations_list function_block_body END_FUNCTION_BLOCK
  3514   FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations_list function_block_body END_FUNCTION_BLOCK
  3487 	{$$ = new function_block_declaration_c($2, $3, $4);
  3515 	{$$ = new function_block_declaration_c($2, $3, $4, locloc(@$));
  3488 	 library_element_symtable.insert($2, prev_declared_derived_function_block_name_token);
  3516 	 library_element_symtable.insert($2, prev_declared_derived_function_block_name_token);
  3489 	 /* Clear the variable_name_symtable. Since
  3517 	 /* Clear the variable_name_symtable. Since
  3490 	  * we have finished parsing the function block,
  3518 	  * we have finished parsing the function block,
  3491 	  * the variable names are now out of scope, so
  3519 	  * the variable names are now out of scope, so
  3492 	  * are no longer valid!
  3520 	  * are no longer valid!
  3493 	  */
  3521 	  */
  3494 	 variable_name_symtable.pop();
  3522 	 variable_name_symtable.pop();
  3495 	}
  3523 	}
       
  3524 /* ERROR_CHECK_BEGIN */
       
  3525 | FUNCTION_BLOCK error END_FUNCTION_BLOCK
       
  3526 	{$$ = NULL;
       
  3527 	 print_err_msg(current_filename, @2.first_line, "error in function block declaration.");
       
  3528 	 /* yychar */
       
  3529 	 yyerrok;
       
  3530 	}
       
  3531 /* ERROR_CHECK_END */
  3496 ;
  3532 ;
  3497 
  3533 
  3498 
  3534 
  3499 
  3535 
  3500 /* intermediate helper symbol for function_declaration */
  3536 /* intermediate helper symbol for function_declaration */
  3502 /*
  3538 /*
  3503  * NOTE: we re-use the var_declarations_list_c
  3539  * NOTE: we re-use the var_declarations_list_c
  3504  */
  3540  */
  3505 io_OR_other_var_declarations_list:
  3541 io_OR_other_var_declarations_list:
  3506   /* empty */
  3542   /* empty */
  3507 	{$$ = new var_declarations_list_c();}
  3543 	{$$ = new var_declarations_list_c(locloc(@$));}
  3508 | io_OR_other_var_declarations_list io_var_declarations
  3544 | io_OR_other_var_declarations_list io_var_declarations
  3509 	{$$ = $1; $$->add_element($2);}
  3545 	{$$ = $1; $$->add_element($2);}
  3510 | io_OR_other_var_declarations_list other_var_declarations
  3546 | io_OR_other_var_declarations_list other_var_declarations
  3511 	{$$ = $1; $$->add_element($2);}
  3547 	{$$ = $1; $$->add_element($2);}
  3512 ;
  3548 ;
  3537 ;
  3573 ;
  3538 
  3574 
  3539 
  3575 
  3540 temp_var_decls:
  3576 temp_var_decls:
  3541   VAR_TEMP temp_var_decls_list END_VAR
  3577   VAR_TEMP temp_var_decls_list END_VAR
  3542 	{$$ = new temp_var_decls_c($2);}
  3578 	{$$ = new temp_var_decls_c($2, locloc(@$));}
  3543 ;
  3579 ;
  3544 
  3580 
  3545 
  3581 
  3546 /* intermediate helper symbol for temp_var_decls */
  3582 /* intermediate helper symbol for temp_var_decls */
  3547 temp_var_decls_list:
  3583 temp_var_decls_list:
  3548   temp_var_decl ';'
  3584   temp_var_decl ';'
  3549 	{$$ = new temp_var_decls_list_c(); $$->add_element($1);}
  3585 	{$$ = new temp_var_decls_list_c(locloc(@$)); $$->add_element($1);}
  3550 | temp_var_decls_list temp_var_decl ';'
  3586 | temp_var_decls_list temp_var_decl ';'
  3551 	{$$ = $1; $$->add_element($2);}
  3587 	{$$ = $1; $$->add_element($2);}
  3552 ;
  3588 ;
  3553 
  3589 
  3554 
  3590 
  3555 non_retentive_var_decls:
  3591 non_retentive_var_decls:
  3556   VAR NON_RETAIN var_init_decl_list END_VAR
  3592   VAR NON_RETAIN var_init_decl_list END_VAR
  3557 	{$$ = new non_retentive_var_decls_c($3);}
  3593 	{$$ = new non_retentive_var_decls_c($3, locloc(@$));}
  3558 ;
  3594 ;
  3559 
  3595 
  3560 
  3596 
  3561 
  3597 
  3562 function_block_body:
  3598 function_block_body:
  3579 program_type_name: identifier;
  3615 program_type_name: identifier;
  3580 
  3616 
  3581 
  3617 
  3582 program_declaration:
  3618 program_declaration:
  3583   PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM
  3619   PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM
  3584 	{$$ = new program_declaration_c($2, $3, $4);
  3620 	{$$ = new program_declaration_c($2, $3, $4, locloc(@$));
  3585 	 library_element_symtable.insert($2, prev_declared_program_type_name_token);
  3621 	 library_element_symtable.insert($2, prev_declared_program_type_name_token);
  3586 	 /* Clear the variable_name_symtable. Since
  3622 	 /* Clear the variable_name_symtable. Since
  3587 	  * we have finished parsing the program declaration,
  3623 	  * we have finished parsing the program declaration,
  3588 	  * the variable names are now out of scope, so
  3624 	  * the variable names are now out of scope, so
  3589 	  * are no longer valid!
  3625 	  * are no longer valid!
  3590 	  */
  3626 	  */
  3591 	 variable_name_symtable.pop();
  3627 	 variable_name_symtable.pop();
  3592 	}
  3628 	}
       
  3629 /* ERROR_CHECK_BEGIN */
       
  3630 | PROGRAM error END_PROGRAM
       
  3631 	{$$ = NULL;
       
  3632 	 print_err_msg(current_filename, @2.first_line, "error in function block declaration.");
       
  3633 	 /* yychar */
       
  3634 	 yyerrok;
       
  3635 	}
       
  3636 /* ERROR_CHECK_END */
  3593 ;
  3637 ;
  3594 
  3638 
  3595 
  3639 
  3596 /* helper symbol for program_declaration */
  3640 /* helper symbol for program_declaration */
  3597 /*
  3641 /*
  3598  * NOTE: we re-use the var_declarations_list_c
  3642  * NOTE: we re-use the var_declarations_list_c
  3599  */
  3643  */
  3600 program_var_declarations_list:
  3644 program_var_declarations_list:
  3601   /* empty */
  3645   /* empty */
  3602 	{$$ = new var_declarations_list_c();}
  3646 	{$$ = new var_declarations_list_c(locloc(@$));}
  3603 | program_var_declarations_list io_var_declarations
  3647 | program_var_declarations_list io_var_declarations
  3604 	{$$ = $1; $$->add_element($2);}
  3648 	{$$ = $1; $$->add_element($2);}
  3605 | program_var_declarations_list other_var_declarations
  3649 | program_var_declarations_list other_var_declarations
  3606 	{$$ = $1; $$->add_element($2);}
  3650 	{$$ = $1; $$->add_element($2);}
  3607 | program_var_declarations_list located_var_declarations
  3651 | program_var_declarations_list located_var_declarations
  3641 /* B 1.6 Sequential Function Chart elements *
  3685 /* B 1.6 Sequential Function Chart elements *
  3642 /********************************************/
  3686 /********************************************/
  3643 
  3687 
  3644 sequential_function_chart:
  3688 sequential_function_chart:
  3645   sfc_network
  3689   sfc_network
  3646 	{$$ = new sequential_function_chart_c(); $$->add_element($1);}
  3690 	{$$ = new sequential_function_chart_c(locloc(@$)); $$->add_element($1);}
  3647 | sequential_function_chart sfc_network
  3691 | sequential_function_chart sfc_network
  3648 	{$$ = $1; $$->add_element($2);}
  3692 	{$$ = $1; $$->add_element($2);}
  3649 ;
  3693 ;
  3650 
  3694 
  3651 sfc_network:
  3695 sfc_network:
  3652   initial_step
  3696   initial_step
  3653 	{$$ = new sfc_network_c(); $$->add_element($1);}
  3697 	{$$ = new sfc_network_c(locloc(@$)); $$->add_element($1);}
  3654 | sfc_network step
  3698 | sfc_network step
  3655 	{$$ = $1; $$->add_element($2);}
  3699 	{$$ = $1; $$->add_element($2);}
  3656 | sfc_network transition
  3700 | sfc_network transition
  3657 	{$$ = $1; $$->add_element($2);}
  3701 	{$$ = $1; $$->add_element($2);}
  3658 | sfc_network action
  3702 | sfc_network action
  3660 ;
  3704 ;
  3661 
  3705 
  3662 initial_step:
  3706 initial_step:
  3663   INITIAL_STEP step_name ':' action_association_list END_STEP
  3707   INITIAL_STEP step_name ':' action_association_list END_STEP
  3664 //  INITIAL_STEP identifier ':' action_association_list END_STEP
  3708 //  INITIAL_STEP identifier ':' action_association_list END_STEP
  3665 	{$$ = new initial_step_c($2, $4);}
  3709 	{$$ = new initial_step_c($2, $4, locloc(@$));}
  3666 ;
  3710 ;
  3667 
  3711 
  3668 step:
  3712 step:
  3669   STEP step_name ':' action_association_list END_STEP
  3713   STEP step_name ':' action_association_list END_STEP
  3670 //  STEP identifier ':' action_association_list END_STEP
  3714 //  STEP identifier ':' action_association_list END_STEP
  3671 	{$$ = new step_c($2, $4);}
  3715 	{$$ = new step_c($2, $4, locloc(@$));}
  3672 ;
  3716 ;
  3673 
  3717 
  3674 /* helper symbol for:
  3718 /* helper symbol for:
  3675  *  - initial_step
  3719  *  - initial_step
  3676  *  - step
  3720  *  - step
  3677  */
  3721  */
  3678 action_association_list:
  3722 action_association_list:
  3679   /* empty */
  3723   /* empty */
  3680 	{$$ = new action_association_list_c();}
  3724 	{$$ = new action_association_list_c(locloc(@$));}
  3681 | action_association_list action_association ';'
  3725 | action_association_list action_association ';'
  3682 	{$$ = $1; $$->add_element($2);}
  3726 	{$$ = $1; $$->add_element($2);}
  3683 ;
  3727 ;
  3684 
  3728 
  3685 
  3729 
  3686 // step_name: identifier;
  3730 // step_name: identifier;
  3687 step_name: any_identifier;
  3731 step_name: any_identifier;
  3688 
  3732 
  3689 action_association:
  3733 action_association:
  3690   action_name '(' action_qualifier indicator_name_list ')'
  3734   action_name '(' {cmd_goto_sfc_qualifier_state()} action_qualifier {cmd_pop_state()} indicator_name_list ')'
  3691 	{$$ = new action_association_c($1, $3, $4, NULL);}
  3735 	{$$ = new action_association_c($1, $4, $6, locloc(@$));}
  3692 ;
  3736 ;
  3693 
  3737 
  3694 /* helper symbol for action_association */
  3738 /* helper symbol for action_association */
  3695 indicator_name_list:
  3739 indicator_name_list:
  3696   /* empty */
  3740   /* empty */
  3697 	{$$ = new indicator_name_list_c();}
  3741 	{$$ = new indicator_name_list_c(locloc(@$));}
  3698 | indicator_name_list ',' indicator_name
  3742 | indicator_name_list ',' indicator_name
  3699 	{$$ = $1; $$->add_element($3);}
  3743 	{$$ = $1; $$->add_element($3);}
  3700 ;
  3744 ;
  3701 
  3745 
  3702 // action_name: identifier;
  3746 // action_name: identifier;
  3704 
  3748 
  3705 action_qualifier:
  3749 action_qualifier:
  3706   /* empty */
  3750   /* empty */
  3707 	{$$ = NULL;}
  3751 	{$$ = NULL;}
  3708 | qualifier
  3752 | qualifier
  3709 	{$$ = new action_qualifier_c($1, NULL);}
  3753 	{$$ = new action_qualifier_c($1, NULL, locloc(@$));}
  3710 | timed_qualifier ',' action_time
  3754 | timed_qualifier ',' action_time
  3711 	{$$ = new action_qualifier_c($1, $3);}
  3755 	{$$ = new action_qualifier_c($1, $3, locloc(@$));}
  3712 ;
  3756 ;
  3713 
  3757 
  3714 qualifier:
  3758 qualifier:
  3715 N		{$$ = new qualifier_c(strdup("N"));}
  3759 N		{$$ = new qualifier_c(strdup("N"), locloc(@$));}
  3716 /* NOTE: the following two clash with the R and S IL operators.
  3760 /* NOTE: the following two clash with the R and S IL operators.
  3717  * It will have to be handled when we include parsing of SFC...
  3761  * It will have to be handled when we include parsing of SFC...
  3718  */
  3762  */
  3719 | R		{$$ = new qualifier_c(strdup("R"));}
  3763 | R		{$$ = new qualifier_c(strdup("R"), locloc(@$));}
  3720 | S		{$$ = new qualifier_c(strdup("S"));}
  3764 | S		{$$ = new qualifier_c(strdup("S"), locloc(@$));}
  3721 | P		{$$ = new qualifier_c(strdup("P"));}
  3765 | P		{$$ = new qualifier_c(strdup("P"), locloc(@$));}
  3722 ;
  3766 ;
  3723 
  3767 
  3724 timed_qualifier:
  3768 timed_qualifier:
  3725 L		{$$ = new timed_qualifier_c(strdup("L"));}
  3769 L		{$$ = new timed_qualifier_c(strdup("L"), locloc(@$));}
  3726 | D		{$$ = new timed_qualifier_c(strdup("D"));}
  3770 | D		{$$ = new timed_qualifier_c(strdup("D"), locloc(@$));}
  3727 | SD		{$$ = new timed_qualifier_c(strdup("SD"));}
  3771 | SD		{$$ = new timed_qualifier_c(strdup("SD"), locloc(@$));}
  3728 | DS		{$$ = new timed_qualifier_c(strdup("DS"));}
  3772 | DS		{$$ = new timed_qualifier_c(strdup("DS"), locloc(@$));}
  3729 | SL		{$$ = new timed_qualifier_c(strdup("SL"));}
  3773 | SL		{$$ = new timed_qualifier_c(strdup("SL"), locloc(@$));}
  3730 ;
  3774 ;
  3731 
  3775 
  3732 action_time:
  3776 action_time:
  3733   duration
  3777   duration
  3734 | variable
  3778 | variable
  3740 transition_name: any_identifier;
  3784 transition_name: any_identifier;
  3741 
  3785 
  3742 
  3786 
  3743 steps:
  3787 steps:
  3744   step_name
  3788   step_name
  3745 	{$$ = new steps_c($1, NULL);}
  3789 	{$$ = new steps_c($1, NULL, locloc(@$));}
  3746 | '(' step_name_list ')'
  3790 | '(' step_name_list ')'
  3747 	{$$ = new steps_c(NULL, $2);}
  3791 	{$$ = new steps_c(NULL, $2, locloc(@$));}
  3748 ;
  3792 ;
  3749 
  3793 
  3750 step_name_list:
  3794 step_name_list:
  3751   step_name ',' step_name
  3795   step_name ',' step_name
  3752 	{$$ = new step_name_list_c(); $$->add_element($1); $$->add_element($3);}
  3796 	{$$ = new step_name_list_c(locloc(@$)); $$->add_element($1); $$->add_element($3);}
  3753 | step_name_list ',' step_name
  3797 | step_name_list ',' step_name
  3754 	{$$ = $1; $$->add_element($3);}
  3798 	{$$ = $1; $$->add_element($3);}
  3755 ;
  3799 ;
  3756 
  3800 
  3757 
  3801 
  3776 transition_condition_st:
  3820 transition_condition_st:
  3777   ASSIGN expression ';'
  3821   ASSIGN expression ';'
  3778 	{$$ = $2}
  3822 	{$$ = $2}
  3779 ;
  3823 ;
  3780 
  3824 
       
  3825 
       
  3826 /* TODO: Can't we clean this up a bit ? */
  3781 transition:
  3827 transition:
  3782   transition_header transition_condition_il END_TRANSITION
  3828   transition_header transition_condition_il END_TRANSITION
  3783         {$$ = new transition_c($1.first, $1.second, $1.third, $1.fourth, $2, NULL);}
  3829         {$$ = new transition_c($1.first, $1.second, $1.third, $1.fourth, $2, NULL, locloc(@$));}
       
  3830         /* TODO: free the memory used up by the no longer used object $1 */
  3784 |  transition_header transition_condition_st END_TRANSITION
  3831 |  transition_header transition_condition_st END_TRANSITION
  3785         {$$ = new transition_c($1.first, $1.second, $1.third, $1.fourth, NULL, $2);}
  3832         {$$ = new transition_c($1.first, $1.second, $1.third, $1.fourth, NULL, $2, locloc(@$));}
  3786 ;
  3833 ;
  3787 
  3834 
  3788 action_header:
  3835 action_header:
  3789   ACTION action_name ':' 
  3836   ACTION action_name ':' 
  3790 //  ACTION identifier ':' 
  3837 //  ACTION identifier ':' 
  3792 ;
  3839 ;
  3793 
  3840 
  3794 
  3841 
  3795 action:
  3842 action:
  3796   action_header function_block_body END_ACTION
  3843   action_header function_block_body END_ACTION
  3797 	{$$ = new action_c($1.first, $2);}
  3844 	{$$ = new action_c($1.first, $2, locloc(@$));}
  3798 ;
  3845 ;
  3799 
  3846 
  3800 
  3847 
  3801 /********************************/
  3848 /********************************/
  3802 /* B 1.7 Configuration elements */
  3849 /* B 1.7 Configuration elements */
  3834  * have already been used to name a variable!
  3881  * have already been used to name a variable!
  3835  *
  3882  *
  3836  * If it ever becomes necessary to change this interpretation of
  3883  * If it ever becomes necessary to change this interpretation of
  3837  * the syntax, then this section of the syntax parser must be updated!
  3884  * the syntax, then this section of the syntax parser must be updated!
  3838  */
  3885  */
  3839 prev_declared_global_var_name: prev_declared_global_var_name_token {$$ = new identifier_c($1);};
  3886 prev_declared_global_var_name: prev_declared_global_var_name_token {$$ = new identifier_c($1, locloc(@$));};
  3840 prev_declared_resource_name: prev_declared_resource_name_token {$$ = new identifier_c($1);};
  3887 prev_declared_resource_name: prev_declared_resource_name_token {$$ = new identifier_c($1, locloc(@$));};
  3841 prev_declared_program_name: prev_declared_program_name_token {$$ = new identifier_c($1);};
  3888 prev_declared_program_name: prev_declared_program_name_token {$$ = new identifier_c($1, locloc(@$));};
  3842 // prev_declared_task_name: prev_declared_task_name_token {$$ = new identifier_c($1);};
  3889 // prev_declared_task_name: prev_declared_task_name_token {$$ = new identifier_c($1, locloc(@$));};
  3843 
  3890 
  3844 
  3891 
  3845 
  3892 
  3846 
  3893 
  3847 
  3894 
  3868    single_resource_declaration
  3915    single_resource_declaration
  3869    {variable_name_symtable.pop();}
  3916    {variable_name_symtable.pop();}
  3870    optional_access_declarations
  3917    optional_access_declarations
  3871    optional_instance_specific_initializations
  3918    optional_instance_specific_initializations
  3872   END_CONFIGURATION
  3919   END_CONFIGURATION
  3873 	{$$ = new configuration_declaration_c($2, $3, $4, $6, $7);
  3920 	{$$ = new configuration_declaration_c($2, $3, $4, $6, $7, locloc(@$));
  3874 	 library_element_symtable.insert($2, prev_declared_configuration_name_token);
  3921 	 library_element_symtable.insert($2, prev_declared_configuration_name_token);
  3875 	 variable_name_symtable.pop();
  3922 	 variable_name_symtable.pop();
  3876 	}
  3923 	}
  3877 | CONFIGURATION configuration_name
  3924 | CONFIGURATION configuration_name
  3878    optional_global_var_declarations
  3925    optional_global_var_declarations
  3879    resource_declaration_list
  3926    resource_declaration_list
  3880    optional_access_declarations
  3927    optional_access_declarations
  3881    optional_instance_specific_initializations
  3928    optional_instance_specific_initializations
  3882  END_CONFIGURATION
  3929  END_CONFIGURATION
  3883 	{$$ = new configuration_declaration_c($2, $3, $4, $5, $6);
  3930 	{$$ = new configuration_declaration_c($2, $3, $4, $5, $6, locloc(@$));
  3884 	 library_element_symtable.insert($2, prev_declared_configuration_name_token);
  3931 	 library_element_symtable.insert($2, prev_declared_configuration_name_token);
  3885 	 variable_name_symtable.pop();
  3932 	 variable_name_symtable.pop();
  3886 	}
  3933 	}
       
  3934 /* ERROR_CHECK_BEGIN */
  3887 | CONFIGURATION error END_CONFIGURATION
  3935 | CONFIGURATION error END_CONFIGURATION
  3888 	{$$ = NULL;
  3936 	{$$ = NULL;
  3889 	 print_err_msg(current_filename, @2.last_line, "error in configuration declaration.");
  3937 	 print_err_msg(current_filename, @2.first_line, "error in configuration declaration.");
  3890 	 /* yychar */
  3938 	 /* yychar */
  3891 	 yyerrok;
  3939 	 yyerrok;
  3892 	}
  3940 	}
       
  3941 /* ERROR_CHECK_END */
  3893 ;
  3942 ;
  3894 
  3943 
  3895 // helper symbol for
  3944 // helper symbol for
  3896 //  - configuration_declaration
  3945 //  - configuration_declaration
  3897 //  - resource_declaration
  3946 //  - resource_declaration
  3918 ;
  3967 ;
  3919 
  3968 
  3920 // helper symbol for configuration_declaration //
  3969 // helper symbol for configuration_declaration //
  3921 resource_declaration_list:
  3970 resource_declaration_list:
  3922   resource_declaration
  3971   resource_declaration
  3923 	{$$ = new resource_declaration_list_c(); $$->add_element($1);}
  3972 	{$$ = new resource_declaration_list_c(locloc(@$)); $$->add_element($1);}
  3924 | resource_declaration_list resource_declaration
  3973 | resource_declaration_list resource_declaration
  3925 	{$$ = $1; $$->add_element($2);}
  3974 	{$$ = $1; $$->add_element($2);}
  3926 ;
  3975 ;
  3927 
  3976 
  3928 
  3977 
  3929 resource_declaration:
  3978 resource_declaration:
  3930   RESOURCE {variable_name_symtable.push();} resource_name ON resource_type_name
  3979   RESOURCE {variable_name_symtable.push();} resource_name ON resource_type_name
  3931    optional_global_var_declarations
  3980    optional_global_var_declarations
  3932    single_resource_declaration
  3981    single_resource_declaration
  3933   END_RESOURCE
  3982   END_RESOURCE
  3934 	{$$ = new resource_declaration_c($3, $5, $6, $7);
  3983 	{$$ = new resource_declaration_c($3, $5, $6, $7, locloc(@$));
  3935 	 variable_name_symtable.pop();
  3984 	 variable_name_symtable.pop();
  3936 	 variable_name_symtable.insert($3, prev_declared_resource_name_token);
  3985 	 variable_name_symtable.insert($3, prev_declared_resource_name_token);
  3937 	}
  3986 	}
  3938 ;
  3987 ;
  3939 
  3988 
  3940 
  3989 
  3941 single_resource_declaration:
  3990 single_resource_declaration:
  3942  task_configuration_list program_configuration_list
  3991  task_configuration_list program_configuration_list
  3943 	{$$ = new single_resource_declaration_c($1, $2);}
  3992 	{$$ = new single_resource_declaration_c($1, $2, locloc(@$));}
  3944 ;
  3993 ;
  3945 
  3994 
  3946 
  3995 
  3947 // helper symbol for single_resource_declaration //
  3996 // helper symbol for single_resource_declaration //
  3948 task_configuration_list:
  3997 task_configuration_list:
  3949   // empty
  3998   // empty
  3950 	{$$ = new task_configuration_list_c();}
  3999 	{$$ = new task_configuration_list_c(locloc(@$));}
  3951 | task_configuration_list task_configuration ';'
  4000 | task_configuration_list task_configuration ';'
  3952 	{$$ = $1; $$->add_element($2);}
  4001 	{$$ = $1; $$->add_element($2);}
  3953 ;
  4002 ;
  3954 
  4003 
  3955 
  4004 
  3956 // helper symbol for single_resource_declaration //
  4005 // helper symbol for single_resource_declaration //
  3957 program_configuration_list:
  4006 program_configuration_list:
  3958   program_configuration ';'
  4007   program_configuration ';'
  3959 	{$$ = new program_configuration_list_c(); $$->add_element($1);}
  4008 	{$$ = new program_configuration_list_c(locloc(@$)); $$->add_element($1);}
  3960 | program_configuration_list program_configuration ';'
  4009 | program_configuration_list program_configuration ';'
  3961 	{$$ = $1; $$->add_element($2);}
  4010 	{$$ = $1; $$->add_element($2);}
  3962 ;
  4011 ;
  3963 
  4012 
  3964 
  4013 
  4008  *       In order to distinguish the two, here we use any_fb_name_list, while
  4057  *       In order to distinguish the two, here we use any_fb_name_list, while
  4009  *       in the the locations we simply use fb_name_list!
  4058  *       in the the locations we simply use fb_name_list!
  4010  */
  4059  */
  4011 any_fb_name_list:
  4060 any_fb_name_list:
  4012   // empty
  4061   // empty
  4013 	{$$ = new any_fb_name_list_c();}
  4062 	{$$ = new any_fb_name_list_c(locloc(@$));}
  4014 //| fb_name_list fb_name '.'
  4063 //| fb_name_list fb_name '.'
  4015 | any_fb_name_list any_identifier '.'
  4064 | any_fb_name_list any_identifier '.'
  4016 	{$$ = $1; $$->add_element($2);}
  4065 	{$$ = $1; $$->add_element($2);}
  4017 ;
  4066 ;
  4018 
  4067 
  4019 
  4068 
  4020 
  4069 
  4021 global_var_reference:
  4070 global_var_reference:
  4022 //  [resource_name '.'] global_var_name ['.' structure_element_name] //
  4071 //  [resource_name '.'] global_var_name ['.' structure_element_name] //
  4023                                   prev_declared_global_var_name
  4072                                   prev_declared_global_var_name
  4024 	{$$ = new global_var_reference_c(NULL, $1, NULL);}
  4073 	{$$ = new global_var_reference_c(NULL, $1, NULL, locloc(@$));}
  4025 |                                 prev_declared_global_var_name '.' structure_element_name
  4074 |                                 prev_declared_global_var_name '.' structure_element_name
  4026 	{$$ = new global_var_reference_c(NULL, $1, $3);}
  4075 	{$$ = new global_var_reference_c(NULL, $1, $3, locloc(@$));}
  4027 | prev_declared_resource_name '.' prev_declared_global_var_name
  4076 | prev_declared_resource_name '.' prev_declared_global_var_name
  4028 	{$$ = new global_var_reference_c($1, $3, NULL);}
  4077 	{$$ = new global_var_reference_c($1, $3, NULL, locloc(@$));}
  4029 | prev_declared_resource_name '.' prev_declared_global_var_name '.' structure_element_name
  4078 | prev_declared_resource_name '.' prev_declared_global_var_name '.' structure_element_name
  4030 	{$$ = new global_var_reference_c($1, $3, $5);}
  4079 	{$$ = new global_var_reference_c($1, $3, $5, locloc(@$));}
  4031 ;
  4080 ;
  4032 
  4081 
  4033 
  4082 
  4034 //access_name: identifier;
  4083 //access_name: identifier;
  4035 
  4084 
  4046  * used really refers to a program declared after the task
  4095  * used really refers to a program declared after the task
  4047  * initialization!
  4096  * initialization!
  4048  */
  4097  */
  4049 //  prev_declared_program_name '.' symbolic_variable
  4098 //  prev_declared_program_name '.' symbolic_variable
  4050   program_name '.' symbolic_variable
  4099   program_name '.' symbolic_variable
  4051 	{$$ = new program_output_reference_c($1, $3);}
  4100 	{$$ = new program_output_reference_c($1, $3, locloc(@$));}
  4052 ;
  4101 ;
  4053 
  4102 
  4054 program_name: identifier;
  4103 program_name: identifier;
  4055 
  4104 
  4056 /*
  4105 /*
  4062 ;
  4111 ;
  4063 */
  4112 */
  4064 
  4113 
  4065 task_configuration:
  4114 task_configuration:
  4066   TASK task_name task_initialization
  4115   TASK task_name task_initialization
  4067 	{$$ = new task_configuration_c($2, $3);}
  4116 	{$$ = new task_configuration_c($2, $3, locloc(@$));}
  4068 ;
  4117 ;
  4069 
  4118 
  4070 /* NOTE: The specification does nopt mention the namespace to which task names
  4119 /* NOTE: The specification does nopt mention the namespace to which task names
  4071  *       should belong to. Unlike resource and program names, for the moment we
  4120  *       should belong to. Unlike resource and program names, for the moment we
  4072  *       let the task names belong to their own private namespace, as they do not
  4121  *       let the task names belong to their own private namespace, as they do not
  4077 task_name: any_identifier;
  4126 task_name: any_identifier;
  4078 
  4127 
  4079 task_initialization:
  4128 task_initialization:
  4080 //  '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' //
  4129 //  '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' //
  4081   '(' PRIORITY ASSIGN integer ')'
  4130   '(' PRIORITY ASSIGN integer ')'
  4082 	{$$ = new task_initialization_c(NULL, NULL, $4);}
  4131 	{$$ = new task_initialization_c(NULL, NULL, $4, locloc(@$));}
  4083 | '(' SINGLE ASSIGN data_source ','   PRIORITY ASSIGN integer ')'
  4132 | '(' SINGLE ASSIGN data_source ','   PRIORITY ASSIGN integer ')'
  4084 	{$$ = new task_initialization_c($4, NULL, $8);}
  4133 	{$$ = new task_initialization_c($4, NULL, $8, locloc(@$));}
  4085 | '(' INTERVAL ASSIGN data_source ',' PRIORITY ASSIGN integer ')'
  4134 | '(' INTERVAL ASSIGN data_source ',' PRIORITY ASSIGN integer ')'
  4086 	{$$ = new task_initialization_c(NULL, $4, $8);}
  4135 	{$$ = new task_initialization_c(NULL, $4, $8, locloc(@$));}
  4087 | '(' SINGLE ASSIGN data_source ',' INTERVAL ASSIGN data_source ',' PRIORITY ASSIGN integer ')'
  4136 | '(' SINGLE ASSIGN data_source ',' INTERVAL ASSIGN data_source ',' PRIORITY ASSIGN integer ')'
  4088 	{$$ = new task_initialization_c($4, $8, $12);}
  4137 	{$$ = new task_initialization_c($4, $8, $12, locloc(@$));}
  4089 ;
  4138 ;
  4090 
  4139 
  4091 data_source:
  4140 data_source:
  4092   constant
  4141   constant
  4093 | global_var_reference
  4142 | global_var_reference
  4096 ;
  4145 ;
  4097 
  4146 
  4098 program_configuration:
  4147 program_configuration:
  4099 //  PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] //
  4148 //  PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] //
  4100   PROGRAM program_name optional_task_name ':' prev_declared_program_type_name optional_prog_conf_elements
  4149   PROGRAM program_name optional_task_name ':' prev_declared_program_type_name optional_prog_conf_elements
  4101 	{$$ = new program_configuration_c(NULL, $2, $3, $5, $6);
  4150 	{$$ = new program_configuration_c(NULL, $2, $3, $5, $6, locloc(@$));
  4102 	 variable_name_symtable.insert($2, prev_declared_program_name_token);
  4151 	 variable_name_symtable.insert($2, prev_declared_program_name_token);
  4103 	}
  4152 	}
  4104 | PROGRAM RETAIN program_name optional_task_name ':' prev_declared_program_type_name optional_prog_conf_elements
  4153 | PROGRAM RETAIN program_name optional_task_name ':' prev_declared_program_type_name optional_prog_conf_elements
  4105 	{$$ = new program_configuration_c(new retain_option_c(), $3, $4, $6, $7);
  4154 	{$$ = new program_configuration_c(new retain_option_c(locloc(@2)), $3, $4, $6, $7, locloc(@$));
  4106 	 variable_name_symtable.insert($3, prev_declared_program_name_token);
  4155 	 variable_name_symtable.insert($3, prev_declared_program_name_token);
  4107 	}
  4156 	}
  4108 | PROGRAM NON_RETAIN program_name optional_task_name ':' prev_declared_program_type_name optional_prog_conf_elements
  4157 | PROGRAM NON_RETAIN program_name optional_task_name ':' prev_declared_program_type_name optional_prog_conf_elements
  4109 	{$$ = new program_configuration_c(new non_retain_option_c(), $3, $4, $6, $7);
  4158 	{$$ = new program_configuration_c(new non_retain_option_c(locloc(@2)), $3, $4, $6, $7, locloc(@$));
  4110 	 variable_name_symtable.insert($3, prev_declared_program_name_token);
  4159 	 variable_name_symtable.insert($3, prev_declared_program_name_token);
  4111 	}
  4160 	}
  4112 ;
  4161 ;
  4113 
  4162 
  4114 // helper symbol for program_configuration //
  4163 // helper symbol for program_configuration //
  4128 ;
  4177 ;
  4129 
  4178 
  4130 
  4179 
  4131 prog_conf_elements:
  4180 prog_conf_elements:
  4132   prog_conf_element
  4181   prog_conf_element
  4133 	{$$ = new prog_conf_elements_c(); $$->add_element($1);}
  4182 	{$$ = new prog_conf_elements_c(locloc(@$)); $$->add_element($1);}
  4134 | prog_conf_elements ',' prog_conf_element
  4183 | prog_conf_elements ',' prog_conf_element
  4135 	{$$ = $1; $$->add_element($3);}
  4184 	{$$ = $1; $$->add_element($3);}
  4136 ;
  4185 ;
  4137 
  4186 
  4138 
  4187 
  4147 /* NOTE: The fb_name refers to funtion block variables
  4196 /* NOTE: The fb_name refers to funtion block variables
  4148  *       that have been declared in a scope outside the one we are
  4197  *       that have been declared in a scope outside the one we are
  4149  *       currently parsing, so we must accept them to be any_identifier!
  4198  *       currently parsing, so we must accept them to be any_identifier!
  4150  */
  4199  */
  4151   any_identifier WITH task_name
  4200   any_identifier WITH task_name
  4152 	{$$ = new fb_task_c($1, $3);}
  4201 	{$$ = new fb_task_c($1, $3, locloc(@$));}
  4153 ;
  4202 ;
  4154 
  4203 
  4155 
  4204 
  4156 /* NOTE:
  4205 /* NOTE:
  4157  *  The semantics of configuring a program are rather confusing, so here is
  4206  *  The semantics of configuring a program are rather confusing, so here is
  4183  *  instead of previosuly declared variable names, to be used in the definition of
  4232  *  instead of previosuly declared variable names, to be used in the definition of
  4184  *  prog_cnxn!
  4233  *  prog_cnxn!
  4185  */
  4234  */
  4186 prog_cnxn:
  4235 prog_cnxn:
  4187   any_symbolic_variable ASSIGN prog_data_source
  4236   any_symbolic_variable ASSIGN prog_data_source
  4188 	{$$ = new prog_cnxn_assign_c($1, $3);}
  4237 	{$$ = new prog_cnxn_assign_c($1, $3, locloc(@$));}
  4189 | any_symbolic_variable SENDTO data_sink
  4238 | any_symbolic_variable SENDTO data_sink
  4190 	{$$ = new prog_cnxn_sendto_c($1, $3);}
  4239 	{$$ = new prog_cnxn_sendto_c($1, $3, locloc(@$));}
  4191 ;
  4240 ;
  4192 
  4241 
  4193 prog_data_source:
  4242 prog_data_source:
  4194   constant
  4243   constant
  4195 | enumerated_value
  4244 | enumerated_value
  4202 | direct_variable
  4251 | direct_variable
  4203 ;
  4252 ;
  4204 
  4253 
  4205 instance_specific_initializations:
  4254 instance_specific_initializations:
  4206  VAR_CONFIG instance_specific_init_list END_VAR
  4255  VAR_CONFIG instance_specific_init_list END_VAR
  4207 	{$$ = new instance_specific_initializations_c($2);}
  4256 	{$$ = new instance_specific_initializations_c($2, locloc(@$));}
  4208 ;
  4257 ;
  4209 
  4258 
  4210 // helper symbol for instance_specific_initializations //
  4259 // helper symbol for instance_specific_initializations //
  4211 instance_specific_init_list:
  4260 instance_specific_init_list:
  4212   instance_specific_init ';'
  4261   instance_specific_init ';'
  4213 	{$$ = new instance_specific_init_list_c(); $$->add_element($1);}
  4262 	{$$ = new instance_specific_init_list_c(locloc(@$)); $$->add_element($1);}
  4214 | instance_specific_init_list instance_specific_init ';'
  4263 | instance_specific_init_list instance_specific_init ';'
  4215 	{$$ = $1; $$->add_element($2);}
  4264 	{$$ = $1; $$->add_element($2);}
  4216 ;
  4265 ;
  4217 
  4266 
  4218 
  4267 
  4228 /* NOTE: program_name has not been changed to prev_declared_program_name because the
  4277 /* NOTE: program_name has not been changed to prev_declared_program_name because the
  4229  *       programs being referenced have been declared outside the scope currently being parsed!
  4278  *       programs being referenced have been declared outside the scope currently being parsed!
  4230  *       The programs are only kept inside the scope of the resource in which they are defined.
  4279  *       The programs are only kept inside the scope of the resource in which they are defined.
  4231  */
  4280  */
  4232   prev_declared_resource_name '.' program_name '.' any_fb_name_list any_identifier ':' located_var_spec_init
  4281   prev_declared_resource_name '.' program_name '.' any_fb_name_list any_identifier ':' located_var_spec_init
  4233 	{$$ = new instance_specific_init_c($1, $3, $5, $6, NULL, $8);}
  4282 	{$$ = new instance_specific_init_c($1, $3, $5, $6, NULL, $8, locloc(@$));}
  4234 | prev_declared_resource_name '.' program_name '.' any_fb_name_list any_identifier location ':' located_var_spec_init
  4283 | prev_declared_resource_name '.' program_name '.' any_fb_name_list any_identifier location ':' located_var_spec_init
  4235 	{$$ = new instance_specific_init_c($1, $3, $5, $6, $7, $9);}
  4284 	{$$ = new instance_specific_init_c($1, $3, $5, $6, $7, $9, locloc(@$));}
  4236 | prev_declared_resource_name '.' program_name '.' any_fb_name_list any_identifier ':' fb_initialization
  4285 | prev_declared_resource_name '.' program_name '.' any_fb_name_list any_identifier ':' fb_initialization
  4237 	{$5->add_element($6); $$ = new instance_specific_init_c($1, $3, $5, NULL, NULL, $8);}
  4286 	{$5->add_element($6); $$ = new instance_specific_init_c($1, $3, $5, NULL, NULL, $8, locloc(@$));}
  4238 ;
  4287 ;
  4239 
  4288 
  4240 
  4289 
  4241 /* helper symbol for instance_specific_init */
  4290 /* helper symbol for instance_specific_init */
  4242 fb_initialization:
  4291 fb_initialization:
  4243   function_block_type_name ASSIGN structure_initialization
  4292   function_block_type_name ASSIGN structure_initialization
  4244 	{$$ = new fb_initialization_c($1, $3);}
  4293 	{$$ = new fb_initialization_c($1, $3, locloc(@$));}
  4245 ;
  4294 ;
  4246 
  4295 
  4247 /***********************************/
  4296 /***********************************/
  4248 /* B 2.1 Instructions and Operands */
  4297 /* B 2.1 Instructions and Operands */
  4249 /***********************************/
  4298 /***********************************/
  4262 ;
  4311 ;
  4263 */
  4312 */
  4264 
  4313 
  4265 instruction_list:
  4314 instruction_list:
  4266   il_instruction
  4315   il_instruction
  4267 	{$$ = new instruction_list_c(); $$->add_element($1);}
  4316 	{$$ = new instruction_list_c(locloc(@$)); $$->add_element($1);}
  4268 | pragma eol_list
  4317 | pragma eol_list
  4269 	{$$ = new instruction_list_c(); $$->add_element($1);}
  4318 	{$$ = new instruction_list_c(locloc(@$)); $$->add_element($1);}
  4270 | instruction_list il_instruction
  4319 | instruction_list il_instruction
  4271 	{$$ = $1; $$->add_element($2);}
  4320 	{$$ = $1; $$->add_element($2);}
  4272 | instruction_list pragma
  4321 | instruction_list pragma
  4273 	{$$ = $1; $$->add_element($2);}
  4322 	{$$ = $1; $$->add_element($2);}
  4274 | instruction_list error
  4323 ;
  4275 	{$$ = $1;
  4324 
  4276 	 print_err_msg(current_filename, @2.last_line, "error in IL instruction.");
  4325 
  4277 	 /* yychar */
  4326 
       
  4327 il_instruction:
       
  4328   il_incomplete_instruction eol_list
       
  4329 	{$$ = new il_instruction_c(NULL, $1, locloc(@$));}
       
  4330 | label ':' il_incomplete_instruction eol_list
       
  4331 	{$$ = new il_instruction_c($1, $3, locloc(@$));}
       
  4332 /* ERROR_CHECK_BEGIN */
       
  4333 | error eol_list
       
  4334 	{$$ = NULL;
       
  4335 	 print_err_msg(current_filename, @1.first_line, "error in IL instruction.");
  4278 	 yyerrok;
  4336 	 yyerrok;
  4279 	}
  4337 	}
  4280 ;
  4338 /* ERROR_CHECK_END */
  4281 
  4339 /* ERROR_CHECK_BEGIN */
  4282 
  4340 | label ':' error eol_list
  4283 
  4341 	{$$ = NULL;
  4284 il_instruction:
  4342 	 print_err_msg(current_filename, @1.first_line, "error in IL instruction.");
  4285   il_incomplete_instruction eol_list
  4343 	 yyerrok;
  4286 	{$$ = new il_instruction_c(NULL, $1);}
  4344 	}
  4287 | label ':' il_incomplete_instruction eol_list
  4345 /* ERROR_CHECK_END */
  4288 	{$$ = new il_instruction_c($1, $3);}
       
  4289 ;
  4346 ;
  4290 
  4347 
  4291 
  4348 
  4292 /* helper symbol for il_instruction */
  4349 /* helper symbol for il_instruction */
  4293 il_incomplete_instruction:
  4350 il_incomplete_instruction:
  4304 
  4361 
  4305 
  4362 
  4306 
  4363 
  4307 il_simple_operation:
  4364 il_simple_operation:
  4308   il_simple_operator
  4365   il_simple_operator
  4309 	{$$ = new il_simple_operation_c($1, NULL);}
  4366 	{$$ = new il_simple_operation_c($1, NULL, locloc(@$));}
  4310 | il_simple_operator_noclash il_operand
  4367 | il_simple_operator_noclash il_operand
  4311 	{$$ = new il_simple_operation_c($1, $2);}
  4368 	{$$ = new il_simple_operation_c($1, $2, locloc(@$));}
  4312 | il_simple_operator_clash_il_operand
  4369 | il_simple_operator_clash_il_operand
  4313 	{$$ = new il_simple_operation_c($1.first, $1.second);}
  4370 	{$$ = new il_simple_operation_c($1.first, $1.second, locloc(@$));}
       
  4371 	 /* TODO: free the memory used up by the no longer used $1 object! */
       
  4372 	 /*       I don't do it now because I would have to test the change, and am
       
  4373 	  *       currently frying bigger fish... (Mario)
       
  4374 	 /*   free($1); */
  4314 /* NOTE: the line
  4375 /* NOTE: the line
  4315  *         | il_simple_operator
  4376  *         | il_simple_operator
  4316  *       already contains the 'NOT' operator, as well as all the
  4377  *       already contains the 'NOT' operator, as well as all the
  4317  *       expression operators ('MOD', 'AND', etc...), all of which
  4378  *       expression operators ('MOD', 'AND', etc...), all of which
  4318  *       may also be a function name! This means that these operators/functions,
  4379  *       may also be a function name! This means that these operators/functions,
  4319  *       without any operands, could be reduced to either an operator or a
  4380  *       without any operands, could be reduced to either an operator or a
  4320  *       function call. I (Mario) have chosen to reduce it to an operator.
  4381  *       function call. I (Mario) have chosen to reduce it to an operator.
  4321  *
  4382  *
       
  4383  *       In order to do this, we must remove from the syntax that defines
       
  4384  *       function calls all the functions whose names clash with the IL operators.
       
  4385  *
  4322  *       The line
  4386  *       The line
  4323  *         | function_name
  4387  *         | function_name
  4324  *       has been replaced with the lines
  4388  *       has been replaced with the lines
  4325  *         | function_name_no_clashes
  4389  *         | function_name_no_clashes
  4326  *       in order to include all possible function names except
  4390  *       in order to include all possible function names except
  4327  *       those whose names coincide with operators !!
  4391  *       those whose names coincide with operators !!
  4328  */
  4392  */
  4329 | function_name_no_clashes
  4393 | function_name_no_clashes
  4330 	{$$ = new il_function_call_c($1, NULL);}
  4394 	{$$ = new il_function_call_c($1, NULL, locloc(@$));}
  4331 /* NOTE: the line
  4395 /* NOTE: the line
  4332  *         | il_simple_operator il_operand
  4396  *         | il_simple_operator il_operand
  4333  *       already contains the 'NOT', 'MOD', etc. operators, followed by a single il_operand,
  4397  *       already contains the 'NOT', 'MOD', etc. operators, followed by a single il_operand.
  4334  *       which may also be reduced to a function name with an operand_list of a single
  4398  *       However, this same code (MOD x) may also be reduced to a function call to the MOD
  4335  *       il_operand! This would lead us to a reduce/reduce conflict!
  4399  *       function. This means that (MOD, AND,...) could be interpret as a function name
       
  4400  *       or as an IL operator! This would lead us to a reduce/reduce conflict!
       
  4401  *
       
  4402  *       In order to do this, we must remove from the syntax that defines
       
  4403  *       function calls all the functions whose names clash with the IL operators.
  4336  *
  4404  *
  4337  *       I (Mario) have chosen to reduce it to an operand, rather than a function call.
  4405  *       I (Mario) have chosen to reduce it to an operand, rather than a function call.
  4338  *
  4406  *
  4339  *       The line
  4407  *       The line
  4340  *         | function_name il_operand_list
  4408  *         | function_name il_operand_list
  4343  *       in order to include all possible function names except
  4411  *       in order to include all possible function names except
  4344  *       for the function names which clash with expression and simple operators.
  4412  *       for the function names which clash with expression and simple operators.
  4345  *
  4413  *
  4346  *       Note that:
  4414  *       Note that:
  4347  *       this alternative syntax does not cover the possibility of
  4415  *       this alternative syntax does not cover the possibility of
  4348  *       the function 'NOT', 'MOD', etc... being called with more than one il_operand!
  4416  *       the function 'NOT', 'MOD', etc... being called with more than one il_operand,
       
  4417  *       in which case it is always a function call, and not an IL instruction.
  4349  *       We therefore need to include an extra rule where the
  4418  *       We therefore need to include an extra rule where the
  4350  *       function_name_expression_clashes and function_name_simpleop_clashes
  4419  *       function_name_expression_clashes and function_name_simpleop_clashes
  4351  *       are followed by a il_operand_list with __two__ or more il_operands!!
  4420  *       are followed by a il_operand_list with __two__ or more il_operands!!
  4352  */
  4421  */
  4353 | function_name_no_clashes il_operand_list
  4422 | function_name_no_clashes il_operand_list
  4354 	{$$ = new il_function_call_c($1, $2);}
  4423 	{$$ = new il_function_call_c($1, $2, locloc(@$));}
  4355 | il_simple_operator_clash_il_operand ',' il_operand_list
  4424 | il_simple_operator_clash_il_operand ',' il_operand_list
  4356 	{list_c *list = new il_operand_list_c();
  4425 	{list_c *list = new il_operand_list_c(locloc(@$));
  4357 	 list->add_element($1.second);
  4426 	 list->add_element($1.second);
  4358 	 FOR_EACH_ELEMENT(elem, $3, {list->add_element(elem);})
  4427 	 FOR_EACH_ELEMENT(elem, $3, {list->add_element(elem);})
  4359 	 $$ = new il_function_call_c(il_operator_c_2_identifier_c($1.first), list);
  4428 	 $$ = new il_function_call_c(il_operator_c_2_identifier_c($1.first), list, locloc(@$));
       
  4429 	 /* TODO: free the memory used up by the no longer used $3 object! */
       
  4430 	 /*       I don't do it now because I would have to test the change, and am
       
  4431 	  *       currently frying bigger fish... (Mario)
       
  4432 	  */
       
  4433 	 /*   free($3); */
  4360 	}
  4434 	}
  4361 ;
  4435 ;
  4362 
  4436 
  4363 
  4437 
  4364 
  4438 
  4369 
  4443 
  4370 
  4444 
  4371 
  4445 
  4372 il_expression:
  4446 il_expression:
  4373   il_expr_operator_noclash '(' eol_list ')'
  4447   il_expr_operator_noclash '(' eol_list ')'
  4374 	{$$ = new il_expression_c($1, NULL, NULL);}
  4448 	{$$ = new il_expression_c($1, NULL, NULL, locloc(@$));}
  4375 | il_expr_operator_noclash '(' il_operand eol_list ')'
  4449 | il_expr_operator_noclash '(' il_operand eol_list ')'
  4376 	{$$ = new il_expression_c($1, $3, NULL);}
  4450 	{$$ = new il_expression_c($1, $3, NULL, locloc(@$));}
  4377 | il_expr_operator_noclash '(' eol_list simple_instr_list ')'
  4451 | il_expr_operator_noclash '(' eol_list simple_instr_list ')'
  4378 	{$$ = new il_expression_c($1, NULL, $4);}
  4452 	{$$ = new il_expression_c($1, NULL, $4, locloc(@$));}
  4379 | il_expr_operator_noclash '(' il_operand eol_list simple_instr_list ')'
  4453 | il_expr_operator_noclash '(' il_operand eol_list simple_instr_list ')'
  4380 	{$$ = new il_expression_c($1, $3, $5);}
  4454 	{$$ = new il_expression_c($1, $3, $5, locloc(@$));}
  4381 /*
  4455 /*
  4382 */
  4456 */
  4383 | il_expr_operator_clash '(' eol_list ')'
  4457 | il_expr_operator_clash '(' eol_list ')'
  4384 	{$$ = new il_expression_c($1, NULL, NULL);}
  4458 	{$$ = new il_expression_c($1, NULL, NULL, locloc(@$));}
  4385 | il_expr_operator_clash '(' il_operand eol_list ')'
  4459 | il_expr_operator_clash '(' il_operand eol_list ')'
  4386 	{$$ = new il_expression_c($1, $3, NULL);}
  4460 	{$$ = new il_expression_c($1, $3, NULL, locloc(@$));}
  4387 | il_expr_operator_clash '(' il_operand eol_list simple_instr_list ')'
  4461 | il_expr_operator_clash '(' il_operand eol_list simple_instr_list ')'
  4388 	{$$ = new il_expression_c($1, $3, $5);}
  4462 	{$$ = new il_expression_c($1, $3, $5, locloc(@$));}
  4389 /*
  4463 /*
  4390 */
  4464 */
  4391 | il_expr_operator_clash_eol_list simple_instr_list ')'
  4465 | il_expr_operator_clash_eol_list simple_instr_list ')'
  4392 	{$$ = new il_expression_c($1, NULL, $2);}
  4466 	{$$ = new il_expression_c($1, NULL, $2, locloc(@$));}
  4393 ;
  4467 ;
  4394 
  4468 
  4395 
  4469 
  4396 il_jump_operation:
  4470 il_jump_operation:
  4397   il_jump_operator label
  4471   il_jump_operator label
  4398 	{$$ = new il_jump_operation_c($1, $2);}
  4472 	{$$ = new il_jump_operation_c($1, $2, locloc(@$));}
  4399 ;
  4473 ;
  4400 
  4474 
  4401 
  4475 
  4402 il_fb_call:
  4476 il_fb_call:
  4403   il_call_operator prev_declared_fb_name
  4477   il_call_operator prev_declared_fb_name
  4404 	{$$ = new il_fb_call_c($1, $2, NULL, NULL);}
  4478 	{$$ = new il_fb_call_c($1, $2, NULL, NULL, locloc(@$));}
  4405 | il_call_operator prev_declared_fb_name '(' ')'
  4479 | il_call_operator prev_declared_fb_name '(' ')'
  4406 	{$$ = new il_fb_call_c($1, $2, NULL, NULL);}
  4480 	{$$ = new il_fb_call_c($1, $2, NULL, NULL, locloc(@$));}
  4407 | il_call_operator prev_declared_fb_name '(' eol_list ')'
  4481 | il_call_operator prev_declared_fb_name '(' eol_list ')'
  4408 	{$$ = new il_fb_call_c($1, $2, NULL, NULL);}
  4482 	{$$ = new il_fb_call_c($1, $2, NULL, NULL, locloc(@$));}
  4409 | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
  4483 | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
  4410 	{$$ = new il_fb_call_c($1, $2, $4, NULL);}
  4484 	{$$ = new il_fb_call_c($1, $2, $4, NULL, locloc(@$));}
  4411 | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
  4485 | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
  4412 	{$$ = new il_fb_call_c($1, $2, NULL, $5);}
  4486 	{$$ = new il_fb_call_c($1, $2, NULL, $5, locloc(@$));}
  4413 ;
  4487 ;
  4414 
  4488 
  4415 
  4489 
  4416 /* NOTE: Please read note above the definition of function_name_without_clashes */
  4490 /* NOTE: Please read note above the definition of function_name_without_clashes */
  4417 il_formal_funct_call:
  4491 il_formal_funct_call:
  4427  *
  4501  *
  4428  *       In summary: 'MOD' '(' eol_list ')', and all other functions whose
  4502  *       In summary: 'MOD' '(' eol_list ')', and all other functions whose
  4429  *       names clash with expressions may be interpreted by the syntax by
  4503  *       names clash with expressions may be interpreted by the syntax by
  4430  *       two different routes. I (Mario) chose to interpret them
  4504  *       two different routes. I (Mario) chose to interpret them
  4431  *       as operators, rather than as function calls!
  4505  *       as operators, rather than as function calls!
       
  4506  *       (AND MOD OR XOR ADD DIV EQ GT GE LT LE MUL NE SUB)
  4432  */
  4507  */
  4433   function_name_no_clashes '(' eol_list ')'
  4508   function_name_no_clashes '(' eol_list ')'
  4434 	{$$ = new il_formal_funct_call_c($1, NULL);}
  4509 	{$$ = new il_formal_funct_call_c($1, NULL, locloc(@$));}
  4435 | function_name_simpleop_clashes '(' eol_list ')'
  4510 | function_name_simpleop_clashes '(' eol_list ')'
  4436 	{$$ = new il_formal_funct_call_c($1, NULL);}
  4511 	{$$ = new il_formal_funct_call_c($1, NULL, locloc(@$));}
  4437 /* | function_name '(' eol_list il_param_list ')' */
  4512 /* | function_name '(' eol_list il_param_list ')' */
       
  4513 /* For the above syntax, we no longer have two ways of interpreting the
       
  4514  * same syntax. The above is always a function call!
       
  4515  * However, some of the functions that we may be calling
       
  4516  * may have the same name as an IL operator. This means that
       
  4517  * flex will be parsing them and handing them over to bison as
       
  4518  * IL operator tokens, and not as function name tokens.
       
  4519  * (when parsing ST, flex no longer recognizes IL operators,
       
  4520  * so will always return the correct function name, unless that
       
  4521  * name also coincides with an operator used in ST -> XOR, OR, MOD, AND, NOT)
       
  4522  *
       
  4523  * We must therefore interpret the IL operators as function names!
       
  4524  */
  4438 | function_name_no_clashes '(' eol_list il_param_list ')'
  4525 | function_name_no_clashes '(' eol_list il_param_list ')'
  4439 	{$$ = new il_formal_funct_call_c($1, $4);}
  4526 	{$$ = new il_formal_funct_call_c($1, $4, locloc(@$));}
  4440 | function_name_simpleop_clashes '(' eol_list il_param_list ')'
  4527 | function_name_simpleop_clashes '(' eol_list il_param_list ')'
  4441 	{$$ = new il_formal_funct_call_c($1, $4);}
  4528 	{$$ = new il_formal_funct_call_c($1, $4, locloc(@$));}
  4442 /* the function_name_expression_clashes had to be first reduced to
  4529 /* The following line should read:
       
  4530  *
       
  4531  * | function_name_expression_clashes '(' eol_list il_param_list ')'
       
  4532  *
       
  4533  * but the function_name_expression_clashes had to be first reduced to
  4443  * an intermediary symbol in order to remove a reduce/reduce conflict.
  4534  * an intermediary symbol in order to remove a reduce/reduce conflict.
  4444  * In essence, the syntax requires more than one look ahead token
  4535  * In essence, the syntax requires more than one look ahead token
  4445  * in order to be parsed. We resolve this by reducing a collection of
  4536  * in order to be parsed. We resolve this by reducing a collection of
  4446  * symbols into a temporary symbol (il_expr_operator_clash_eol_list), that
  4537  * symbols into a temporary symbol (il_expr_operator_clash_eol_list), that
  4447  * will later be replaced by the correct symbol. The correct symbol will
  4538  * will later be replaced by the correct symbol. The correct symbol will
  4455  * and create the correct symbol for our case.
  4546  * and create the correct symbol for our case.
  4456  * This is a lot of work, so I put it in a function
  4547  * This is a lot of work, so I put it in a function
  4457  * at the end of this file... il_operator_c_2_identifier_c()
  4548  * at the end of this file... il_operator_c_2_identifier_c()
  4458  */
  4549  */
  4459 | il_expr_operator_clash_eol_list il_param_list ')'
  4550 | il_expr_operator_clash_eol_list il_param_list ')'
  4460 	{$$ = new il_formal_funct_call_c(il_operator_c_2_identifier_c($1), $2);}
  4551 	{$$ = new il_formal_funct_call_c(il_operator_c_2_identifier_c($1), $2, locloc(@$));}
  4461 ;
  4552 ;
  4462 
  4553 
  4463 
  4554 
  4464 il_expr_operator_clash_eol_list:
  4555 il_expr_operator_clash_eol_list:
  4465   il_expr_operator_clash '(' eol_list
  4556   il_expr_operator_clash '(' eol_list
  4478 ;
  4569 ;
  4479 
  4570 
  4480 
  4571 
  4481 il_operand_list:
  4572 il_operand_list:
  4482   il_operand
  4573   il_operand
  4483 	{$$ = new il_operand_list_c(); $$->add_element($1);}
  4574 	{$$ = new il_operand_list_c(locloc(@$)); $$->add_element($1);}
  4484 | il_operand_list ',' il_operand
  4575 | il_operand_list ',' il_operand
  4485 	{$$ = $1; $$->add_element($3);}
  4576 	{$$ = $1; $$->add_element($3);}
  4486 ;
  4577 ;
  4487 
  4578 
  4488 
  4579 
  4489 simple_instr_list:
  4580 simple_instr_list:
  4490   il_simple_instruction
  4581   il_simple_instruction
  4491 	{$$ = new simple_instr_list_c(); $$->add_element($1);}
  4582 	{$$ = new simple_instr_list_c(locloc(@$)); $$->add_element($1);}
  4492 | simple_instr_list il_simple_instruction
  4583 | simple_instr_list il_simple_instruction
  4493 	{$$ = $1; $$->add_element($2);}
  4584 	{$$ = $1; $$->add_element($2);}
  4494 ;
  4585 ;
  4495 
  4586 
  4496 
  4587 
  4517  */
  4608  */
  4518 il_param_list:
  4609 il_param_list:
  4519   il_param_instruction_list il_param_last_instruction
  4610   il_param_instruction_list il_param_last_instruction
  4520 	{$$ = $1; $$->add_element($2);}
  4611 	{$$ = $1; $$->add_element($2);}
  4521 | il_param_last_instruction
  4612 | il_param_last_instruction
  4522 	{$$ = new il_param_list_c(); $$->add_element($1);}
  4613 	{$$ = new il_param_list_c(locloc(@$)); $$->add_element($1);}
  4523 ;
  4614 ;
  4524 
  4615 
  4525 
  4616 
  4526 /* Helper symbol for il_param_list */
  4617 /* Helper symbol for il_param_list */
  4527 il_param_instruction_list:
  4618 il_param_instruction_list:
  4528   il_param_instruction
  4619   il_param_instruction
  4529 	{$$ = new il_param_list_c(); $$->add_element($1);}
  4620 	{$$ = new il_param_list_c(locloc(@$)); $$->add_element($1);}
  4530 | il_param_instruction_list il_param_instruction
  4621 | il_param_instruction_list il_param_instruction
  4531 	{$$ = $1; $$->add_element($2);}
  4622 	{$$ = $1; $$->add_element($2);}
  4532 ;
  4623 ;
  4533 
  4624 
  4534 
  4625 
  4544 ;
  4635 ;
  4545 
  4636 
  4546 
  4637 
  4547 il_param_assignment:
  4638 il_param_assignment:
  4548   il_assign_operator il_operand
  4639   il_assign_operator il_operand
  4549 	{$$ = new il_param_assignment_c($1, $2, NULL);}
  4640 	{$$ = new il_param_assignment_c($1, $2, NULL, locloc(@$));}
  4550 | il_assign_operator '(' eol_list simple_instr_list ')'
  4641 | il_assign_operator '(' eol_list simple_instr_list ')'
  4551 	{$$ = new il_param_assignment_c($1, NULL, $4);}
  4642 	{$$ = new il_param_assignment_c($1, NULL, $4, locloc(@$));}
  4552 ;
  4643 ;
  4553 
  4644 
  4554 
  4645 
  4555 il_param_out_assignment:
  4646 il_param_out_assignment:
  4556   il_assign_out_operator variable
  4647   il_assign_out_operator variable
  4557 	{$$ = new il_param_out_assignment_c($1, $2);}
  4648 	{$$ = new il_param_out_assignment_c($1, $2, locloc(@$));}
  4558 ;
  4649 ;
  4559 
  4650 
  4560 
  4651 
  4561 
  4652 
  4562 /*******************/
  4653 /*******************/
  4563 /* B 2.2 Operators */
  4654 /* B 2.2 Operators */
  4564 /*******************/
  4655 /*******************/
  4565 sendto_identifier: sendto_identifier_token {$$ = new identifier_c($1);};
  4656 sendto_identifier: sendto_identifier_token {$$ = new identifier_c($1, locloc(@$));};
  4566 
  4657 
  4567 
  4658 
  4568 /* NOTE:
  4659 /* NOTE:
  4569  *  The spec includes the operator 'EQ '
  4660  *  The spec includes the operator 'EQ '
  4570  * Note that EQ is followed by a space.
  4661  * Note that EQ is followed by a space.
  4571  * I am considering this a typo, and defining the operator
  4662  * I am considering this a typo, and defining the operator
  4572  * as 'EQ'
  4663  * as 'EQ'
  4573  * (Mario)
  4664  * (Mario)
  4574  */
  4665  */
  4575 LD_operator: 		LD 	{$$ = new LD_operator_c();};
  4666 LD_operator: 		LD 	{$$ = new LD_operator_c(locloc(@$));};
  4576 LDN_operator: 		LDN 	{$$ = new LDN_operator_c();};
  4667 LDN_operator: 		LDN 	{$$ = new LDN_operator_c(locloc(@$));};
  4577 ST_operator: 		ST 	{$$ = new ST_operator_c();};
  4668 ST_operator: 		ST 	{$$ = new ST_operator_c(locloc(@$));};
  4578 STN_operator: 		STN 	{$$ = new STN_operator_c();};
  4669 STN_operator: 		STN 	{$$ = new STN_operator_c(locloc(@$));};
  4579 NOT_operator: 		NOT 	{$$ = new NOT_operator_c();};
  4670 NOT_operator: 		NOT 	{$$ = new NOT_operator_c(locloc(@$));};
  4580 S_operator: 		S 	{$$ = new S_operator_c();};
  4671 S_operator: 		S 	{$$ = new S_operator_c(locloc(@$));};
  4581 R_operator: 		R 	{$$ = new R_operator_c();};
  4672 R_operator: 		R 	{$$ = new R_operator_c(locloc(@$));};
  4582 S1_operator: 		S1 	{$$ = new S1_operator_c();};
  4673 S1_operator: 		S1 	{$$ = new S1_operator_c(locloc(@$));};
  4583 R1_operator: 		R1 	{$$ = new R1_operator_c();};
  4674 R1_operator: 		R1 	{$$ = new R1_operator_c(locloc(@$));};
  4584 CLK_operator: 		CLK 	{$$ = new CLK_operator_c();};
  4675 CLK_operator: 		CLK 	{$$ = new CLK_operator_c(locloc(@$));};
  4585 CU_operator: 		CU 	{$$ = new CU_operator_c();};
  4676 CU_operator: 		CU 	{$$ = new CU_operator_c(locloc(@$));};
  4586 CD_operator: 		CD 	{$$ = new CD_operator_c();};
  4677 CD_operator: 		CD 	{$$ = new CD_operator_c(locloc(@$));};
  4587 PV_operator: 		PV 	{$$ = new PV_operator_c();};
  4678 PV_operator: 		PV 	{$$ = new PV_operator_c(locloc(@$));};
  4588 IN_operator: 		IN 	{$$ = new IN_operator_c();};
  4679 IN_operator: 		IN 	{$$ = new IN_operator_c(locloc(@$));};
  4589 PT_operator: 		PT 	{$$ = new PT_operator_c();};
  4680 PT_operator: 		PT 	{$$ = new PT_operator_c(locloc(@$));};
  4590 AND_operator: 		AND 	{$$ = new AND_operator_c();};
  4681 AND_operator: 		AND 	{$$ = new AND_operator_c(locloc(@$));};
  4591 AND2_operator: 		AND2 	{$$ = new AND_operator_c();}; /* '&' in the source code! */
  4682 AND2_operator: 		AND2 	{$$ = new AND_operator_c(locloc(@$));}; /* '&' in the source code! */
  4592 OR_operator: 		OR 	{$$ = new OR_operator_c();};
  4683 OR_operator: 		OR 	{$$ = new OR_operator_c(locloc(@$));};
  4593 XOR_operator: 		XOR 	{$$ = new XOR_operator_c();};
  4684 XOR_operator: 		XOR 	{$$ = new XOR_operator_c(locloc(@$));};
  4594 ANDN_operator: 		ANDN 	{$$ = new ANDN_operator_c();};
  4685 ANDN_operator: 		ANDN 	{$$ = new ANDN_operator_c(locloc(@$));};
  4595 ANDN2_operator:		ANDN2 	{$$ = new ANDN_operator_c();}; /* '&N' in the source code! */
  4686 ANDN2_operator:		ANDN2 	{$$ = new ANDN_operator_c(locloc(@$));}; /* '&N' in the source code! */
  4596 ORN_operator: 		ORN 	{$$ = new ORN_operator_c();};
  4687 ORN_operator: 		ORN 	{$$ = new ORN_operator_c(locloc(@$));};
  4597 XORN_operator: 		XORN 	{$$ = new XORN_operator_c();};
  4688 XORN_operator: 		XORN 	{$$ = new XORN_operator_c(locloc(@$));};
  4598 ADD_operator: 		ADD 	{$$ = new ADD_operator_c();};
  4689 ADD_operator: 		ADD 	{$$ = new ADD_operator_c(locloc(@$));};
  4599 SUB_operator: 		SUB 	{$$ = new SUB_operator_c();};
  4690 SUB_operator: 		SUB 	{$$ = new SUB_operator_c(locloc(@$));};
  4600 MUL_operator: 		MUL 	{$$ = new MUL_operator_c();};
  4691 MUL_operator: 		MUL 	{$$ = new MUL_operator_c(locloc(@$));};
  4601 DIV_operator: 		DIV 	{$$ = new DIV_operator_c();};
  4692 DIV_operator: 		DIV 	{$$ = new DIV_operator_c(locloc(@$));};
  4602 MOD_operator: 		MOD 	{$$ = new MOD_operator_c();};
  4693 MOD_operator: 		MOD 	{$$ = new MOD_operator_c(locloc(@$));};
  4603 GT_operator: 		GT 	{$$ = new GT_operator_c();};
  4694 GT_operator: 		GT 	{$$ = new GT_operator_c(locloc(@$));};
  4604 GE_operator: 		GE 	{$$ = new GE_operator_c();};
  4695 GE_operator: 		GE 	{$$ = new GE_operator_c(locloc(@$));};
  4605 EQ_operator: 		EQ 	{$$ = new EQ_operator_c();};
  4696 EQ_operator: 		EQ 	{$$ = new EQ_operator_c(locloc(@$));};
  4606 LT_operator: 		LT 	{$$ = new LT_operator_c();};
  4697 LT_operator: 		LT 	{$$ = new LT_operator_c(locloc(@$));};
  4607 LE_operator: 		LE 	{$$ = new LE_operator_c();};
  4698 LE_operator: 		LE 	{$$ = new LE_operator_c(locloc(@$));};
  4608 NE_operator: 		NE 	{$$ = new NE_operator_c();};
  4699 NE_operator: 		NE 	{$$ = new NE_operator_c(locloc(@$));};
  4609 CAL_operator: 		CAL 	{$$ = new CAL_operator_c();};
  4700 CAL_operator: 		CAL 	{$$ = new CAL_operator_c(locloc(@$));};
  4610 CALC_operator: 		CALC 	{$$ = new CALC_operator_c();};
  4701 CALC_operator: 		CALC 	{$$ = new CALC_operator_c(locloc(@$));};
  4611 CALCN_operator: 	CALCN 	{$$ = new CALCN_operator_c();};
  4702 CALCN_operator: 	CALCN 	{$$ = new CALCN_operator_c(locloc(@$));};
  4612 RET_operator: 		RET 	{$$ = new RET_operator_c();};
  4703 RET_operator: 		RET 	{$$ = new RET_operator_c(locloc(@$));};
  4613 RETC_operator: 		RETC 	{$$ = new RETC_operator_c();};
  4704 RETC_operator: 		RETC 	{$$ = new RETC_operator_c(locloc(@$));};
  4614 RETCN_operator: 	RETCN 	{$$ = new RETCN_operator_c();};
  4705 RETCN_operator: 	RETCN 	{$$ = new RETCN_operator_c(locloc(@$));};
  4615 JMP_operator: 		JMP 	{$$ = new JMP_operator_c();};
  4706 JMP_operator: 		JMP 	{$$ = new JMP_operator_c(locloc(@$));};
  4616 JMPC_operator: 		JMPC 	{$$ = new JMPC_operator_c();};
  4707 JMPC_operator: 		JMPC 	{$$ = new JMPC_operator_c(locloc(@$));};
  4617 JMPCN_operator: 	JMPCN 	{$$ = new JMPCN_operator_c();};
  4708 JMPCN_operator: 	JMPCN 	{$$ = new JMPCN_operator_c(locloc(@$));};
  4618 
       
  4619 /*
       
  4620  MAY CONFLICT WITH STANDARD FUNCTION NAMES!!!
       
  4621 
       
  4622 NOT_operator: NOT {new NOT_operator_c();};
       
  4623 
       
  4624 AND_operator: AND {new AND_operator_c();};
       
  4625 OR_operator: OR {new OR_operator_c();};
       
  4626 XOR_operator: XOR {new XOR_operator_c();};
       
  4627 
       
  4628 ADD_operator: ADD {new ADD_operator_c();};
       
  4629 SUB_operator: SUB {new SUB_operator_c();};
       
  4630 MUL_operator: MUL {new MUL_operator_c();};
       
  4631 DIV_operator: DIV {new DIV_operator_c();};
       
  4632 MOD_operator: MOD {new MOD_operator_c();};
       
  4633 
       
  4634 GT_operator: GT {new GT_operator_c();};
       
  4635 GE_operator: GE {new GE_operator_c();};
       
  4636 EQ_operator: EQ {new EQ_operator_c();};
       
  4637 LT_operator: LT {new LT_operator_c();};
       
  4638 LE_operator: LE {new LE_operator_c();};
       
  4639 NE_operator: NE {new NE_operator_c();};
       
  4640 */
       
  4641 
  4709 
  4642 
  4710 
  4643 il_simple_operator:
  4711 il_simple_operator:
  4644   il_simple_operator_clash
  4712   il_simple_operator_clash
  4645 | il_simple_operator_noclash
  4713 | il_simple_operator_noclash
  4723 
  4791 
  4724 il_assign_out_operator:
  4792 il_assign_out_operator:
  4725 /*  variable_name SENDTO */
  4793 /*  variable_name SENDTO */
  4726 /*  any_identifier SENDTO */
  4794 /*  any_identifier SENDTO */
  4727   sendto_identifier SENDTO
  4795   sendto_identifier SENDTO
  4728 	{$$ = new il_assign_out_operator_c(NULL, $1);}
  4796 	{$$ = new il_assign_out_operator_c(NULL, $1, locloc(@$));}
  4729 /*| NOT variable_name SENDTO */
  4797 /*| NOT variable_name SENDTO */
  4730 | NOT sendto_identifier SENDTO
  4798 | NOT sendto_identifier SENDTO
  4731 	{$$ = new il_assign_out_operator_c(new not_paramassign_c(), $2);}
  4799 	{$$ = new il_assign_out_operator_c(new not_paramassign_c(locloc(@1)), $2, locloc(@$));}
  4732 ;
  4800 ;
  4733 
  4801 
  4734 
  4802 
  4735 il_call_operator:
  4803 il_call_operator:
  4736   CAL_operator
  4804   CAL_operator
  4757 /* B 3.1 - Expressions */
  4825 /* B 3.1 - Expressions */
  4758 /***********************/
  4826 /***********************/
  4759 expression:
  4827 expression:
  4760   xor_expression
  4828   xor_expression
  4761 | expression OR xor_expression
  4829 | expression OR xor_expression
  4762 	{$$ = new or_expression_c($1, $3);}
  4830 	{$$ = new or_expression_c($1, $3, locloc(@$));}
  4763 ;
  4831 ;
  4764 
  4832 
  4765 xor_expression:
  4833 xor_expression:
  4766   and_expression
  4834   and_expression
  4767 | xor_expression XOR and_expression
  4835 | xor_expression XOR and_expression
  4768 	{$$ = new xor_expression_c($1, $3);}
  4836 	{$$ = new xor_expression_c($1, $3, locloc(@$));}
  4769 ;
  4837 ;
  4770 
  4838 
  4771 and_expression:
  4839 and_expression:
  4772   comparison
  4840   comparison
  4773 | and_expression '&' comparison
  4841 | and_expression '&' comparison
  4774 	{$$ = new and_expression_c($1, $3);}
  4842 	{$$ = new and_expression_c($1, $3, locloc(@$));}
  4775 | and_expression AND comparison
  4843 | and_expression AND comparison
  4776 	{$$ = new and_expression_c($1, $3);}
  4844 	{$$ = new and_expression_c($1, $3, locloc(@$));}
  4777 /* NOTE: The lexical parser never returns the token '&'.
  4845 /* NOTE: The lexical parser never returns the token '&'.
  4778  *       The '&' string is interpreted by the lexcial parser as the token
  4846  *       The '&' string is interpreted by the lexcial parser as the token
  4779  *       AND2!
  4847  *       AND2!
  4780  *       This means that the first rule with '&' is actually not required,
  4848  *       This means that the first rule with '&' is actually not required,
  4781  *       but we leave it in nevertheless just in case we later decide
  4849  *       but we leave it in nevertheless just in case we later decide
  4782  *       to remove theh AND2 token...
  4850  *       to remove theh AND2 token...
  4783  */
  4851  */
  4784 | and_expression AND2 comparison
  4852 | and_expression AND2 comparison
  4785 	{$$ = new and_expression_c($1, $3);}
  4853 	{$$ = new and_expression_c($1, $3, locloc(@$));}
  4786 ;
  4854 ;
  4787 
  4855 
  4788 comparison:
  4856 comparison:
  4789   equ_expression
  4857   equ_expression
  4790 | comparison '=' equ_expression
  4858 | comparison '=' equ_expression
  4791 	{$$ = new equ_expression_c($1, $3);}
  4859 	{$$ = new equ_expression_c($1, $3, locloc(@$));}
  4792 | comparison OPER_NE equ_expression
  4860 | comparison OPER_NE equ_expression
  4793 	{$$ = new notequ_expression_c($1, $3);}
  4861 	{$$ = new notequ_expression_c($1, $3, locloc(@$));}
  4794 ;
  4862 ;
  4795 
  4863 
  4796 equ_expression:
  4864 equ_expression:
  4797   add_expression
  4865   add_expression
  4798 | equ_expression '<' add_expression
  4866 | equ_expression '<' add_expression
  4799 	{$$ = new lt_expression_c($1, $3);}
  4867 	{$$ = new lt_expression_c($1, $3, locloc(@$));}
  4800 | equ_expression '>' add_expression
  4868 | equ_expression '>' add_expression
  4801 	{$$ = new gt_expression_c($1, $3);}
  4869 	{$$ = new gt_expression_c($1, $3, locloc(@$));}
  4802 | equ_expression OPER_LE add_expression
  4870 | equ_expression OPER_LE add_expression
  4803 	{$$ = new le_expression_c($1, $3);}
  4871 	{$$ = new le_expression_c($1, $3, locloc(@$));}
  4804 | equ_expression OPER_GE add_expression
  4872 | equ_expression OPER_GE add_expression
  4805 	{$$ = new ge_expression_c($1, $3);}
  4873 	{$$ = new ge_expression_c($1, $3, locloc(@$));}
  4806 ;
  4874 ;
  4807 
  4875 
  4808 /* Not required...
  4876 /* Not required...
  4809 comparison_operator: '<' | '>' | '>=' '<='
  4877 comparison_operator: '<' | '>' | '>=' '<='
  4810 */
  4878 */
  4811 
  4879 
  4812 add_expression:
  4880 add_expression:
  4813   term
  4881   term
  4814 | add_expression '+' term
  4882 | add_expression '+' term
  4815 	{$$ = new add_expression_c($1, $3);}
  4883 	{$$ = new add_expression_c($1, $3, locloc(@$));}
  4816 | add_expression '-' term
  4884 | add_expression '-' term
  4817 	{$$ = new sub_expression_c($1, $3);}
  4885 	{$$ = new sub_expression_c($1, $3, locloc(@$));}
  4818 ;
  4886 ;
  4819 
  4887 
  4820 /* Not required...
  4888 /* Not required...
  4821 add_operator: '+' | '-'
  4889 add_operator: '+' | '-'
  4822 */
  4890 */
  4823 
  4891 
  4824 term:
  4892 term:
  4825   power_expression
  4893   power_expression
  4826 | term '*' power_expression
  4894 | term '*' power_expression
  4827 	{$$ = new mul_expression_c($1, $3);}
  4895 	{$$ = new mul_expression_c($1, $3, locloc(@$));}
  4828 | term '/' power_expression
  4896 | term '/' power_expression
  4829 	{$$ = new div_expression_c($1, $3);}
  4897 	{$$ = new div_expression_c($1, $3, locloc(@$));}
  4830 | term MOD power_expression
  4898 | term MOD power_expression
  4831 	{$$ = new mod_expression_c($1, $3);}
  4899 	{$$ = new mod_expression_c($1, $3, locloc(@$));}
  4832 ;
  4900 ;
  4833 
  4901 
  4834 /* Not required...
  4902 /* Not required...
  4835 multiply_operator: '*' | '/' | 'MOD'
  4903 multiply_operator: '*' | '/' | 'MOD'
  4836 */
  4904 */
  4837 
  4905 
  4838 power_expression:
  4906 power_expression:
  4839   unary_expression
  4907   unary_expression
  4840 | power_expression OPER_EXP unary_expression
  4908 | power_expression OPER_EXP unary_expression
  4841 	{$$ = new power_expression_c($1, $3);}
  4909 	{$$ = new power_expression_c($1, $3, locloc(@$));}
  4842 ;
  4910 ;
  4843 
  4911 
  4844 
  4912 
  4845 unary_expression:
  4913 unary_expression:
  4846   primary_expression
  4914   primary_expression
  4847 | '-' primary_expression
  4915 | '-' primary_expression
  4848 	{$$ = new neg_expression_c($2);}
  4916 	{$$ = new neg_expression_c($2, locloc(@$));}
  4849 | NOT primary_expression
  4917 | NOT primary_expression
  4850 	{$$ = new not_expression_c($2);}
  4918 	{$$ = new not_expression_c($2, locloc(@$));}
  4851 ;
  4919 ;
  4852 
  4920 
  4853 /* Not required...
  4921 /* Not required...
  4854 unary_operator: '-' | 'NOT'
  4922 unary_operator: '-' | 'NOT'
  4855 */
  4923 */
  4910  *       letting names clash!
  4978  *       letting names clash!
  4911  */
  4979  */
  4912 function_invocation:
  4980 function_invocation:
  4913 /*  function_name '(' param_assignment_list ')' */
  4981 /*  function_name '(' param_assignment_list ')' */
  4914   function_name_no_NOT_clashes '(' param_assignment_list ')'
  4982   function_name_no_NOT_clashes '(' param_assignment_list ')'
  4915 	{$$ = new function_invocation_c($1, $3);}
  4983 	{$$ = new function_invocation_c($1, $3, locloc(@$));}
  4916 ;
  4984 ;
  4917 
  4985 
  4918 
  4986 
  4919 /********************/
  4987 /********************/
  4920 /* B 3.2 Statements */
  4988 /* B 3.2 Statements */
  4921 /********************/
  4989 /********************/
  4922 statement_list:
  4990 statement_list:
  4923   statement ';'
  4991   statement ';'
  4924 	{$$ = new statement_list_c(); $$->add_element($1);}
  4992 	{$$ = new statement_list_c(locloc(@$)); $$->add_element($1);}
  4925 | pragma
  4993 | pragma
  4926 	{$$ = new statement_list_c(); $$->add_element($1);}
  4994 	{$$ = new statement_list_c(locloc(@$)); $$->add_element($1);}
  4927 | statement_list statement ';'
  4995 | statement_list statement ';'
  4928 	{$$ = $1; $$->add_element($2);}
  4996 	{$$ = $1; $$->add_element($2);}
  4929 | statement_list pragma
  4997 | statement_list pragma
  4930 	{$$ = $1; $$->add_element($2);}
  4998 	{$$ = $1; $$->add_element($2);}
       
  4999 /* ERROR_CHECK_BEGIN */
  4931 | statement_list error ';'
  5000 | statement_list error ';'
  4932 	{$$ = $1;
  5001 	{$$ = $1;
  4933 	 print_err_msg(current_filename, @2.last_line, "error in statement.");
  5002 	 print_err_msg(current_filename, @2.first_line, "error in statement.");
  4934 	 /* yychar */
  5003 	 /* yychar */
  4935 	 yyerrok;
  5004 	 yyerrok;
  4936 	}
  5005 	}
       
  5006 /* ERROR_CHECK_END */
  4937 ;
  5007 ;
  4938 
  5008 
  4939 
  5009 
  4940 statement:
  5010 statement:
  4941   assignment_statement
  5011   assignment_statement
  4948 /*********************************/
  5018 /*********************************/
  4949 /* B 3.2.1 Assignment Statements */
  5019 /* B 3.2.1 Assignment Statements */
  4950 /*********************************/
  5020 /*********************************/
  4951 assignment_statement:
  5021 assignment_statement:
  4952   variable ASSIGN expression
  5022   variable ASSIGN expression
  4953 	{$$ = new assignment_statement_c($1, $3);}
  5023 	{$$ = new assignment_statement_c($1, $3, locloc(@$));}
  4954 ;
  5024 ;
  4955 
  5025 
  4956 
  5026 
  4957 
  5027 
  4958 
  5028 
  4964 | return_statement
  5034 | return_statement
  4965 ;
  5035 ;
  4966 
  5036 
  4967 
  5037 
  4968 return_statement:
  5038 return_statement:
  4969   RETURN	{$$ = new return_statement_c();}
  5039   RETURN	{$$ = new return_statement_c(locloc(@$));}
  4970 ;
  5040 ;
  4971 
  5041 
  4972 
  5042 
  4973 
  5043 
  4974 fb_invocation:
  5044 fb_invocation:
  4975   prev_declared_fb_name '(' ')'
  5045   prev_declared_fb_name '(' ')'
  4976 	{$$ = new fb_invocation_c($1, NULL);	}
  5046 	{$$ = new fb_invocation_c($1, NULL, locloc(@$));	}
  4977 | prev_declared_fb_name '(' param_assignment_list ')'
  5047 | prev_declared_fb_name '(' param_assignment_list ')'
  4978 	{$$ = new fb_invocation_c($1, $3);}
  5048 	{$$ = new fb_invocation_c($1, $3, locloc(@$));}
  4979 ;
  5049 ;
  4980 
  5050 
  4981 
  5051 
  4982 /* helper symbol for
  5052 /* helper symbol for
  4983  * - fb_invocation
  5053  * - fb_invocation
  4984  * - function_invocation
  5054  * - function_invocation
  4985  */
  5055  */
  4986 param_assignment_list:
  5056 param_assignment_list:
  4987   param_assignment
  5057   param_assignment
  4988 	{$$ = new param_assignment_list_c(); $$->add_element($1);}
  5058 	{$$ = new param_assignment_list_c(locloc(@$)); $$->add_element($1);}
  4989 | param_assignment_list ',' param_assignment
  5059 | param_assignment_list ',' param_assignment
  4990 	{$$ = $1; $$->add_element($3);}
  5060 	{$$ = $1; $$->add_element($3);}
  4991 ;
  5061 ;
  4992 
  5062 
  4993 
  5063 
  4994 
  5064 
  4995 param_assignment:
  5065 param_assignment:
  4996 /*  variable_name ASSIGN expression */
  5066 /*  variable_name ASSIGN expression */
  4997   any_identifier ASSIGN expression
  5067   any_identifier ASSIGN expression
  4998 	{$$ = new input_variable_param_assignment_c($1, $3);}
  5068 	{$$ = new input_variable_param_assignment_c($1, $3, locloc(@$));}
  4999 | expression
  5069 | expression
  5000 /*| variable_name SENDTO variable */
  5070 /*| variable_name SENDTO variable */
  5001 /*| any_identifier SENDTO variable */
  5071 /*| any_identifier SENDTO variable */
  5002 | sendto_identifier SENDTO variable
  5072 | sendto_identifier SENDTO variable
  5003 	{$$ = new output_variable_param_assignment_c(NULL,$1, $3);}
  5073 	{$$ = new output_variable_param_assignment_c(NULL,$1, $3, locloc(@$));}
  5004 /*| variable_name SENDTO variable */
  5074 /*| variable_name SENDTO variable */
  5005 /*| NOT any_identifier SENDTO variable*/
  5075 /*| NOT any_identifier SENDTO variable*/
  5006 | NOT sendto_identifier SENDTO variable
  5076 | NOT sendto_identifier SENDTO variable
  5007 	{$$ = new output_variable_param_assignment_c(new not_paramassign_c(),$2, $4);}
  5077 	{$$ = new output_variable_param_assignment_c(new not_paramassign_c(locloc(@$)),$2, $4, locloc(@$));}
  5008 ;
  5078 ;
  5009 
  5079 
  5010 
  5080 
  5011 
  5081 
  5012 
  5082 
  5020 ;
  5090 ;
  5021 
  5091 
  5022 
  5092 
  5023 if_statement:
  5093 if_statement:
  5024   IF expression THEN statement_list elseif_statement_list END_IF
  5094   IF expression THEN statement_list elseif_statement_list END_IF
  5025 	{$$ = new if_statement_c($2, $4, $5, NULL);}
  5095 	{$$ = new if_statement_c($2, $4, $5, NULL, locloc(@$));}
  5026 | IF expression THEN statement_list elseif_statement_list ELSE statement_list END_IF
  5096 | IF expression THEN statement_list elseif_statement_list ELSE statement_list END_IF
  5027 	{$$ = new if_statement_c($2, $4, $5, $7);}
  5097 	{$$ = new if_statement_c($2, $4, $5, $7, locloc(@$));}
  5028 ;
  5098 ;
  5029 
  5099 
  5030 /* helper symbol for if_statement */
  5100 /* helper symbol for if_statement */
  5031 elseif_statement_list:
  5101 elseif_statement_list:
  5032   /* empty */
  5102   /* empty */
  5033 	{$$ = new elseif_statement_list_c();}
  5103 	{$$ = new elseif_statement_list_c(locloc(@$));}
  5034 | elseif_statement_list elseif_statement
  5104 | elseif_statement_list elseif_statement
  5035 	{$$ = $1; $$->add_element($2);}
  5105 	{$$ = $1; $$->add_element($2);}
  5036 ;
  5106 ;
  5037 
  5107 
  5038 /* helper symbol for elseif_statement_list */
  5108 /* helper symbol for elseif_statement_list */
  5039 elseif_statement:
  5109 elseif_statement:
  5040   ELSIF expression THEN statement_list
  5110   ELSIF expression THEN statement_list
  5041 	{$$ = new elseif_statement_c($2, $4);}
  5111 	{$$ = new elseif_statement_c($2, $4, locloc(@$));}
  5042 ;
  5112 ;
  5043 
  5113 
  5044 
  5114 
  5045 case_statement:
  5115 case_statement:
  5046   CASE expression OF case_element_list END_CASE
  5116   CASE expression OF case_element_list END_CASE
  5047 	{$$ = new case_statement_c($2, $4, NULL);}
  5117 	{$$ = new case_statement_c($2, $4, NULL, locloc(@$));}
  5048 | CASE expression OF case_element_list ELSE statement_list END_CASE
  5118 | CASE expression OF case_element_list ELSE statement_list END_CASE
  5049 	{$$ = new case_statement_c($2, $4, $6);}
  5119 	{$$ = new case_statement_c($2, $4, $6, locloc(@$));}
  5050 ;
  5120 ;
  5051 
  5121 
  5052 
  5122 
  5053 /* helper symbol for case_statement */
  5123 /* helper symbol for case_statement */
  5054 case_element_list:
  5124 case_element_list:
  5055   case_element
  5125   case_element
  5056 	{$$ = new case_element_list_c(); $$->add_element($1);}
  5126 	{$$ = new case_element_list_c(locloc(@$)); $$->add_element($1);}
  5057 | case_element_list case_element
  5127 | case_element_list case_element
  5058 	{$$ = $1; $$->add_element($2);}
  5128 	{$$ = $1; $$->add_element($2);}
  5059 ;
  5129 ;
  5060 
  5130 
  5061 
  5131 
  5062 case_element:
  5132 case_element:
  5063   case_list ':' statement_list
  5133   case_list ':' statement_list
  5064 	{$$ = new case_element_c($1, $3);}
  5134 	{$$ = new case_element_c($1, $3, locloc(@$));}
  5065 | case_list ':' statement_list identifier BOGUS_TOKEN_ID
  5135 | case_list ':' statement_list identifier BOGUS_TOKEN_ID
  5066 	{$$ = new case_element_c($1, $3); ERROR;}
  5136 	{$$ = new case_element_c($1, $3, locloc(@$)); ERROR;}
  5067 ;
  5137 ;
  5068 
  5138 
  5069 
  5139 
  5070 case_list:
  5140 case_list:
  5071   case_list_element
  5141   case_list_element
  5072 	{$$ = new case_list_c(); $$->add_element($1);}
  5142 	{$$ = new case_list_c(locloc(@$)); $$->add_element($1);}
  5073 | case_list ',' case_list_element
  5143 | case_list ',' case_list_element
  5074 	{$$ = $1; $$->add_element($3);}
  5144 	{$$ = $1; $$->add_element($3);}
  5075 ;
  5145 ;
  5076 
  5146 
  5077 
  5147 
  5102 ;
  5172 ;
  5103 
  5173 
  5104 
  5174 
  5105 for_statement:
  5175 for_statement:
  5106   FOR control_variable ASSIGN expression TO expression BY expression DO statement_list END_FOR
  5176   FOR control_variable ASSIGN expression TO expression BY expression DO statement_list END_FOR
  5107 	{$$ = new for_statement_c($2, $4, $6, $8, $10);}
  5177 	{$$ = new for_statement_c($2, $4, $6, $8, $10, locloc(@$));}
  5108 | FOR control_variable ASSIGN expression TO expression DO statement_list END_FOR
  5178 | FOR control_variable ASSIGN expression TO expression DO statement_list END_FOR
  5109 	{$$ = new for_statement_c($2, $4, $6, NULL, $8);}
  5179 	{$$ = new for_statement_c($2, $4, $6, NULL, $8, locloc(@$));}
  5110 ;
  5180 ;
  5111 
  5181 
  5112 /* The spec has the syntax
  5182 /* The spec has the syntax
  5113  * control_variable: identifier;
  5183  * control_variable: identifier;
  5114  * but then defines the semantics of control_variable
  5184  * but then defines the semantics of control_variable
  5134 */
  5204 */
  5135 
  5205 
  5136 
  5206 
  5137 while_statement:
  5207 while_statement:
  5138   WHILE expression DO statement_list END_WHILE
  5208   WHILE expression DO statement_list END_WHILE
  5139 	{$$ = new while_statement_c($2, $4);}
  5209 	{$$ = new while_statement_c($2, $4, locloc(@$));}
  5140 ;
  5210 ;
  5141 
  5211 
  5142 
  5212 
  5143 repeat_statement:
  5213 repeat_statement:
  5144   REPEAT statement_list UNTIL expression END_REPEAT
  5214   REPEAT statement_list UNTIL expression END_REPEAT
  5145 	{$$ = new repeat_statement_c($2, $4);}
  5215 	{$$ = new repeat_statement_c($2, $4, locloc(@$));}
  5146 ;
  5216 ;
  5147 
  5217 
  5148 
  5218 
  5149 exit_statement:
  5219 exit_statement:
  5150   EXIT	{$$ = new exit_statement_c();}
  5220   EXIT	{$$ = new exit_statement_c(locloc(@$));}
  5151 ;
  5221 ;
  5152 
  5222 
  5153 
  5223 
  5154 
  5224 
  5155 
  5225 
  5189  */
  5259  */
  5190 const char *current_error_msg;
  5260 const char *current_error_msg;
  5191 void yyerror (const char *error_msg) {
  5261 void yyerror (const char *error_msg) {
  5192   current_error_msg = error_msg;
  5262   current_error_msg = error_msg;
  5193 /* fprintf(stderr, "error %d: %s\n", yynerrs // global variable //, error_msg); */
  5263 /* fprintf(stderr, "error %d: %s\n", yynerrs // global variable //, error_msg); */
  5194   print_include_stack();
  5264 /*  print_include_stack(); */
  5195 }
  5265 }
  5196 
  5266 
  5197 
  5267 
  5198 void print_err_msg(const char *filename, int lineno, const char *additional_error_msg) {
  5268 void print_err_msg(const char *filename, int lineno, const char *additional_error_msg) {
  5199   fprintf(stderr, "error %d: %s\n", yynerrs, additional_error_msg);
  5269   fprintf(stderr, "error %d: %s\n", yynerrs /* a global variable */, additional_error_msg);
  5200   print_include_stack();
  5270   print_include_stack();
  5201   fprintf(stderr, "%s:%d: %s\n", filename, lineno, current_error_msg);
  5271   fprintf(stderr, "%s:%d: %s\n", filename, lineno, current_error_msg);
  5202 }
  5272 }
  5203 
  5273 
  5204 
  5274 
  5216 /* NOTE: this code is very ugly and un-eficient, but I (Mario) have many
  5286 /* NOTE: this code is very ugly and un-eficient, but I (Mario) have many
  5217  *       more things to worry about right now, so just let it be...
  5287  *       more things to worry about right now, so just let it be...
  5218  */
  5288  */
  5219 symbol_c *il_operator_c_2_identifier_c(symbol_c *il_operator) {
  5289 symbol_c *il_operator_c_2_identifier_c(symbol_c *il_operator) {
  5220   const char *name = NULL;
  5290   const char *name = NULL;
       
  5291   identifier_c *res;
  5221 
  5292 
  5222   op_2_str(NOT, "NOT");
  5293   op_2_str(NOT, "NOT");
  5223 
  5294 
  5224   op_2_str(AND, "AND");
  5295   op_2_str(AND, "AND");
  5225   op_2_str(OR, "OR");
  5296   op_2_str(OR, "OR");
  5280   op_2_str(JMPCN, "JMPCN");
  5351   op_2_str(JMPCN, "JMPCN");
  5281 
  5352 
  5282   if (name == NULL)
  5353   if (name == NULL)
  5283     ERROR;
  5354     ERROR;
  5284 
  5355 
       
  5356   res = new identifier_c(strdup(name), 
       
  5357                          il_operator->first_line,
       
  5358                          il_operator->first_column,
       
  5359                          il_operator->last_line,
       
  5360                          il_operator->last_column
       
  5361                         );
  5285   free(il_operator);
  5362   free(il_operator);
  5286   return new identifier_c(strdup(name));
  5363   return res;
  5287 }
  5364 }
  5288 
  5365 
  5289 
  5366 
  5290 #include "standard_function_names.c"
  5367 #include "standard_function_names.c"
  5291 
  5368 
  5296 // 2.5.2.3.2  Edge detection
  5373 // 2.5.2.3.2  Edge detection
  5297 //   Table 35 - Standard edge detection function blocks
  5374 //   Table 35 - Standard edge detection function blocks
  5298 "R_TRIG","F_TRIG",
  5375 "R_TRIG","F_TRIG",
  5299 // 2.5.2.3.3  Counters
  5376 // 2.5.2.3.3  Counters
  5300 //   Table 36 - Standard counter function blocks
  5377 //   Table 36 - Standard counter function blocks
  5301 "CTU","CTU_LINT","CTU_UDINT","CTU_ULINT",
  5378 "CTU","CTU_DINT","CTU_LINT","CTU_UDINT","CTU_ULINT",
  5302 "CTD","CTD_DINT","CTD_LINT","CTD_UDINT",
  5379 "CTD","CTD_DINT","CTD_LINT","CTD_UDINT","CTD_ULINT",
  5303 "CTUD","CTUD_DINT","CTUD_LINT","CTUD_ULINT",
  5380 "CTUD","CTUD_DINT","CTUD_LINT","CTUD_ULINT",
  5304 // 2.5.2.3.4  Timers
  5381 // 2.5.2.3.4  Timers
  5305 //   Table 37 - Standard timer function blocks
  5382 //   Table 37 - Standard timer function blocks
  5306 "TP","TON","TOF",
  5383 "TP","TON","TOF",
  5307 /* end of array marker! Do not remove! */
  5384 /* end of array marker! Do not remove! */