
etisserant@0: /*
msousa@261:  *  matiec - a compiler for the programming languages defined in IEC 61131-3
msousa@261:  *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
Edouard@279:  *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
msousa@261:  *
msousa@261:  *  This program is free software: you can redistribute it and/or modify
msousa@261:  *  it under the terms of the GNU General Public License as published by
msousa@261:  *  the Free Software Foundation, either version 3 of the License, or
msousa@261:  *  (at your option) any later version.
msousa@261:  *
msousa@261:  *  This program is distributed in the hope that it will be useful,
msousa@261:  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
msousa@261:  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
msousa@261:  *  GNU General Public License for more details.
msousa@261:  *
msousa@261:  *  You should have received a copy of the GNU General Public License
msousa@261:  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
msousa@261:  *
etisserant@0:  *
etisserant@0:  * This code is made available on the understanding that it will not be
etisserant@0:  * used in safety-critical situations without a full and competent review.
etisserant@0:  */
etisserant@0: 
etisserant@0: /*
msousa@261:  * An IEC 61131-3 compiler.
etisserant@0:  *
etisserant@0:  * Based on the
etisserant@0:  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
etisserant@0:  *
etisserant@0:  */
etisserant@0: 
msousa@261: 
etisserant@0: /*
etisserant@0:  * Definition of the Abstract Syntax data structure components
etisserant@0:  */
etisserant@0: 
etisserant@0: 
etisserant@0: /*
etisserant@0:  * ABSYNTAX.DEF
etisserant@0:  *
etisserant@0:  * This generates the parse tree structure used to bind the components
etisserant@0:  * identified by Bison in the correct syntax order. At the end of the
etisserant@0:  * Bison analysis the tree is walked in a sequential fashion generating
etisserant@0:  * the relavent code.
etisserant@0:  */
etisserant@0: 
etisserant@0: 
mario@177: 
mario@177: 
mario@177: 
mario@177: 
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: /*                                                               */
msousa@257: /*      safe<xxxxxx> Symbols are defined in:                     */
mario@177: /*      PLCopen - Technical Committee 5                          */
mario@177: /*      Safety Software Technical Specification,                 */
mario@177: /*      Part 1: Concepts and Function Blocks,                    */
mario@177: /*      Version 1.0 – Official Release - 2006-01-31              */
mario@177: /*                                                               */
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: 
mario@177: 
mario@177: 
mario@177: 
mario@177: 
mario@177: 
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: /*                                                               */
mario@177: /*             Symbols defined in:                               */
mario@177: /*      FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)          */
mario@177: /*                                                               */
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: /*****************************************************************/
mario@177: 
mario@177: /* Based on the                                    */
mario@177: /* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) */
mario@177: 
mario@177: 
lbessard@143: /* EN/ENO */
ccb@202: /* NOTE we store 'EN' and 'ENO' tokens in an identifier_c
ccb@202:  *      as they may be used as variables, and it is much easier 
ccb@202:  *      to handle them (fewer special cases) if we do it that way...
ccb@202:  */
ccb@202: /*
lbessard@143: SYM_REF0(en_param_c)
lbessard@143: SYM_REF0(eno_param_c)
ccb@202: */
lbessard@143: 
msousa@267: /********************/
msousa@267: /* 2.1.6 - Pragmas  */
msousa@267: /********************/
msousa@267: SYM_REF0(disable_code_generation_pragma_c)
msousa@267: SYM_REF0(enable_code_generation_pragma_c)
etisserant@0: SYM_TOKEN(pragma_c)
etisserant@0: 
msousa@267: 
etisserant@0: /***************************/
etisserant@0: /* B 0 - Programming Model */
etisserant@0: /***************************/
etisserant@0: SYM_LIST(library_c)
etisserant@0: 
etisserant@0: 
etisserant@0: /*************************/
etisserant@0: /* B.1 - Common elements */
etisserant@0: /*************************/
etisserant@0: /*******************************************/
etisserant@0: /* B 1.1 - Letters, digits and identifiers */
etisserant@0: /*******************************************/
etisserant@0: SYM_TOKEN(identifier_c)
etisserant@0: 
etisserant@0: 
etisserant@0: /*********************/
etisserant@0: /* B 1.2 - Constants */
etisserant@0: /*********************/
etisserant@0: 
etisserant@0: /******************************/
etisserant@0: /* B 1.2.1 - Numeric Literals */
etisserant@0: /******************************/
etisserant@0: SYM_TOKEN(real_c)
etisserant@0: SYM_TOKEN(integer_c)
etisserant@0: SYM_TOKEN(binary_integer_c)
etisserant@0: SYM_TOKEN(octal_integer_c)
etisserant@0: SYM_TOKEN(hex_integer_c)
etisserant@0: 
etisserant@0: /* Note:
etisserant@0:  * We do not have signed_integer_c and signed_real_c classes.
etisserant@0:  * These are stored in the parse tree as a integer_c or real_c
msousa@257:  * preceded by a unary minus operator if they are inside an expression,
msousa@257:  * or a neg_integer_c and neg_real_c when used outside an ST expression.
etisserant@0:  */
etisserant@0: /* Not required:
etisserant@0: SYM_TOKEN(signed_integer_c)
etisserant@0: SYM_TOKEN(signed_real_c)
etisserant@0: */
etisserant@0: 
msousa@257: /* NOTE: literal __values__ are stored directly in classes such as:
msousa@257:  *          - real_c
msousa@257:  *          - integer_c
msousa@257:  *          - binary_integer_c
msousa@257:  *          - etc...
msousa@257:  *
msousa@257:  *       However, for both the real_c and the integer_c, if they are preceded 
msousa@257:  *       by a '-' negation sign, they are further encapsulated inside 
msousa@257:  *       a neg_literal_c (i.e. the neg_literal_c will point to the 
msousa@257:  *       real_c or integer_c with the value being negated.
msousa@257:  *          neg_literal_c -> integer_literal_c
msousa@257:  *                OR
msousa@257:  *          neg_literal_c -> real_literal_c
msousa@257:  *
msousa@257:  *      In the semantic verification and code generation stages of the compiler,
msousa@257:  *      the integer_c is treated as a basic (undefined) data type, since an integer
msousa@257:  *      constant may be used as a BYTE, BOOLEAN, REAL, etc..., depending on the
msousa@257:  *      context in which it is used.
msousa@257:  *      However, an integer_c that is preceded by a '-' may not be used
msousa@257:  *      as an ANY_BIT data type (BYTE, BOOLEAN, WORD, ...).
msousa@257:  *      We must therefore be able to determine, holding a simple pointer
msousa@257:  *      to an integer_c, if that integer_c value is preceded by a '-'.
msousa@257:  *      However, since the neg_literal_c points to the integer_c, and not
msousa@257:  *      vice-versa, we can't determine that.
msousa@257:  *      There are 3 simple ways of working around this:
msousa@257:  *        - change the order of the pointers: 
msousa@257:  *              have the integer_c and real_c point to the neg_literal_c
msousa@257:  *        - maintain the order of the pointers, and
msousa@257:  *              add redundant info to the integer_c and real_c
msousa@257:  *        - replace the neg_literal_c with two distinc classes
msousa@257:  *              (neg_integer_c and neg_real_c), one for each
msousa@257:  *              lietral type. This means that we can now treat
msousa@257:  *              each of these classes as an unknown data type
msousa@257:  *              just as we do with the integer_c and real_c.
msousa@257:  *
msousa@257:  *      The second option is simply ugly.
msousa@257:  *      and the first has a serious drawback: when generating code it is
msousa@257:  *      easier to encapsulate the real or integer values inside prefix
msousa@257:  *      and postfix symbols (e.g. NEG(<value>) - with postfix ')' )
msousa@257:  *      if we keep the pointer order as is.
msousa@257:  *
msousa@257:  *      For the above reasoning, we use the third option.
msousa@257:  */  
msousa@257: SYM_REF1(neg_real_c, exp)
msousa@257: SYM_REF1(neg_integer_c, exp)
lbessard@118: 
ccb@202: /* Not required:
etisserant@0: SYM_REF2(numeric_literal_c, type, value)
ccb@202: */
etisserant@0: SYM_REF2(integer_literal_c, type, value)
etisserant@0: SYM_REF2(real_literal_c, type, value)
etisserant@0: SYM_REF2(bit_string_literal_c, type, value)
msousa@257: /* A typed or untyped boolean literal... */
msousa@257: /* type may be NULL */
etisserant@0: SYM_REF2(boolean_literal_c, type, value)
etisserant@0: 
etisserant@0: /* helper class for boolean_literal_c */
etisserant@0: SYM_REF0(boolean_true_c)
etisserant@0: 
etisserant@0: /* helper class for boolean_literal_c */
etisserant@0: SYM_REF0(boolean_false_c)
etisserant@0: 
etisserant@0: 
etisserant@0: /*******************************/
etisserant@0: /* B.1.2.2   Character Strings */
etisserant@0: /*******************************/
etisserant@0: SYM_TOKEN(double_byte_character_string_c)
etisserant@0: SYM_TOKEN(single_byte_character_string_c)
etisserant@0: 
etisserant@0: 
etisserant@0: /***************************/
etisserant@0: /* B 1.2.3 - Time Literals */
etisserant@0: /***************************/
etisserant@0: 
etisserant@0: /************************/
etisserant@0: /* B 1.2.3.1 - Duration */
etisserant@0: /************************/
etisserant@0: SYM_REF0(neg_time_c)
msousa@257: SYM_REF3(duration_c, type_name, neg, interval)
etisserant@0: SYM_TOKEN(fixed_point_c)
etisserant@0: SYM_REF2(days_c, days, hours)
etisserant@0: SYM_REF2(hours_c, hours, minutes)
etisserant@0: SYM_REF2(minutes_c, minutes, seconds)
etisserant@0: SYM_REF2(seconds_c, seconds, milliseconds)
mario@69: SYM_REF1(milliseconds_c, milliseconds)
etisserant@0: 
etisserant@0: 
etisserant@0: /************************************/
etisserant@0: /* B 1.2.3.2 - Time of day and Date */
etisserant@0: /************************************/
msousa@257: SYM_REF2(time_of_day_c, type_name, daytime)
mario@69: SYM_REF3(daytime_c, day_hour, day_minute, day_second)
msousa@257: SYM_REF2(date_c, type_name, date_literal)
mario@69: SYM_REF3(date_literal_c, year, month, day)
msousa@257: SYM_REF3(date_and_time_c, type_name, date_literal, daytime)
etisserant@0: 
etisserant@0: 
etisserant@0: /**********************/
etisserant@0: /* B.1.3 - Data types */
etisserant@0: /**********************/
etisserant@0: /***********************************/
etisserant@0: /* B 1.3.1 - Elementary Data Types */
etisserant@0: /***********************************/
etisserant@0: SYM_REF0(time_type_name_c)
etisserant@0: SYM_REF0(bool_type_name_c)
etisserant@0: SYM_REF0(sint_type_name_c)
etisserant@0: SYM_REF0(int_type_name_c)
etisserant@0: SYM_REF0(dint_type_name_c)
etisserant@0: SYM_REF0(lint_type_name_c)
etisserant@0: SYM_REF0(usint_type_name_c)
etisserant@0: SYM_REF0(uint_type_name_c)
etisserant@0: SYM_REF0(udint_type_name_c)
etisserant@0: SYM_REF0(ulint_type_name_c)
etisserant@0: SYM_REF0(real_type_name_c)
etisserant@0: SYM_REF0(lreal_type_name_c)
etisserant@0: SYM_REF0(date_type_name_c)
etisserant@0: SYM_REF0(tod_type_name_c)
etisserant@0: SYM_REF0(dt_type_name_c)
etisserant@0: SYM_REF0(byte_type_name_c)
etisserant@0: SYM_REF0(word_type_name_c)
etisserant@0: SYM_REF0(dword_type_name_c)
etisserant@0: SYM_REF0(lword_type_name_c)
etisserant@0: SYM_REF0(string_type_name_c)
etisserant@0: SYM_REF0(wstring_type_name_c)
ccb@202: 
msousa@257:   /*****************************************************************/
msousa@257:   /* Keywords defined in "Safety Software Technical Specification" */
msousa@257:   /*****************************************************************/
msousa@257: 
msousa@257: SYM_REF0(safetime_type_name_c)
msousa@257: SYM_REF0(safebool_type_name_c)
msousa@257: SYM_REF0(safesint_type_name_c)
msousa@257: SYM_REF0(safeint_type_name_c)
msousa@257: SYM_REF0(safedint_type_name_c)
msousa@257: SYM_REF0(safelint_type_name_c)
msousa@257: SYM_REF0(safeusint_type_name_c)
msousa@257: SYM_REF0(safeuint_type_name_c)
msousa@257: SYM_REF0(safeudint_type_name_c)
msousa@257: SYM_REF0(safeulint_type_name_c)
msousa@257: SYM_REF0(safereal_type_name_c)
msousa@257: SYM_REF0(safelreal_type_name_c)
msousa@257: SYM_REF0(safedate_type_name_c)
msousa@257: SYM_REF0(safetod_type_name_c)
msousa@257: SYM_REF0(safedt_type_name_c)
msousa@257: SYM_REF0(safebyte_type_name_c)
msousa@257: SYM_REF0(safeword_type_name_c)
msousa@257: SYM_REF0(safedword_type_name_c)
msousa@257: SYM_REF0(safelword_type_name_c)
msousa@257: SYM_REF0(safestring_type_name_c)
msousa@257: SYM_REF0(safewstring_type_name_c)
etisserant@0: 
etisserant@0: 
etisserant@0: /********************************/
etisserant@0: /* B.1.3.2 - Generic data types */
etisserant@0: /********************************/
etisserant@0: 
etisserant@0: /********************************/
etisserant@0: /* B 1.3.3 - Derived data types */
etisserant@0: /********************************/
etisserant@0: /*  TYPE type_declaration_list END_TYPE */
mario@69: SYM_REF1(data_type_declaration_c, type_declaration_list)
etisserant@0: 
etisserant@0: /* helper symbol for data_type_declaration */
etisserant@0: SYM_LIST(type_declaration_list_c)
etisserant@0: 
etisserant@0: /*  simple_type_name ':' simple_spec_init */
etisserant@0: SYM_REF2(simple_type_declaration_c, simple_type_name, simple_spec_init)
etisserant@0: 
etisserant@0: 
etisserant@0: /* simple_specification ASSIGN constant */
etisserant@0: SYM_REF2(simple_spec_init_c, simple_specification, constant)
etisserant@0: 
etisserant@0: /*  subrange_type_name ':' subrange_spec_init */
etisserant@0: SYM_REF2(subrange_type_declaration_c, subrange_type_name, subrange_spec_init)
etisserant@0: 
etisserant@0: /* subrange_specification ASSIGN signed_integer */
etisserant@0: SYM_REF2(subrange_spec_init_c, subrange_specification, signed_integer)
etisserant@0: 
etisserant@0: /*  integer_type_name '(' subrange')' */
etisserant@0: SYM_REF2(subrange_specification_c, integer_type_name, subrange)
etisserant@0: 
etisserant@0: /*  signed_integer DOTDOT signed_integer */
etisserant@0: SYM_REF2(subrange_c, lower_limit, upper_limit)
etisserant@0: 
etisserant@0: /*  enumerated_type_name ':' enumerated_spec_init */
etisserant@0: SYM_REF2(enumerated_type_declaration_c, enumerated_type_name, enumerated_spec_init)
etisserant@0: 
etisserant@0: /* enumerated_specification ASSIGN enumerated_value */
etisserant@0: SYM_REF2(enumerated_spec_init_c, enumerated_specification, enumerated_value)
etisserant@0: 
etisserant@0: /* helper symbol for enumerated_specification->enumerated_spec_init */
etisserant@0: /* enumerated_value_list ',' enumerated_value */
etisserant@0: SYM_LIST(enumerated_value_list_c)
etisserant@0: 
etisserant@0: /* enumerated_type_name '#' identifier */
etisserant@0: SYM_REF2(enumerated_value_c, type, value)
etisserant@0: 
etisserant@0: /*  identifier ':' array_spec_init */
etisserant@0: SYM_REF2(array_type_declaration_c, identifier, array_spec_init)
etisserant@0: 
etisserant@0: /* array_specification [ASSIGN array_initialization} */
etisserant@0: /* array_initialization may be NULL ! */
etisserant@0: SYM_REF2(array_spec_init_c, array_specification, array_initialization)
etisserant@0: 
etisserant@0: /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
etisserant@0: SYM_REF2(array_specification_c, array_subrange_list, non_generic_type_name)
etisserant@0: 
etisserant@0: /* helper symbol for array_specification */
etisserant@0: /* array_subrange_list ',' subrange */
etisserant@0: SYM_LIST(array_subrange_list_c)
etisserant@0: 
etisserant@0: /* array_initialization:  '[' array_initial_elements_list ']' */
etisserant@0: /* helper symbol for array_initialization */
etisserant@0: /* array_initial_elements_list ',' array_initial_elements */
etisserant@0: SYM_LIST(array_initial_elements_list_c)
etisserant@0: 
etisserant@0: /* integer '(' [array_initial_element] ')' */
etisserant@0: /* array_initial_element may be NULL ! */
etisserant@0: SYM_REF2(array_initial_elements_c, integer, array_initial_element)
etisserant@0: 
etisserant@0: /*  structure_type_name ':' structure_specification */
etisserant@0: SYM_REF2(structure_type_declaration_c, structure_type_name, structure_specification)
etisserant@0: 
etisserant@0: /* structure_type_name ASSIGN structure_initialization */
etisserant@0: /* structure_initialization may be NULL ! */
etisserant@0: SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
etisserant@0: 
etisserant@0: /* helper symbol for structure_declaration */
etisserant@0: /* structure_declaration:  STRUCT structure_element_declaration_list END_STRUCT */
etisserant@0: /* structure_element_declaration_list structure_element_declaration ';' */
etisserant@0: SYM_LIST(structure_element_declaration_list_c)
etisserant@0: 
etisserant@0: /*  structure_element_name ':' *_spec_init */
etisserant@0: SYM_REF2(structure_element_declaration_c, structure_element_name, spec_init)
etisserant@0: 
etisserant@0: /* helper symbol for structure_initialization */
etisserant@0: /* structure_initialization: '(' structure_element_initialization_list ')' */
etisserant@0: /* structure_element_initialization_list ',' structure_element_initialization */
etisserant@0: SYM_LIST(structure_element_initialization_list_c)
etisserant@0: 
etisserant@0: /*  structure_element_name ASSIGN value */
etisserant@0: SYM_REF2(structure_element_initialization_c, structure_element_name, value)
etisserant@0: 
etisserant@0: /*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
etisserant@0: /*
etisserant@0:  * NOTE:
etisserant@0:  * (Summary: Contrary to what is expected, the
etisserant@0:  *           string_type_declaration_c is not used to store
etisserant@0:  *           simple string type declarations that do not include
etisserant@0:  *           size limits.
etisserant@0:  *           For e.g.:
etisserant@0:  *             str1_type: STRING := "hello!"
etisserant@0:  *           will be stored in a simple_type_declaration_c
etisserant@0:  *           instead of a string_type_declaration_c.
etisserant@0:  *           The following:
etisserant@0:  *             str2_type: STRING [64] := "hello!"
etisserant@0:  *           will be stored in a sring_type_declaration_c
etisserant@0:  *
etisserant@0:  *           Read on for why this is done...
etisserant@0:  * End Summary)
etisserant@0:  *
etisserant@0:  * According to the spec, the valid construct
etisserant@0:  * TYPE new_str_type : STRING := "hello!"; END_TYPE
etisserant@0:  * has two possible routes to type_declaration...
etisserant@0:  *
etisserant@0:  * Route 1:
etisserant@0:  * type_declaration: single_element_type_declaration
etisserant@0:  * single_element_type_declaration: simple_type_declaration
etisserant@0:  * simple_type_declaration: identifier ':' simple_spec_init
etisserant@0:  * simple_spec_init: simple_specification ASSIGN constant
etisserant@0:  * (shift:  identifier <- 'new_str_type')
etisserant@0:  * simple_specification: elementary_type_name
etisserant@0:  * elementary_type_name: STRING
etisserant@0:  * (shift: elementary_type_name <- STRING)
etisserant@0:  * (reduce: simple_specification <- elementary_type_name)
etisserant@0:  * (shift: constant <- "hello!")
etisserant@0:  * (reduce: simple_spec_init: simple_specification ASSIGN constant)
etisserant@0:  * (reduce: ...)
etisserant@0:  *
etisserant@0:  *
etisserant@0:  * Route 2:
etisserant@0:  * type_declaration: string_type_declaration
etisserant@0:  * string_type_declaration: identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init
etisserant@0:  * (shift:  identifier <- 'new_str_type')
etisserant@0:  * elementary_string_type_name: STRING
etisserant@0:  * (shift: elementary_string_type_name <- STRING)
etisserant@0:  * (shift: string_type_declaration_size <-  empty )
etisserant@0:  * string_type_declaration_init: ASSIGN character_string
etisserant@0:  * (shift: character_string <- "hello!")
etisserant@0:  * (reduce: string_type_declaration_init <- ASSIGN character_string)
etisserant@0:  * (reduce: string_type_declaration <- identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init )
etisserant@0:  * (reduce: type_declaration <- string_type_declaration)
etisserant@0:  *
etisserant@0:  *
etisserant@0:  * At first glance it seems that removing route 1 would make
etisserant@0:  * the most sense. Unfortunately the construct 'simple_spec_init'
etisserant@0:  * shows up multiple times in other rules, so changing this construct
etisserant@0:  * would also mean changing all the rules in which it appears.
etisserant@0:  * I (Mario) therefore chose to remove route 2 instead. This means
etisserant@0:  * that the above declaration gets stored in a
etisserant@0:  * simple_type_declaration_c, and not in a string_type_declaration_c
etisserant@0:  * as would be expected!
etisserant@0:  */
etisserant@0: /*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
etisserant@0: SYM_REF4(string_type_declaration_c,	string_type_name,
etisserant@0: 					elementary_string_type_name,
etisserant@0: 					string_type_declaration_size,
etisserant@0: 					string_type_declaration_init) /* may be == NULL! */
etisserant@0: 
etisserant@0: 
etisserant@0: /*********************/
etisserant@0: /* B 1.4 - Variables */
etisserant@0: /*********************/
mario@69: SYM_REF1(symbolic_variable_c, var_name)
etisserant@0: 
etisserant@0: /********************************************/
etisserant@0: /* B.1.4.1   Directly Represented Variables */
etisserant@0: /********************************************/
etisserant@0: SYM_TOKEN(direct_variable_c)
etisserant@0: 
etisserant@0: /*************************************/
etisserant@0: /* B.1.4.2   Multi-element Variables */
etisserant@0: /*************************************/
etisserant@0: /*  subscripted_variable '[' subscript_list ']' */
etisserant@0: SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
etisserant@0: 
etisserant@0: /* subscript_list ',' subscript */
etisserant@0: SYM_LIST(subscript_list_c)
etisserant@0: 
etisserant@0: /*  record_variable '.' field_selector */
etisserant@0: /*  WARNING: input and/or output variables of function blocks
etisserant@1:  *           may be accessed as fields of a structured variable!
etisserant@0:  *           Code handling a structured_variable_c must take
etisserant@0:  *           this into account!
etisserant@0:  */
etisserant@0: SYM_REF2(structured_variable_c, record_variable, field_selector)
etisserant@0: 
etisserant@0: /******************************************/
etisserant@0: /* B 1.4.3 - Declaration & Initialisation */
etisserant@0: /******************************************/
etisserant@0: SYM_REF0(constant_option_c)
etisserant@0: SYM_REF0(retain_option_c)
etisserant@0: SYM_REF0(non_retain_option_c)
etisserant@0: 
etisserant@0: /* option -> the RETAIN/NON_RETAIN/<NULL> directive... */
ccb@202: /* NOTE: We need to implicitly define the EN and ENO function and FB parameters when the user
ccb@202:  *       does not do it explicitly in the IEC 61131-3 source code. 
ccb@202:  *       To be able to distinguish later on between implictly and explicitly defined
ccb@202:  *       variables, we use the 'method' flag that allows us to remember
ccb@202:  *       whether this declaration was in the original source code (method -> implicit_definition_c) 
ccb@202:  *       or not (method -> explicit_definition_c).
ccb@202:  */
ccb@202: SYM_REF3(input_declarations_c, option, input_declaration_list, method)
etisserant@0: 
etisserant@0: /* helper symbol for input_declarations */
etisserant@0: SYM_LIST(input_declaration_list_c)
etisserant@0: 
ccb@202: /* NOTE: The formal definition of the standard is erroneous, as it simply does not
ccb@202:  *       consider the EN and ENO keywords!
ccb@202:  *       The semantic description of the languages clearly states that these may be
ccb@202:  *       used in several ways. One of them is to declare an EN input parameter, or
ccb@202:  *       an ENO output parameter.
ccb@202:  *       We have added the 'en_param_declaration_c' and 'eno_param_declaration_c' 
ccb@202:  *       to cover for this.
ccb@202:  *
ccb@202:  *       We could have re-used the standard class used for all other input variables (with
ccb@202:  *       an identifier set to 'EN' or 'ENO') however we may sometimes need to add this
ccb@202:  *       declaration implicitly (if the user does not include it in the source
ccb@202:  *       code himself), and it is good to know whether it was added implicitly or not.
ccb@202:  *       So we create a new class that has a 'method' flag that allows us to remember
ccb@202:  *       whether this declaration was in the original source code (method -> implicit_definition_c) 
ccb@202:  *       or not (method -> explicit_definition_c).
ccb@202:  */
ccb@202: SYM_REF0(implicit_definition_c)
ccb@202: SYM_REF0(explicit_definition_c)
ccb@202: SYM_REF4(en_param_declaration_c, name, type, value, method)
ccb@202: SYM_REF3(eno_param_declaration_c, name, type, method)
ccb@202: 
etisserant@0: /* edge -> The F_EDGE or R_EDGE directive */
etisserant@0: SYM_REF2(edge_declaration_c, edge, var1_list)
etisserant@0: 
etisserant@0: SYM_REF0(raising_edge_option_c)
etisserant@0: SYM_REF0(falling_edge_option_c)
etisserant@0: 
etisserant@0: /* spec_init is one of the following...
etisserant@0:  *    simple_spec_init_c *
etisserant@0:  *    subrange_spec_init_c *
etisserant@0:  *    enumerated_spec_init_c *
etisserant@0:  */
etisserant@0: SYM_REF2(var1_init_decl_c, var1_list, spec_init)
etisserant@0: 
etisserant@0: /* | var1_list ',' variable_name */
etisserant@0: SYM_LIST(var1_list_c)
etisserant@0: 
msousa@350: /* | [var1_list ','] variable_name integer '..' */
msousa@350: /* NOTE: This is an extension to the standard!!! */
msousa@350: /* In order to be able to handle extensible standard functions
msousa@350:  * (i.e. standard functions that may have a variable number of
msousa@350:  * input parameters, such as AND(word#33, word#44, word#55, word#66),
msousa@350:  * we have extended the acceptable syntax to allow var_name '..'
msousa@350:  * in an input variable declaration.
msousa@350:  *
msousa@350:  * This allows us to parse the declaration of standard
msousa@350:  * extensible functions and load their interface definition
msousa@350:  * into the abstract syntax tree just like we do to other 
msousa@350:  * user defined functions.
msousa@350:  * This has the advantage that we can later do semantic
msousa@350:  * checking of calls to functions (be it a standard or user defined
msousa@350:  * function) in (almost) exactly the same way.
msousa@350:  *
msousa@350:  * The integer tells the compiler the number of the first parameter.
msousa@350:  * for example, for ADD(IN1 := 11, IN2:=22), the index for IN starts off at 1.
msousa@350:  * Some other standard library functions, such as MUX, has the extensible
msousa@350:  * variable starting off from 0 (IN0, IN1, IN2, ...).
msousa@350:  *
msousa@350:  * Of course, we have a flag that disables this syntax when parsing user
msousa@350:  * written code, so we only allow this extra syntax while parsing the 
msousa@350:  * 'header' file that declares all the standard IEC 61131-3 functions.
msousa@350:  */
msousa@350: SYM_REF2(extensible_input_parameter_c, var_name, first_index)
msousa@350: 
etisserant@0: /* var1_list ':' array_spec_init */
etisserant@0: SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init)
etisserant@0: 
etisserant@0: /*  var1_list ':' initialized_structure */
etisserant@0: SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure)
etisserant@0: 
etisserant@0: /* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
etisserant@0: /* structure_initialization -> may be NULL ! */
mario@69: SYM_REF3(fb_name_decl_c, fb_name_list, function_block_type_name, structure_initialization)
etisserant@0: 
etisserant@0: /* fb_name_list ',' fb_name */
etisserant@0: SYM_LIST(fb_name_list_c)
etisserant@0: 
etisserant@0: /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */
etisserant@0: /* option -> may be NULL ! */
ccb@202: /* NOTE: We need to implicitly define the EN and ENO function and FB parameters when the user
ccb@202:  *       does not do it explicitly in the IEC 61131-3 source code. 
ccb@202:  *       To be able to distinguish later on between implictly and explicitly defined
ccb@202:  *       variables, we use the 'method' flag that allows us to remember
ccb@202:  *       whether this declaration was in the original source code (method -> implicit_definition_c) 
ccb@202:  *       or not (method -> explicit_definition_c).
ccb@202:  */
ccb@202: SYM_REF3(output_declarations_c, option, var_init_decl_list, method)
lbessard@146: 
etisserant@0: /*  VAR_IN_OUT var_declaration_list END_VAR */
mario@69: SYM_REF1(input_output_declarations_c, var_declaration_list)
etisserant@0: 
etisserant@0: /* helper symbol for input_output_declarations */
etisserant@0: /* var_declaration_list var_declaration ';' */
etisserant@0: SYM_LIST(var_declaration_list_c)
etisserant@0: 
etisserant@0: /*  var1_list ':' array_specification */
etisserant@0: SYM_REF2(array_var_declaration_c, var1_list, array_specification)
etisserant@0: 
etisserant@0: /*  var1_list ':' structure_type_name */
etisserant@0: SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name)
etisserant@0: 
etisserant@0: /* VAR [CONSTANT] var_init_decl_list END_VAR */
etisserant@0: /* option -> may be NULL ! */
etisserant@0: SYM_REF2(var_declarations_c, option, var_init_decl_list)
etisserant@0: 
etisserant@0: /*  VAR RETAIN var_init_decl_list END_VAR */
mario@69: SYM_REF1(retentive_var_declarations_c, var_init_decl_list)
etisserant@0: 
etisserant@0: /*  VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */
etisserant@0: /* option -> may be NULL ! */
etisserant@0: SYM_REF2(located_var_declarations_c, option, located_var_decl_list)
etisserant@0: 
etisserant@0: /* helper symbol for located_var_declarations */
etisserant@0: /* located_var_decl_list located_var_decl ';' */
etisserant@0: SYM_LIST(located_var_decl_list_c)
etisserant@0: 
etisserant@0: /*  [variable_name] location ':' located_var_spec_init */
etisserant@0: /* variable_name -> may be NULL ! */
mario@69: SYM_REF3(located_var_decl_c, variable_name, location, located_var_spec_init)
etisserant@0: 
etisserant@0: /*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */
etisserant@0: /* option -> may be NULL ! */
etisserant@0: SYM_REF2(external_var_declarations_c, option, external_declaration_list)
etisserant@0: 
etisserant@0: /* helper symbol for external_var_declarations */
etisserant@0: /*| external_declaration_list external_declaration';' */
etisserant@0: SYM_LIST(external_declaration_list_c)
etisserant@0: 
etisserant@0: /*  global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */
etisserant@0: SYM_REF2(external_declaration_c, global_var_name, specification)
etisserant@0: 
etisserant@0: /*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */
etisserant@0: /* option -> may be NULL ! */
etisserant@0: SYM_REF2(global_var_declarations_c, option, global_var_decl_list)
etisserant@0: 
etisserant@0: /* helper symbol for global_var_declarations */
etisserant@0: /*| global_var_decl_list global_var_decl ';' */
etisserant@0: SYM_LIST(global_var_decl_list_c)
etisserant@0: 
etisserant@0: /*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */
etisserant@0: /* type_specification ->may be NULL ! */
etisserant@0: SYM_REF2(global_var_decl_c, global_var_spec, type_specification)
etisserant@0: 
etisserant@0: /*| global_var_name location */
etisserant@0: SYM_REF2(global_var_spec_c, global_var_name, location)
etisserant@0: 
etisserant@0: /*  AT direct_variable */
mario@69: SYM_REF1(location_c, direct_variable)
etisserant@0: 
etisserant@0: /*| global_var_list ',' global_var_name */
etisserant@0: SYM_LIST(global_var_list_c)
etisserant@0: 
etisserant@0: /*  var1_list ':' single_byte_string_spec */
etisserant@0: SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec)
etisserant@0: 
etisserant@0: /*  STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */
etisserant@0: /* integer ->may be NULL ! */
etisserant@0: /* single_byte_character_string ->may be NULL ! */
msousa@350: SYM_REF2(single_byte_string_spec_c, string_spec, single_byte_character_string)
msousa@350: 
msousa@350: /*   STRING ['[' integer ']'] */
msousa@350: /* integer ->may be NULL ! */
msousa@350: SYM_REF2(single_byte_limited_len_string_spec_c, string_type_name, character_string_len)
msousa@350: 
msousa@350: /*  WSTRING ['[' integer ']'] */
msousa@350: /* integer ->may be NULL ! */
msousa@350: SYM_REF2(double_byte_limited_len_string_spec_c, string_type_name, character_string_len)
etisserant@0: 
etisserant@0: /*  var1_list ':' double_byte_string_spec */
etisserant@0: SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec)
etisserant@0: 
etisserant@0: /*  WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */
etisserant@0: /* integer ->may be NULL ! */
etisserant@0: /* double_byte_character_string ->may be NULL ! */
msousa@350: SYM_REF2(double_byte_string_spec_c, string_spec, double_byte_character_string)
etisserant@0: 
etisserant@0: /*| VAR [RETAIN|NON_RETAIN] incompl_located_var_decl_list END_VAR */
etisserant@0: /* option ->may be NULL ! */
etisserant@0: SYM_REF2(incompl_located_var_declarations_c, option, incompl_located_var_decl_list)
etisserant@0: 
etisserant@0: /* helper symbol for incompl_located_var_declarations */
etisserant@0: /*| incompl_located_var_decl_list incompl_located_var_decl ';' */
etisserant@0: SYM_LIST(incompl_located_var_decl_list_c)
etisserant@0: 
etisserant@0: /*  variable_name incompl_location ':' var_spec */
mario@69: SYM_REF3(incompl_located_var_decl_c, variable_name, incompl_location, var_spec)
etisserant@0: 
etisserant@0: /*  AT incompl_location_token */
etisserant@0: SYM_TOKEN(incompl_location_c)
etisserant@0: 
etisserant@0: /* intermediate helper symbol for:
etisserant@0:  *  - non_retentive_var_decls
etisserant@0:  *  - output_declarations
etisserant@0:  */
etisserant@0: SYM_LIST(var_init_decl_list_c)
etisserant@0: 
etisserant@0: 
etisserant@0: 
etisserant@0: 
etisserant@0: /**************************************/
etisserant@0: /* B.1.5 - Program organization units */
etisserant@0: /**************************************/
etisserant@0: /***********************/
etisserant@0: /* B 1.5.1 - Functions */
etisserant@0: /***********************/
etisserant@0: SYM_REF4(function_declaration_c, derived_function_name, type_name, var_declarations_list, function_body)
etisserant@0: 
etisserant@0: /* intermediate helper symbol for
etisserant@0:  * - function_declaration
etisserant@0:  * - function_block_declaration
etisserant@0:  * - program_declaration
etisserant@0:  */
etisserant@0: SYM_LIST(var_declarations_list_c)
etisserant@0: 
etisserant@0: /* option -> storage method, CONSTANT or <null> */
etisserant@0: SYM_REF2(function_var_decls_c, option, decl_list)
etisserant@0: 
etisserant@0: /* intermediate helper symbol for function_var_decls */
etisserant@0: SYM_LIST(var2_init_decl_list_c)
etisserant@0: 
etisserant@0: 
etisserant@0: /*****************************/
etisserant@0: /* B 1.5.2 - Function Blocks */
etisserant@0: /*****************************/
etisserant@0: /*  FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
mario@69: SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body)
etisserant@0: 
etisserant@0: /* intermediate helper symbol for function_declaration */
etisserant@0: /*  { io_var_declarations | other_var_declarations }   */
etisserant@0: /*
etisserant@0:  * NOTE: we re-use the var_declarations_list_c
etisserant@0:  */
etisserant@0: 
etisserant@0: /*  VAR_TEMP temp_var_decl_list END_VAR */
mario@69: SYM_REF1(temp_var_decls_c, var_decl_list)
etisserant@0: 
etisserant@0: /* intermediate helper symbol for temp_var_decls */
etisserant@0: SYM_LIST(temp_var_decls_list_c)
etisserant@0: 
etisserant@0: /*  VAR NON_RETAIN var_init_decl_list END_VAR */
mario@69: SYM_REF1(non_retentive_var_decls_c, var_decl_list)
etisserant@0: 
etisserant@0: 
etisserant@0: /**********************/
etisserant@0: /* B 1.5.3 - Programs */
etisserant@0: /**********************/
etisserant@0: /*  PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */
mario@69: SYM_REF3(program_declaration_c, program_type_name, var_declarations, function_block_body)
etisserant@0: 
etisserant@0: /* intermediate helper symbol for program_declaration_c */
etisserant@0: /*  { io_var_declarations | other_var_declarations }   */
etisserant@0: /*
etisserant@0:  * NOTE: we re-use the var_declarations_list_c
etisserant@0:  */
etisserant@0: 
etisserant@0: 
etisserant@0: 
etisserant@0: /*********************************************/
etisserant@0: /* B.1.6  Sequential function chart elements */
etisserant@0: /*********************************************/
etisserant@0: 
mario@97: /* | sequential_function_chart sfc_network */
etisserant@1: SYM_LIST(sequential_function_chart_c)
etisserant@1: 
mario@97: /* initial_step {step | transition | action} */
etisserant@1: SYM_LIST(sfc_network_c)
etisserant@1: 
mario@97: /* INITIAL_STEP step_name ':' action_association_list END_STEP */
etisserant@1: SYM_REF2(initial_step_c, step_name, action_association_list)
etisserant@1: 
mario@97: /* | action_association_list action_association ';' */
etisserant@1: SYM_LIST(action_association_list_c)
mario@97: 
mario@97: /* STEP step_name ':' action_association_list END_STEP */
etisserant@1: SYM_REF2(step_c, step_name, action_association_list)
mario@97: 
mario@97: /* action_name '(' action_qualifier indicator_name_list ')' */
mario@97: /* action_qualifier -> may be NULL ! */
mario@69: SYM_REF3(action_association_c, action_name, action_qualifier, indicator_name_list)
etisserant@1: 
mario@97: /* N | R | S | P */
etisserant@1: SYM_TOKEN(qualifier_c)
mario@97: 
mario@97: /* L | D | SD | DS | SL */
etisserant@1: SYM_TOKEN(timed_qualifier_c)
etisserant@1: 
mario@97: /* | indicator_name_list ',' indicator_name */
etisserant@1: SYM_LIST(indicator_name_list_c)
etisserant@1: 
mario@97: /* qualifier | timed_qualifier ',' action_time */
mario@97: /* action_time -> may be NULL ! */
etisserant@1: SYM_REF2(action_qualifier_c, action_qualifier, action_time)
etisserant@1: 
mario@97: /* TRANSITION [transition_name] ['(' PRIORITY ASSIGN integer ')'] 
mario@97:  *   FROM steps TO steps 
mario@97:  *   transition_condition 
mario@97:  * END_TRANSITION
mario@97: */
mario@97: /* transition_name -> may be NULL ! */
mario@97: /* integer -> may be NULL ! */
lbessard@87: SYM_REF5(transition_c, transition_name, integer, from_steps, to_steps, transition_condition)
lbessard@87: 
mario@97: /* ':' eol_list simple_instr_list | ASSIGN expression ';' */
mario@97: /* transition_condition_il -> may be NULL ! */
mario@97: /* transition_condition_st -> may be NULL ! */
lbessard@87: SYM_REF2(transition_condition_c, transition_condition_il, transition_condition_st)
etisserant@1: 
mario@97: /* step_name | '(' step_name_list ')' */
mario@97: /* step_name      -> may be NULL ! */
mario@97: /* step_name_list -> may be NULL ! */
etisserant@1: SYM_REF2(steps_c, step_name, step_name_list)
etisserant@1: 
mario@97: /* | step_name_list ',' step_name */
etisserant@1: SYM_LIST(step_name_list_c)
etisserant@1: 
mario@97: /* ACTION action_name ':' function_block_body END_ACTION */
etisserant@1: SYM_REF2(action_c, action_name, function_block_body)
etisserant@0: 
etisserant@0: /********************************/
etisserant@0: /* B 1.7 Configuration elements */
etisserant@0: /********************************/
etisserant@0: 
etisserant@0: /*
etisserant@0: CONFIGURATION configuration_name
etisserant@0:    optional_global_var_declarations
etisserant@0:    (resource_declaration_list | single_resource_declaration)
etisserant@0:    optional_access_declarations
etisserant@0:    optional_instance_specific_initializations
etisserant@0: END_CONFIGURATION
etisserant@0: */
mario@69: SYM_REF5(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations)
etisserant@0: 
etisserant@0: /* helper symbol for configuration_declaration */
etisserant@0: SYM_LIST(resource_declaration_list_c)
etisserant@0: 
etisserant@0: /*
etisserant@0: RESOURCE resource_name ON resource_type_name
etisserant@0:    optional_global_var_declarations
etisserant@0:    single_resource_declaration
etisserant@0: END_RESOURCE
etisserant@0: */
etisserant@0: SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration)
etisserant@0: 
etisserant@0: /* task_configuration_list program_configuration_list */
etisserant@0: SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list)
etisserant@0: 
etisserant@0: /* helper symbol for single_resource_declaration */
etisserant@0: SYM_LIST(task_configuration_list_c)
etisserant@0: 
etisserant@0: /* helper symbol for single_resource_declaration */
etisserant@0: SYM_LIST(program_configuration_list_c)
etisserant@0: 
etisserant@0: /* helper symbol for
etisserant@0:  *  - access_path
etisserant@0:  *  - instance_specific_init
etisserant@0:  */
etisserant@0: SYM_LIST(any_fb_name_list_c)
etisserant@0: 
etisserant@0: /*  [resource_name '.'] global_var_name ['.' structure_element_name] */
mario@69: SYM_REF3(global_var_reference_c, resource_name, global_var_name, structure_element_name)
etisserant@0: 
etisserant@0: /*  prev_declared_program_name '.' symbolic_variable */
etisserant@0: SYM_REF2(program_output_reference_c, program_name, symbolic_variable)
etisserant@0: 
etisserant@0: /*  TASK task_name task_initialization */
etisserant@0: SYM_REF2(task_configuration_c, task_name, task_initialization)
etisserant@0: 
etisserant@0: /*  '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */
mario@69: SYM_REF3(task_initialization_c, single_data_source, interval_data_source, priority_data_source)
etisserant@0: 
etisserant@0: /*  PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */
mario@69: SYM_REF5(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements)
etisserant@0: 
etisserant@0: /* prog_conf_elements ',' prog_conf_element */
etisserant@0: SYM_LIST(prog_conf_elements_c)
etisserant@0: 
etisserant@0: /*  fb_name WITH task_name */
etisserant@0: SYM_REF2(fb_task_c, fb_name, task_name)
etisserant@0: 
etisserant@0: /*  any_symbolic_variable ASSIGN prog_data_source */
etisserant@0: SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source)
etisserant@0: 
etisserant@0: /* any_symbolic_variable SENDTO data_sink */
lbessard@28: SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, data_sink)
etisserant@0: 
etisserant@0: /* VAR_CONFIG instance_specific_init_list END_VAR */
mario@69: SYM_REF1(instance_specific_initializations_c, instance_specific_init_list)
etisserant@0: 
etisserant@0: /* helper symbol for instance_specific_initializations */
etisserant@0: SYM_LIST(instance_specific_init_list_c)
etisserant@0: 
etisserant@0: /* resource_name '.' program_name '.' {fb_name '.'}
etisserant@0:     ((variable_name [location] ':' located_var_spec_init) | (fb_name ':' fb_initialization))
etisserant@0: */
etisserant@0: SYM_REF6(instance_specific_init_c, resource_name, program_name, any_fb_name_list, variable_name, location, initialization)
etisserant@0: 
etisserant@0: /* helper symbol for instance_specific_init */
etisserant@0: /* function_block_type_name ':=' structure_initialization */
etisserant@0: SYM_REF2(fb_initialization_c, function_block_type_name, structure_initialization)
etisserant@0: 
etisserant@0: 
etisserant@0: 
etisserant@0: /****************************************/
etisserant@0: /* B.2 - Language IL (Instruction List) */
etisserant@0: /****************************************/
etisserant@0: /***********************************/
etisserant@0: /* B 2.1 Instructions and Operands */
etisserant@0: /***********************************/
etisserant@0: /*| instruction_list il_instruction */
etisserant@0: SYM_LIST(instruction_list_c)
etisserant@0: 
etisserant@0: /* | label ':' [il_incomplete_instruction] eol_list */
etisserant@0: SYM_REF2(il_instruction_c, label, il_instruction)
etisserant@0: 
etisserant@0: 
etisserant@0: /* | il_simple_operator [il_operand] */
etisserant@0: SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand)
etisserant@0: 
etisserant@0: /* | function_name [il_operand_list] */
laurent@399: /* NOTE: The parameters 'called_function_declaration' and 'overloaded_return_type' are used to pass 
laurent@399:  *       data between the stage 3 and stage 4.
msousa@350:  *       See the comment above function_invocation_c for more details 
msousa@350:  */
laurent@399: SYM_REF2(il_function_call_c, function_name, il_operand_list, symbol_c *called_function_declaration; symbol_c *overloaded_return_type; int extensible_param_count;)
etisserant@0: 
etisserant@0: 
etisserant@0: /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
mario@69: SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list)
etisserant@0: 
etisserant@0: /*  il_jump_operator label */
etisserant@0: SYM_REF2(il_jump_operation_c, il_jump_operator, label)
etisserant@0: 
etisserant@0: /*   il_call_operator prev_declared_fb_name
etisserant@0:  * | il_call_operator prev_declared_fb_name '(' ')'
etisserant@0:  * | il_call_operator prev_declared_fb_name '(' eol_list ')'
etisserant@0:  * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
etisserant@0:  * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
etisserant@0:  */
etisserant@0: SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list)
etisserant@0: 
etisserant@0: 
etisserant@0: /* | function_name '(' eol_list [il_param_list] ')' */
laurent@399: /* NOTE: The parameters 'called_function_declaration' and 'overloaded_return_type' are used to pass 
laurent@399:  *       data between the stage 3 and stage 4.
msousa@350:  *       See the comment above function_invocation_c for more details 
msousa@350:  */
laurent@399: SYM_REF2(il_formal_funct_call_c, function_name, il_param_list, symbol_c *called_function_declaration; symbol_c *overloaded_return_type; int extensible_param_count;)
etisserant@0: 
etisserant@0: /* | il_operand_list ',' il_operand */
etisserant@0: SYM_LIST(il_operand_list_c)
etisserant@0: 
etisserant@0: /* | simple_instr_list il_simple_instruction */
etisserant@0: SYM_LIST(simple_instr_list_c)
etisserant@0: 
etisserant@0: /* | il_initial_param_list il_param_instruction */
etisserant@0: SYM_LIST(il_param_list_c)
etisserant@0: 
etisserant@0: /*  il_assign_operator il_operand
etisserant@0:  * | il_assign_operator '(' eol_list simple_instr_list ')'
etisserant@0:  */
mario@69: SYM_REF3(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list)
etisserant@0: 
etisserant@0: /*  il_assign_out_operator variable */
etisserant@0: SYM_REF2(il_param_out_assignment_c, il_assign_out_operator, variable)
etisserant@0: 
etisserant@0: 
etisserant@0: 
etisserant@0: /*******************/
etisserant@0: /* B 2.2 Operators */
etisserant@0: /*******************/
etisserant@0: SYM_REF0(LD_operator_c)
etisserant@0: SYM_REF0(LDN_operator_c)
etisserant@0: SYM_REF0(ST_operator_c)
etisserant@0: SYM_REF0(STN_operator_c)
etisserant@0: SYM_REF0(NOT_operator_c)
etisserant@0: SYM_REF0(S_operator_c)
etisserant@0: SYM_REF0(R_operator_c)
etisserant@0: SYM_REF0(S1_operator_c)
etisserant@0: SYM_REF0(R1_operator_c)
etisserant@0: SYM_REF0(CLK_operator_c)
etisserant@0: SYM_REF0(CU_operator_c)
etisserant@0: SYM_REF0(CD_operator_c)
etisserant@0: SYM_REF0(PV_operator_c)
etisserant@0: SYM_REF0(IN_operator_c)
etisserant@0: SYM_REF0(PT_operator_c)
etisserant@0: SYM_REF0(AND_operator_c)
etisserant@0: SYM_REF0(OR_operator_c)
etisserant@0: SYM_REF0(XOR_operator_c)
etisserant@0: SYM_REF0(ANDN_operator_c)
etisserant@0: SYM_REF0(ORN_operator_c)
etisserant@0: SYM_REF0(XORN_operator_c)
etisserant@0: SYM_REF0(ADD_operator_c)
etisserant@0: SYM_REF0(SUB_operator_c)
etisserant@0: SYM_REF0(MUL_operator_c)
etisserant@0: SYM_REF0(DIV_operator_c)
etisserant@0: SYM_REF0(MOD_operator_c)
etisserant@0: SYM_REF0(GT_operator_c)
etisserant@0: SYM_REF0(GE_operator_c)
etisserant@0: SYM_REF0(EQ_operator_c)
etisserant@0: SYM_REF0(LT_operator_c)
etisserant@0: SYM_REF0(LE_operator_c)
etisserant@0: SYM_REF0(NE_operator_c)
etisserant@0: SYM_REF0(CAL_operator_c)
etisserant@0: SYM_REF0(CALC_operator_c)
etisserant@0: SYM_REF0(CALCN_operator_c)
etisserant@0: SYM_REF0(RET_operator_c)
etisserant@0: SYM_REF0(RETC_operator_c)
etisserant@0: SYM_REF0(RETCN_operator_c)
etisserant@0: SYM_REF0(JMP_operator_c)
etisserant@0: SYM_REF0(JMPC_operator_c)
etisserant@0: SYM_REF0(JMPCN_operator_c)
etisserant@0: 
lbessard@143: /*  any_identifier ASSIGN */
lbessard@143: SYM_REF1(il_assign_operator_c, variable_name)
lbessard@143: 
etisserant@0: /*| [NOT] any_identifier SENDTO */
etisserant@0: SYM_REF2(il_assign_out_operator_c, option, variable_name)
etisserant@0: 
etisserant@0: 
etisserant@0: 
etisserant@0: /***************************************/
etisserant@0: /* B.3 - Language ST (Structured Text) */
etisserant@0: /***************************************/
etisserant@0: /***********************/
etisserant@0: /* B 3.1 - Expressions */
etisserant@0: /***********************/
etisserant@0: SYM_REF2(or_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(xor_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(and_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(equ_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(notequ_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(lt_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(gt_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(le_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(ge_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(add_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(sub_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(mul_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(div_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(mod_expression_c, l_exp, r_exp)
etisserant@0: SYM_REF2(power_expression_c, l_exp, r_exp)
mario@69: SYM_REF1(neg_expression_c, exp)
mario@69: SYM_REF1(not_expression_c, exp)
etisserant@0: 
ccb@202: /*    formal_param_list -> may be NULL ! */
ccb@202: /* nonformal_param_list -> may be NULL ! */
laurent@399: /* NOTE: The parameters 'called_function_declaration' and 'overloaded_return_type' are used to pass 
laurent@399:  *        data between the stage 3 and stage 4.
msousa@350:  *       The IEC 61131-3 standard allows for overloaded standard functions. This means that some
msousa@350:  *       function calls are not compeletely defined by the name of the function being called,
msousa@350:  *       and need to be disambiguated with using the data types of the parameters being passed.
msousa@350:  *       Stage 3 does this to verify semantic correctnes.
msousa@350:  *       Stage 4 also needs to do this in order to determine which function to call.
msousa@350:  *       It does not make sense to determine the exact function being called twice (once in stage 3,
msousa@350:  *       and again in stage 4), so stage 3 will store this infor in the parameter called_function_declaration
msousa@350:  *       for stage 4 to use it later on.
msousa@350:  */
laurent@399: SYM_REF3(function_invocation_c, function_name, formal_param_list, nonformal_param_list, symbol_c *called_function_declaration; symbol_c *overloaded_return_type; int extensible_param_count;)
etisserant@0: 
etisserant@0: 
etisserant@0: /********************/
etisserant@0: /* B 3.2 Statements */
etisserant@0: /********************/
etisserant@0: SYM_LIST(statement_list_c)
etisserant@0: 
etisserant@0: 
etisserant@0: /*********************************/
etisserant@0: /* B 3.2.1 Assignment Statements */
etisserant@0: /*********************************/
etisserant@0: SYM_REF2(assignment_statement_c, l_exp, r_exp)
etisserant@0: 
etisserant@0: 
etisserant@0: /*****************************************/
etisserant@0: /* B 3.2.2 Subprogram Control Statements */
etisserant@0: /*****************************************/
lbessard@143: 
etisserant@0: /*  RETURN */
etisserant@0: SYM_REF0(return_statement_c)
etisserant@0: 
etisserant@0: /* fb_name '(' [param_assignment_list] ')' */
ccb@202: /*    formal_param_list -> may be NULL ! */
ccb@202: /* nonformal_param_list -> may be NULL ! */
ccb@202: SYM_REF3(fb_invocation_c, fb_name, formal_param_list, nonformal_param_list)
etisserant@0: 
etisserant@0: /* helper symbol for fb_invocation */
etisserant@0: /* param_assignment_list ',' param_assignment */
etisserant@0: SYM_LIST(param_assignment_list_c)
etisserant@0: 
etisserant@0: /*  variable_name ASSIGN expression */
etisserant@0: SYM_REF2(input_variable_param_assignment_c, variable_name, expression)
etisserant@0: 
etisserant@0: /* [NOT] variable_name '=>' variable */
mario@69: SYM_REF3(output_variable_param_assignment_c, not_param, variable_name, variable)
etisserant@0: 
etisserant@0: /* helper CLASS for output_variable_param_assignment */
etisserant@0: SYM_REF0(not_paramassign_c)
etisserant@0: 
etisserant@0: 
etisserant@0: /********************************/
etisserant@0: /* B 3.2.3 Selection Statements */
etisserant@0: /********************************/
etisserant@0: /* IF expression THEN statement_list elseif_statement_list ELSE statement_list END_IF */
etisserant@0: SYM_REF4(if_statement_c, expression, statement_list, elseif_statement_list, else_statement_list)
etisserant@0: 
etisserant@0: /* helper symbol for if_statement */
etisserant@0: SYM_LIST(elseif_statement_list_c)
etisserant@0: 
etisserant@0: /* helper symbol for elseif_statement_list */
etisserant@0: /* ELSIF expression THEN statement_list    */
etisserant@0: SYM_REF2(elseif_statement_c, expression, statement_list)
etisserant@0: 
etisserant@0: /* CASE expression OF case_element_list ELSE statement_list END_CASE */
mario@69: SYM_REF3(case_statement_c, expression, case_element_list, statement_list)
etisserant@0: 
etisserant@0: /* helper symbol for case_statement */
etisserant@0: SYM_LIST(case_element_list_c)
etisserant@0: 
etisserant@0: /*  case_list ':' statement_list */
etisserant@0: SYM_REF2(case_element_c, case_list, statement_list)
etisserant@0: 
etisserant@0: SYM_LIST(case_list_c)
etisserant@0: 
etisserant@0: 
etisserant@0: /********************************/
etisserant@0: /* B 3.2.4 Iteration Statements */
etisserant@0: /********************************/
etisserant@0: /*  FOR control_variable ASSIGN expression TO expression [BY expression] DO statement_list END_FOR */
mario@69: SYM_REF5(for_statement_c, control_variable, beg_expression, end_expression, by_expression, statement_list)
etisserant@0: 
etisserant@0: /*  WHILE expression DO statement_list END_WHILE */
etisserant@0: SYM_REF2(while_statement_c, expression, statement_list)
etisserant@0: 
etisserant@0: /*  REPEAT statement_list UNTIL expression END_REPEAT */
etisserant@0: SYM_REF2(repeat_statement_c, statement_list, expression)
etisserant@0: 
etisserant@0: /*  EXIT */
etisserant@0: SYM_REF0(exit_statement_c)
etisserant@0: 
etisserant@0: 




