tests/syntax/identifier/identifier_as_function2.test
author Mario de Sousa <msousa@fe.up.pt>
Thu, 10 Jan 2013 10:47:06 +0000
changeset 792 78083edf93d5
parent 108 f9e001952488
permissions -rwxr-xr-x
disable not yet complete constant propagation algorithm (currently brocken and producing incorrect results),
108
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
     1
(* Test whether the keyword XXXX may be used as an identifier for:
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
     2
 * FUNCTION declaration
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
     3
 *
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
     4
 * The XXXX names in the following code are merely a placeholder.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
     5
 * They will be replaced by several identifiers before actual testing
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
     6
 * of the compiler.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
     7
 *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
     8
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
     9
(* The identifiers that will replace the XXXX
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    10
 * must be placed on a line starting with #
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    11
 * All identifiers preceded by # are ignored!
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    12
 * The identifier list must be placed inside an IEC 61131-3 comment.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    13
 *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    14
(* This file is specific for identifiers NOT identical to IL operators.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    15
 *  See the note following the identifier list
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    16
 *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    17
(*
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    18
#IL_operators #ANDN #CAL #CALC #CALCN #CD #CLK #CU #IN #JMP #JMPC #JMPCN #LD #LDN #ORN 
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    19
#IL_operators #PT #PV #R #R1 #RET #RETC #RETCN #S #S1 #ST #STN #XORN
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    20
     NOTE: R and S are identical to IL operators!!
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    21
#SFC_qualifiers D DS L N P #R #S SD SL   
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    22
#Task_initialisers PRIORITY SINGLE INTERVAL
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    23
*)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    24
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    25
(* NOTE: The identifier as a function test has some special cases.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    26
 *       Namely, when using IL operators as function names.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    27
 *       For example, if a function LD has been previoulsy defined,
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    28
 *       The following IL code may be interpreted as either a 
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    29
 *       function call or an IL operation
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    30
 *         LD 10
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    31
 *       Due to undefined situations as the above, our 
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    32
 *       IEC compiler currently will always interpret IL operator identifiers.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    33
 *       inside IL code as an IL operator.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    34
 *       This means that calling, from IL code, of functions whose names
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    35
 *       coincide with an IL operator is not possible.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    36
 *
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    37
 *       The following test code must therefore consider two possibilities:
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    38
 *        - if the identifier under test is an IL operator
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    39
 *        - if the identifier under test is not an IL operator
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    40
 *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    41
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    42
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    43
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    44
(* The FUNCTION declaration *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    45
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    46
function XXXX : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    47
 var_input
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    48
  a_1, b_1: int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    49
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    50
  XXXX := a_1 + b_1;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    51
end_function
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    52
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    53
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    54
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    55
(* Calling of the function from within ST code *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    56
function foo : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    57
 var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    58
  c_1, d_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    59
  e_1, f_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    60
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    61
  d_1 := XXXX(c_1, d_1);
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    62
  d_1 := XXXX(10, 20);
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    63
  c_1 := XXXX(20, 22);
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    64
  c_1 := XXXX(b_1 := e_1, a_1 := f_1);
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    65
  c_1 := XXXX (a_1 := e_1, b_1 := f_1);
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    66
end_function
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    67
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    68
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    69
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    70
(* Calling of the function from within IL code *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    71
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    72
function bar000 : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    73
 var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    74
  e_1, f_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    75
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    76
  XXXX 10
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    77
  LD 20
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    78
  XXXX 30
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    79
  XXXX 10, 20
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    80
  XXXX (
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    81
    b_1 := 10,
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    82
    a_1 := 20
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    83
   )
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    84
  XXXX(
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    85
    b_1 := 10,
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    86
    a_1 := 20
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    87
   )
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    88
  XXXX (
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    89
    b_1 := 10
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    90
   )
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    91
  XXXX(
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    92
    b_1 := 10
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    93
   )
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    94
end_function
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    95
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    96
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    97
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    98
(* Checking whether the use of XXXX will confuse the logic 
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    99
 * used to determine if a POU body is in IL or ST language.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   100
 *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   101
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   102
function bar001 : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   103
 var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   104
  e_1, f_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   105
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   106
  XXXX 10
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   107
end_function
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   108
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   109
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   110
function bar002 : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   111
 var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   112
  e_1, f_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   113
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   114
  XXXX 10, 20
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   115
end_function
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   116
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   117
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   118
function bar003 : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   119
 var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   120
  e_1, f_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   121
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   122
  XXXX(
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   123
    b_1 := 10,
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   124
    a_1 := 20
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   125
   )
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   126
end_function
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   127
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   128
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   129
function bar004 : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   130
 var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   131
  e_1, f_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   132
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   133
  XXXX (
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   134
    b_1 := 10,
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   135
    a_1 := 20
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   136
   )
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   137
end_function
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   138
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   139
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   140
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   141
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   142
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   143
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   144
(* Checking whether the use of XXXX will confuse any other
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   145
 * normal and correct IL or ST code.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   146
 *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   147
{#include "basic_code.test" }
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   148
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   149