tests/syntax/identifier/identifier_as_function1.test
author Mario de Sousa <msousa@fe.up.pt>
Tue, 13 Mar 2012 12:39:09 +0000
changeset 477 c0c6ff7357b7
parent 108 f9e001952488
permissions -rwxr-xr-x
Clarify some details in the comments.
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 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 PT PV R R1 RET RETC RETCN S S1 ST STN XORN
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    19
#SFC_qualifiers #D #DS #L #N #P #R #S #SD #SL
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    20
#Task_initialisers #PRIORITY #SINGLE #INTERVAL
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    21
*)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    22
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    23
(* NOTE: The identifier as a function test has some special cases.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    24
 *       Namely, when using IL operators as function names.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    25
 *       For example, if a function LD has been previoulsy defined,
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    26
 *       The following IL code may be interpreted as either a 
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    27
 *       function call or an IL operation
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    28
 *         LD 10
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    29
 *       Due to undefined situations as the above, our 
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    30
 *       IEC compiler currently will always interpret IL operator identifiers.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    31
 *       inside IL code as an IL operator.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    32
 *       This means that calling, from IL code, of functions whose names
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    33
 *       coincide with an IL operator is not possible.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    34
 *
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    35
 *       The following test code must therefore consider two possibilities:
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    36
 *        - if the identifier under test is an IL operator
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    37
 *        - if the identifier under test is not an IL operator
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    38
 *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    39
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
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    71
(* Calling of the function from within IL code *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    72
(* NOTE: some legal identifiers, for ex. IL operators,
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    73
 * will not actually be interpreted as a reference to
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    74
 * the function, but rather as an IL operator.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    75
 * However, no error should occur, as the compiler is written
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    76
 * to give priority to interpreting it as an IL operator.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    77
 *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    78
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    79
(*
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    80
function bar000 : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    81
 var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    82
  e_1, f_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    83
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    84
  XXXX 10
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    85
  LD 20
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    86
  XXXX 30
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    87
  XXXX 10, 20
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
    a_1 := 20
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    91
   )
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    92
  XXXX(
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    93
    b_1 := 10,
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    94
    a_1 := 20
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
  XXXX (
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    97
    b_1 := 10
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    98
   )
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
    99
  XXXX(
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   100
    b_1 := 10
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
end_function
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   103
*)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   104
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   105
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   106
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   107
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   108
(* Checking whether the use of XXXX will confuse the logic 
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   109
 * 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
   110
 *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   111
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   112
(*
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   113
function bar001 : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   114
 var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   115
  e_1, f_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   116
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   117
  XXXX 10
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   118
end_function
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   119
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   120
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   121
function bar002 : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   122
 var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   123
  e_1, f_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   124
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   125
  XXXX 10, 20
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 bar003 : 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
function bar004 : int
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   141
 var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   142
  e_1, f_1 : int;
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   143
 end_var
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   144
  XXXX (
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   145
    b_1 := 10,
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   146
    a_1 := 20
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   147
   )
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   148
end_function
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   149
*)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   150
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   151
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   152
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   153
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   154
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   155
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   156
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   157
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   158
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   159
(* Checking whether the use of XXXX will confuse any other
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   160
 * normal and correct IL or ST code.
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   161
 *)
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   162
{#include "basic_code.test"}
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   163
f9e001952488 Regression tests. Test correct parsing of identifiers.
mario
parents:
diff changeset
   164