stage1_2/iec_flex.ll
author mjsousa
Sun, 16 Feb 2014 14:29:31 +0000
changeset 869 d88f47549408
parent 868 23f271534a7c
child 870 9c6c588fd708
child 873 dea39ef02847
permissions -rw-r--r--
fix definition of pragma.
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     1
/*
264
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     3
 *
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     4
 *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     5
 *
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     6
 *  This program is free software: you can redistribute it and/or modify
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     7
 *  it under the terms of the GNU General Public License as published by
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
     8
 *  the Free Software Foundation, either version 3 of thest_whitespaceLicense, or
264
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     9
 *  (at your option) any later version.
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    10
 *
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    11
 *  This program is distributed in the hope that it will be useful,
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    14
 *  GNU General Public License for more details.
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    15
 *
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    16
 *  You should have received a copy of the GNU General Public License
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    18
 *
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    19
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    20
 * This code is made available on the understanding that it will not be
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    21
 * used in safety-critical situations without a full and competent review.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    22
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    23
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    24
/*
264
6facabd9c2cd Updating License info (with Edoaurd's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    25
 * An IEC 61131-3 compiler.
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    26
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    27
 * Based on the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    28
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    29
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    30
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    31
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    32
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    33
 * Stage 1
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    34
 * =======
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    35
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    36
 * This file contains the lexical tokens definitions, from which
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    37
 * the flex utility will generate a lexical parser function.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    38
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    39
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    40
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    41
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    42
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    43
/*****************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    44
/* Lexical Parser Options... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    45
/*****************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    46
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    47
/* The lexical analyser will never work in interactive mode,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    48
 * i.e., it will only process programs saved to files, and never
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    49
 * programs being written inter-actively by the user.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    50
 * This option saves the resulting parser from calling the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    51
 * isatty() function, that seems to be generating some compile
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    52
 * errors under some (older?) versions of flex.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    53
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    54
%option never-interactive
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    55
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    56
/* Have the lexical analyser use a 'char *yytext' instead of an
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    57
 * array of char 'char yytext[??]' to store the lexical token.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    58
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    59
%pointer
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    60
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    61
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    62
/* Have the lexical analyser ignore the case of letters.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    63
 * This will occur for all the tokens and keywords, but
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    64
 * the resulting text handed up to the syntax parser
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    65
 * will not be changed, and keep the original case
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    66
 * of the letters in the input file.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    67
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    68
%option case-insensitive
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    69
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    70
/* Have the generated lexical analyser keep track of the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    71
 * line number it is currently analysing.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    72
 * This is used to pass up to the syntax parser
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    73
 * the number of the line on which the current
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    74
 * token was found. It will enable the syntax parser
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    75
 * to generate more informatve error messages...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    76
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    77
%option yylineno
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    78
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    79
/* required for the use of the yy_pop_state() and
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    80
 * yy_push_state() functions
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    81
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    82
%option stack
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    83
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    84
/* The '%option stack' also requests the inclusion of 
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    85
 * the yy_top_state(), however this function is not
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    86
 * currently being used. This means that the compiler
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    87
 * is complaining about the existance of this function.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    88
 * The following option removes the yy_top_state()
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    89
 * function from the resulting c code, so the compiler 
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    90
 * no longer complains.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    91
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    92
%option noyy_top_state
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    93
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
    94
/* We will be using unput() in our flex code, so we cannot set the following option!... */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
    95
/*
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
    96
%option nounput
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
    97
*/
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
    98
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    99
/**************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   100
/* External Variable and Function declarations... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   101
/**************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   102
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   103
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   104
%{
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   105
/* Define TEST_MAIN to include a main() function.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   106
 * Useful for testing the parser generated by flex.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   107
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   108
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   109
#define TEST_MAIN
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   110
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   111
/* If lexical parser is compiled by itself, we need to define the following
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   112
 * constant to some string. Under normal circumstances LIBDIRECTORY is set
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   113
 * in the syntax parser header file...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   114
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   115
#ifdef TEST_MAIN
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents: 15
diff changeset
   116
#define DEFAULT_LIBDIR "just_testing"
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   117
#endif
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   118
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   119
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   120
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   121
/* Required for strdup() */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   122
#include <string.h>
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   123
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   124
/* Required only for the declaration of abstract syntax classes
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   125
 * (class symbol_c; class token_c; class list_c;)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   126
 * These will not be used in flex, but the token type union defined
354
0f24db96b519 Fixing automake configuration to work properly with flex and bison.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   127
 * in iec_bison.h contains pointers to these classes, so we must include
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   128
 * it here.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   129
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   130
#include "../absyntax/absyntax.hh"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   131
15
0b472e25eb16 Adding changes to make the compiler compatible with bison ver 2.3
mario
parents: 13
diff changeset
   132
354
0f24db96b519 Fixing automake configuration to work properly with flex and bison.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   133
/* iec_bison.h is generated by bison.
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   134
 * Contains the definition of the token constants, and the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   135
 * token value type YYSTYPE (in our case, a 'const char *')
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   136
 */
354
0f24db96b519 Fixing automake configuration to work properly with flex and bison.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   137
#include "iec_bison.h"
15
0b472e25eb16 Adding changes to make the compiler compatible with bison ver 2.3
mario
parents: 13
diff changeset
   138
#include "stage1_2_priv.hh"
0b472e25eb16 Adding changes to make the compiler compatible with bison ver 2.3
mario
parents: 13
diff changeset
   139
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   140
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   141
/* Variable defined by the bison parser,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   142
 * where the value of the tokens will be stored
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   143
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   144
extern YYSTYPE yylval;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   145
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   146
/* The name of the file currently being parsed...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   147
 * Note that flex accesses and updates this global variable
757
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   148
 * apropriately whenever it comes across an (*#include <filename> *) directive...
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   149
 */
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   150
const char *current_filename = NULL;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   151
15
0b472e25eb16 Adding changes to make the compiler compatible with bison ver 2.3
mario
parents: 13
diff changeset
   152
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   153
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   154
/* We will not be using unput() in our flex code... */
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   155
/* NOTE: it seems that this #define is no longer needed, It has been 
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   156
 * replaced by %option nounput.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   157
 * Should we simply delete it?
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   158
 * For now leave it in, in case someone is using an old version of flex.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   159
 * In any case, the most harm that can result in a warning message
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   160
 * when compiling iec.flex.c:
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   161
 * warning: ‘void yyunput(int, char*)’ defined but not used
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   162
 */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   163
#define YY_NO_UNPUT
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   164
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   165
/* Variable defined by the bison parser.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   166
 * It must be initialised with the location
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   167
 * of the token being parsed.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   168
 * This is only needed if we want to keep
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   169
 * track of the locations, in order to give
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   170
 * more meaningful error messages!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   171
 */
415
5c115720149c Fix YYLTYPE declaration.
Manuele Conti <conti.ma@alice.it>
parents: 354
diff changeset
   172
/*
5c115720149c Fix YYLTYPE declaration.
Manuele Conti <conti.ma@alice.it>
parents: 354
diff changeset
   173
 *extern YYLTYPE yylloc;
5c115720149c Fix YYLTYPE declaration.
Manuele Conti <conti.ma@alice.it>
parents: 354
diff changeset
   174
b*/
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
   175
#define YY_INPUT(buf,result,max_size)  {\
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
   176
    result = GetNextChar(buf, max_size);\
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
   177
    if (  result <= 0  )\
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
   178
      result = YY_NULL;\
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
   179
    }
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
   180
287
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   181
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   182
/* A counter to track the order by which each token is processed.
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   183
 * NOTE: This counter is not exactly linear (i.e., it does not get incremented by 1 for each token).
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   184
 *       i.e.. it may get incremented by more than one between two consecutive tokens.
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   185
 *       This is due to the fact that the counter gets incremented every 'user action' in flex,
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   186
 *       however not every user action will result in a token being passed to bison.
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   187
 *       Nevertheless this is still OK, as we are only interested in the relative
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   188
 *       ordering of tokens...
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   189
 */
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   190
static long int current_order = 0;
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   191
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   192
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   193
/* Macro that is executed for every action.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   194
 * We use it to pass the location of the token
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   195
 * back to the bison parser...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   196
 */
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
   197
#define YY_USER_ACTION {\
287
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   198
	yylloc.first_line = current_tracking->lineNumber;			\
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   199
	yylloc.first_column = current_tracking->currentTokenStart;		\
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   200
	yylloc.first_file = current_filename;					\
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   201
	yylloc.first_order = current_order;					\
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   202
	yylloc.last_line = current_tracking->lineNumber;			\
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   203
	yylloc.last_column = current_tracking->currentChar - 1;			\
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   204
	yylloc.last_file = current_filename;					\
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   205
	yylloc.last_order = current_order;					\
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   206
	current_tracking->currentTokenStart = current_tracking->currentChar;	\
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
   207
	current_order++;							\
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   208
	}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   209
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   210
/* Since this lexical parser we defined only works in ASCII based
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   211
 * systems, we might as well make sure it is being compiled on
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   212
 * one...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   213
 * Lets check a few random characters...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   214
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   215
#if (('a' != 0x61) || ('A' != 0x41) || ('z' != 0x7A) || ('Z' != 0x5A) || \
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   216
     ('0' != 0x30) || ('9' != 0x39) || ('(' != 0x28) || ('[' != 0x5B))
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   217
#error This lexical analyser is not portable to a non ASCII based system.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   218
#endif
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   219
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   220
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   221
/* Function only called from within flex, but defined
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   222
 * in iec.y!
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
   223
 * We declare it here...
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   224
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   225
 * Search for a symbol in either of the two symbol tables
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   226
 * and return the token id of the first symbol found.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   227
 * Searches first in the variables, and only if not found
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   228
 * does it continue searching in the library elements
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   229
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   230
//token_id_t get_identifier_token(const char *identifier_str);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   231
int get_identifier_token(const char *identifier_str);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   232
%}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   233
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   234
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   235
/***************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   236
/* Forward Declaration of functions defined later. */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   237
/***************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   238
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   239
%{
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   240
/* return all the text in the current token back to the input stream. */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   241
void unput_text(unsigned int n);
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   242
/* return all the text in the current token back to the input stream, 
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   243
 * but first return to the stream an additional character to mark the end of the token. 
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   244
 */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   245
void unput_and_mark(const char c);
756
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
   246
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
   247
void include_file(const char *include_filename);
757
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   248
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   249
int GetNextChar(char *b, int maxBuffer);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   250
%}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   251
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   252
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   253
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   254
/****************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   255
/* Lexical Parser States... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   256
/****************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   257
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   258
/* NOTE: Our psrser can parse st or il code, intermixed
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   259
 *       within the same file.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   260
 *       With IL we come across the issue of the EOL (end of line) token.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   261
 *       ST, and the declaration parts of IL do not use this token!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   262
 *       If the lexical analyser were to issue this token during ST
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   263
 *       language parsing, or during the declaration of data types,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   264
 *       function headers, etc. in IL, the syntax parser would crash.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   265
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   266
 *       We can solve this issue using one of three methods:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   267
 *        (1) Augment all the syntax that does not accept the EOL
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   268
 *            token to simply ignore it. This makes the syntax
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   269
 *            definition (in iec.y) very cluttered!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   270
 *        (2) Let the lexical parser figure out which language
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   271
 *            it is parsing, and decide whether or not to issue
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   272
 *            the EOL token. This requires the lexical parser
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   273
 *            to have knowledge of the syntax!, making for a poor
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   274
 *            overall organisation of the code. It would also make it
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   275
 *            very difficult to understand the lexical parser as it
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   276
 *            would use several states, and a state machine to transition
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   277
 *            between the states. The state transitions would be
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   278
 *            intermingled with the lexical parser defintion!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   279
 *        (3) Use a mixture of (1) and (2). The lexical analyser
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   280
 *            merely distinguishes between function headers and function
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   281
 *            bodies, but no longer makes a distinction between il and
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   282
 *            st language bodies. When parsing a body, it will return
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   283
 *            the EOL token. In other states '\n' will be ignored as
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   284
 *            whitespace.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   285
 *            The ST language syntax has been augmented in the syntax
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   286
 *            parser configuration to ignore any EOL tokens that it may
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   287
 *            come across!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   288
 *            This option has both drawbacks of option (1) and (2), but
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   289
 *            much less intensely.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   290
 *            The syntax that gets cluttered is limited to the ST statements
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   291
 *            (which is rather limited, compared to the function headers and
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   292
 *            data type declarations, etc...), while the state machine in
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   293
 *            the lexical parser becomes very simple. All state transitions
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   294
 *            can be handled within the lexical parser by itself, and can be
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   295
 *            easily identified. Thus knowledge of the syntax required by
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   296
 *            the lexical parser is very limited!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   297
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   298
 * Amazingly enough, I (Mario) got to implement option (3)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   299
 * at first, requiring two basic states, decl and body.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   300
 * The lexical parser will enter the body state when
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   301
 * it is parsing the body of a function/program/function block. The
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   302
 * state transition is done when we find a VAR_END that is not followed
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   303
 * by a VAR! This is the syntax knowledge that gets included in the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   304
 * lexical analyser with this option!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   305
 * Unfortunately, getting the st syntax parser to ignore EOL anywhere
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   306
 * where they might appear leads to conflicts. This is due to the fact
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   307
 * that the syntax parser uses the single look-ahead token to remove
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   308
 * possible conflicts. When we insert a possible EOL, the single
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   309
 * look ahead token becomes the EOL, which means the potential conflicts
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   310
 * could no longer be resolved.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   311
 * Removing these conflicts would make the st syntax parser very convoluted,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   312
 * and adding the extraneous EOL would make it very cluttered.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   313
 * This option was therefore dropped in favour of another!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   314
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   315
 * I ended up implementing (2). Unfortunately the lexical analyser can
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   316
 * not easily distinguish between il and st code, since function
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   317
 * calls in il are very similar to function block calls in st.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   318
 * We therefore use an extra 'body' state. When the lexical parser
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   319
 * finds that last END_VAR, it enters the body state. This state
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   320
 * must figure out what language is being parsed from the first few
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   321
 * tokens, and switch to the correct state (st, il or sfc) according to the
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   322
 * language. This means that we insert quite a bit of knowledge of the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   323
 * syntax of the languages into the lexical parser. This is ugly, but it
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   324
 * works, and at least it is possible to keep all the state changes together
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   325
 * to make it easier to remove them later on if need be.
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   326
 * Once the language being parsed has been identified, 
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   327
 * the body state returns any matched text back to the buffer with unput(),
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   328
 * to be later matched correctly by the apropriate language parser (st, il or sfc).
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   329
 *
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   330
 * Aditionally, in sfc state it may further recursively enter the body state
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   331
 * once again. This is because an sfc body may contain ACTIONS, which are then
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   332
 * written in one of the three languages (ST, IL or SFC), so once again we need
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   333
 * to figure out which language the ACTION in the SFC was written in. We already
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   334
 * ahve all that done in the body state, so we recursively transition to the body 
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   335
 * state once again.
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   336
 * Note that in this case, when coming out of the st/il state (whichever language
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   337
 * the action was written in) the sfc state will become active again. This is done by
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   338
 * pushing and poping the previously active state!
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   339
 *
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   340
 * The sfc_qualifier_state is required because when parsing actions within an
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   341
 * sfc, we will be expecting action qualifiers (N, P, R, S, DS, SD, ...). In order
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   342
 * to bison to work correctly, these qualifiers must be returned as tokens. However,
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   343
 * these tokens are not reserved keywords, which means it should be possible to
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   344
 * define variables/functions/FBs with any of these names (including 
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   345
 * S and R which are special because they are also IL operators). So, when we are not
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   346
 * expecting any action qualifiers, flex does not return these tokens, and is free
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   347
 * to interpret them as previously defined variables/functions/... as the case may be.
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   348
 *
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   349
 * The time_literal_state is required because TIME# literals are decomposed into 
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   350
 * portions, and wewant to send these portions one by one to bison. Each poertion will 
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   351
 * represent the value in days/hours/minutes/seconds/ms.
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   352
 * Unfortunately, some of these portions may also be lexically analysed as an identifier. So,
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   353
 * we need to disable lexical identification of identifiers while parsing TIME# literals!
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   354
 * e.g.:  TIME#55d_4h_56m
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   355
 *       We would like to return to bison the tokens 'TIME' '#' '55d' '_' '4h' '_' '56m'
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   356
 *       Unfortunately, flex will join '_' and '4h' to create a legal {identifier} '_4h',
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   357
 *       and return that identifier instead! So, we added this state!
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   358
 *
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   359
 * There is a main state machine...
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   360
 * 
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   361
 *       +---> INITIAL <-------> config
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   362
 *       |        \
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   363
 *       |        V
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   364
 *       |   header_state
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   365
 *       |        |
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   366
 *       |        V
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   367
 *     vardecl_list_state <------> var_decl
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   368
 *       ^        | 
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   369
 *       |        | [using push()]
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   370
 *       |        |
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   371
 *       |        V
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   372
 *       |       body, 
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   373
 *       |        |
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   374
 *       |        | 
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   375
 *       |   -------------------
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   376
 *       |   |       |         |
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   377
 *       |   v       v         v
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   378
 *       |  st      il        sfc
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   379
 *       |   |       |         |  [using pop() when leaving st/il/sfc => goes to vardecl_list_state]
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   380
 *       |   |       |         |
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   381
 *       -----------------------
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   382
 *
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   383
 * NOTE:- When inside sfc, and an action or transition in ST/IL is found, then 
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   384
 *        we also push() to the body state. This means that sometimes, when pop()ing
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   385
 *        from st and il, the state machine may return to the sfc state!
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   386
 *      - The transitions form sfc to body will be decided by bison, which will
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   387
 *        tell flex to do the transition by calling cmd_goto_body_state().
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   388
 *   
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   389
 * 
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   390
 * Possible state changes are:
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   391
 *   INITIAL -> goto(config_state)
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   392
 *                (when a CONFIGURATION is found)
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   393
 * 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   394
 *   INITIAL -> goto(header_state)
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   395
 *               (when a FUNCTION, FUNCTION_BLOCK, or PROGRAM is found)
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   396
 *   header_state -> goto(vardecl_list_state)
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   397
 *               (When the first VAR token is found, i.e. at begining of first VAR .. END_VAR declaration)
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   398
 * 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   399
 *  vardecl_list_state -> push current state (vardecl_list_state), and goto(vardecl_state) 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   400
 *                (when a VAR token is found)
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   401
 *   vardecl_state -> pop() to (vardecl_list_state) 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   402
 *                (when a END_VAR token is found)
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   403
 * 
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   404
 *   vardecl_list_state -> push current state (vardecl_list_state), and goto(body_state) 
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   405
 *                (when the last END_VAR is found!)
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   406
 *
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   407
 *   body_state    -> goto(sfc_state)
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   408
 *                     (when it figures out it is parsing sfc language)
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   409
 *   body_state    -> goto(st_state)
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   410
 *                     (when it figures out it is parsing st language)
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   411
 *   body_state    -> goto(il_state)
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   412
 *                     (when it figures out it is parsing il language)
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   413
 *   st_state      -> pop() to vardecl_list_state
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   414
 *                     (when a END_FUNCTION, END_FUNCTION_BLOCK, END_PROGRAM,
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   415
 *                      END_ACTION or END_TRANSITION is found)
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   416
 *   il_state      -> pop() to vardecl_list_state
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   417
 *                     (when a END_FUNCTION, END_FUNCTION_BLOCK, END_PROGRAM,
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   418
 *                      END_ACTION or END_TRANSITION is found)
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   419
 *   sfc_state     -> pop() to vardecl_list_state
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   420
 *                     (when a END_FUNCTION, END_FUNCTION_BLOCK, or END_PROGRAM is found)
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   421
 * 
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   422
 *   vardecl_list_state -> goto(INITIAL)
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   423
 *                     (when a END_FUNCTION, END_FUNCTION_BLOCK, or END_PROGRAM is found)
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   424
 *   config_state  -> goto(INITIAL)
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   425
 *                     (when a END_CONFIGURATION is found)
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   426
 * 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   427
 *  
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   428
 *   sfc_state     -> push current state(sfc_state); goto(body_state)
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   429
 *                     (when parsing an action. This transition is requested by bison)
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   430
 *   sfc_state     -> push current state(sfc_state); goto(sfc_qualifier_state)
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   431
 *                     (when expecting an action qualifier. This transition is requested by bison)
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   432
 *   sfc_qualifier_state -> pop() to sfc_state
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   433
 *                     (when no longer expecting an action qualifier. This transition is requested by bison)
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   434
 *
74
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   435
 *   config_state  -> push(config_state); goto(task_init_state)
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   436
 *                     (when parsing a task initialisation. This transition is requested by bison)
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   437
 *   task_init_state -> pop()
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   438
 *                     (when no longer parsing task initialisation parameters. This transition is requested by bison)
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   439
 *
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   440
 * 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   441
 * There is another secondary state machine for parsing comments, another for file_includes, 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   442
 * and yet another for time literals.
74
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   443
 */
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   444
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   445
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   446
/* we are parsing a configuration. */
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
   447
%s config_state
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   448
74
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   449
/* Inside a configuration, we are parsing a task initialisation parameters */
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   450
/* This means that PRIORITY, SINGLE and INTERVAL must be handled as
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   451
 * tokens, and not as possible identifiers. Note that the above words
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   452
 * are not keywords.
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   453
 */
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   454
%s task_init_state
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   455
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   456
/* we are looking for the first VAR inside a function's, program's or function block's declaration */
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   457
/* This is not exclusive (%x) as we must be able to parse the identifier and data types of a function/FB */
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   458
%s header_state
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   459
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   460
/* we are parsing a function, program or function block sequence of VAR..END_VAR delcarations */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   461
%x vardecl_list_state 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   462
/* a substate of the vardecl_list_state: we are inside a specific VAR .. END_VAR */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   463
%s vardecl_state
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   464
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   465
/* we will be parsing a function body/action/transition. Whether il/st/sfc remains to be determined */
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   466
%x body_state
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   467
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   468
/* we are parsing il code -> flex must return the EOL tokens!       */
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
   469
%s il_state
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   470
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   471
/* we are parsing st code -> flex must not return the EOL tokens!   */
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
   472
%s st_state
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   473
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   474
/* we are parsing sfc code -> flex must not return the EOL tokens!  */
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
   475
%s sfc_state
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   476
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   477
/* we are parsing sfc code, and expecting an action qualifier.      */
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   478
%s sfc_qualifier_state
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   479
86
1988bf1634da Adding support for use of PRIORITY as identifier inside SFC.
mario
parents: 84
diff changeset
   480
/* we are parsing sfc code, and expecting the priority token.       */
1988bf1634da Adding support for use of PRIORITY as identifier inside SFC.
mario
parents: 84
diff changeset
   481
%s sfc_priority_state
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   482
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   483
/* we are parsing a TIME# literal. We must not return any {identifier} tokens. */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   484
%x time_literal_state
75
0e381bdb8888 Fixing handling of task initialisation.
mario
parents: 74
diff changeset
   485
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   486
/* we are parsing a comment. */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   487
%x comment_state
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   488
75
0e381bdb8888 Fixing handling of task initialisation.
mario
parents: 74
diff changeset
   489
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   490
/*******************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   491
/* File #include's */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   492
/*******************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   493
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   494
/* We extend the IEC 61131-3 standard syntax to allow inclusion
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   495
 * of other files, using the IEC 61131-3 pragma directive...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   496
 * The accepted syntax is:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   497
 *  {#include "<filename>"}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   498
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   499
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   500
/* the "include" states are used for picking up the name of an include file */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   501
%x include_beg
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   502
%x include_filename
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   503
%x include_end
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   504
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   505
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   506
file_include_pragma_filename	[^\"]*
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   507
file_include_pragma_beg		"{#include"{st_whitespace}\"
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   508
file_include_pragma_end		\"{st_whitespace}"}"
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   509
file_include_pragma			{file_include_pragma_beg}{file_include_pragma_filename}{file_include_pragma_end}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   510
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   511
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   512
%{
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   513
#define MAX_INCLUDE_DEPTH 16
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   514
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   515
typedef struct {
757
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   516
    int eof;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   517
    int lineNumber;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   518
    int currentChar;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   519
    int lineLength;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   520
    int currentTokenStart;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   521
    char *buffer;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   522
    FILE *in_file;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   523
  } tracking_t;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   524
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   525
typedef struct {
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   526
	  YY_BUFFER_STATE buffer_state;
757
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   527
	  tracking_t *env;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   528
	  const char *filename;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   529
	} include_stack_t;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   530
757
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
   531
tracking_t *current_tracking = NULL;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   532
include_stack_t include_stack[MAX_INCLUDE_DEPTH];
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   533
int include_stack_ptr = 0;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   534
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   535
const char *INCLUDE_DIRECTORIES[] = {
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents: 15
diff changeset
   536
	DEFAULT_LIBDIR,
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents: 15
diff changeset
   537
	".",
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents: 15
diff changeset
   538
	"/lib",
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents: 15
diff changeset
   539
	"/usr/lib",
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents: 15
diff changeset
   540
	"/usr/lib/iec",
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   541
	NULL /* must end with NULL!! */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   542
	};
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   543
%}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   544
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   545
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   546
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   547
/*****************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   548
/* Prelimenary constructs... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   549
/*****************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   550
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   551
/* PRAGMAS */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   552
/* ======= */
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   553
/* In order to allow the declaration of POU prototypes (Function, FB, Program, ...),
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   554
 * especially the prototypes of Functions and FBs defined in the standard
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   555
 * (i.e. standard functions and FBs), we extend the IEC 61131-3 standard syntax 
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   556
 * with two pragmas to indicate that the code is to be parsed (going through the 
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   557
 * lexical, syntactical, and semantic analysers), but no code is to be generated.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   558
 * 
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   559
 * The accepted syntax is:
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   560
 *  {no_code_generation begin}
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   561
 *    ... prototypes ...
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   562
 *  {no_code_generation end}
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   563
 * 
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   564
 * When parsing these prototypes the abstract syntax tree will be populated as usual,
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   565
 * allowing the semantic analyser to correctly analyse the semantics of calls to these
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   566
 * functions/FBs. However, stage4 will simply ignore all IEC61131-3 code
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   567
 * between the above two pragmas.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   568
 */
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   569
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   570
disable_code_generation_pragma	"{disable code generation}"
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   571
enable_code_generation_pragma	"{enable code generation}"
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   572
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   573
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   574
/* Any other pragma... */
869
d88f47549408 fix definition of pragma.
mjsousa
parents: 868
diff changeset
   575
pragma ("{"[^}]*"}")|("{{"([^}]|"}"[^}])*"}}")
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   576
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   577
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   578
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   579
/* COMMENTS */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   580
/* ======== */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   581
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   582
/* In order to allow nested comments, comments are handled by a specific comment_state state */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   583
/* Whenever a "(*" is found, we push the current state onto the stack, and enter a new instance of the comment_state state.
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   584
 * Whenever a "*)" is found, we pop a state off the stack
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   585
 */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   586
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   587
/* comments... */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   588
comment_beg  "(*"
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   589
comment_end  "*)"
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   590
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   591
/* However, bison has a shift/reduce conflict in bison, when parsing formal function/FB
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   592
 * invocations with the 'NOT <variable_name> =>' syntax (which needs two look ahead 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   593
 * tokens to be parsed correctly - and bison being LALR(1) only supports one).
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   594
 * The current work around requires flex to completely parse the '<variable_name> =>'
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   595
 * sequence. This sequence includes whitespace and/or comments between the 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   596
 * <variable_name> and the "=>" token.
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   597
 * 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   598
 * This flex rule (sendto_identifier_token) uses the whitespace/comment as trailing context,
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   599
 * which means we can not use the comment_state method of specifying/finding and ignoring 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   600
 * comments.
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   601
 * 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   602
 * For this reason only, we must also define what a complete comment looks like, so
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   603
 * it may be used in this rule. Since the rule uses the whitespace_or_comment
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   604
 * construct as trailing context, this definition of comment must not use any
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   605
 * trailing context either.
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   606
 * 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   607
 * Aditionally, it is not possible to define nested comments in flex without the use of
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   608
 * states, so for this particular location, we do NOT support nested comments.
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   609
 */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   610
/* NOTE: this seemingly unnecessary complex definition is required
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   611
 *       to be able to eat up comments such as:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   612
 *          '(* Testing... ! ***** ******)'
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   613
 *       without using the trailing context command in flex (/{context})
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   614
 *       since {comment} itself will later be used with
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   615
 *       trailing context ({comment}/{context})
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   616
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   617
not_asterisk				[^*]
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   618
not_close_parenthesis_nor_asterisk	[^*)]
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   619
asterisk				"*"
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   620
comment_text	({not_asterisk})|(({asterisk}+){not_close_parenthesis_nor_asterisk})
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   621
comment		"(*"({comment_text}*)({asterisk}+)")"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   622
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   623
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   624
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   625
/* 3.1 Whitespace */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   626
/* ============== */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   627
/*
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   628
 * Whitespace is clearly defined (see IEC 61131-3 v2, section 2.1.4)
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   629
 * 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   630
 * Whitespace definition includes the newline character.
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   631
 * 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   632
 * However, the standard is inconsistent in that in IL the newline character 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   633
 * is considered a token (EOL - end of line). 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   634
 * In our implementation we therefore have two definitions of whitespace
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   635
 *   - one for ST, that includes the newline character
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   636
 *   - one for IL without the newline character.
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   637
 * Additionally, when parsing IL, the newline character is treated as the EOL token.
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   638
 * This requires the use of a state machine in the lexical parser that needs at least 
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   639
 * some knowledge of the syntax itself.
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   640
 *
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   641
 * NOTE: Our definition of whitespace will only work in ASCII!
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   642
 *
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   643
 * NOTE: we cannot use
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   644
 *         st_whitespace	[:space:]*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   645
 *       since we use {st_whitespace} as trailing context. In our case
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   646
 *       this would not constitute "dangerous trailing context", but the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   647
 *       lexical generator (i.e. flex) does not know this (since it does
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   648
 *       not know which characters belong to the set [:space:]), and will
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   649
 *       generate a "dangerous trailing context" warning!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   650
 *       We use this alternative just to stop the flex utility from
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   651
 *       generating the invalid (in this case) warning...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   652
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   653
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   654
st_whitespace			[ \f\n\r\t\v]*
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   655
il_whitespace			[ \f\r\t\v]*
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   656
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   657
st_whitespace_or_pragma_or_commentX	({st_whitespace})|({pragma})|({comment})
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   658
il_whitespace_or_pragma_or_commentX	({il_whitespace})|({pragma})|({comment})
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   659
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   660
st_whitespace_or_pragma_or_comment	{st_whitespace_or_pragma_or_commentX}*
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   661
il_whitespace_or_pragma_or_comment	{il_whitespace_or_pragma_or_commentX}*
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   662
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   663
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   664
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   665
qualified_identifier	{identifier}(\.{identifier})+
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   666
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   667
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   668
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   669
/*****************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   670
/* B.1.1 Letters, digits and identifiers */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   671
/*****************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   672
/* NOTE: The following definitions only work if the host computer
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   673
 *       is using the ASCII maping. For e.g., with EBCDIC [A-Z]
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   674
 *       contains non-alphabetic characters!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   675
 *       The correct way of doing it would be to use
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   676
 *       the [:upper:] etc... definitions.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   677
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   678
 *       Unfortunately, further on we need all printable
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   679
 *       characters (i.e. [:print:]), but excluding '$'.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   680
 *       Flex does not allow sets to be composed by excluding
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   681
 *       elements. Sets may only be constructed by adding new
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   682
 *       elements, which means that we have to revert to
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   683
 *       [\x20\x21\x23\x25\x26\x28-x7E] for the definition
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   684
 *       of the printable characters with the required exceptions.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   685
 *       The above also implies the use of ASCII, but now we have
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   686
 *       no way to work around it|
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   687
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   688
 *       The conclusion is that our parser is limited to ASCII
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   689
 *       based host computers!!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   690
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   691
letter		[A-Za-z]
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   692
digit		[0-9]
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   693
octal_digit	[0-7]
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   694
hex_digit	{digit}|[A-F]
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   695
identifier	({letter}|(_({letter}|{digit})))((_?({letter}|{digit}))*)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   696
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   697
/*******************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   698
/* B.1.2 Constants */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   699
/*******************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   700
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   701
/******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   702
/* B.1.2.1   Numeric literals */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   703
/******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   704
integer         {digit}((_?{digit})*)
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   705
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   706
/* Some helper symbols for parsing TIME literals... */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   707
integer_0_59    (0(_?))*([0-5](_?))?{digit}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   708
integer_0_19    (0(_?))*([0-1](_?))?{digit}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   709
integer_20_23   (0(_?))*2(_?)[0-3]
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   710
integer_0_23    {integer_0_19}|{integer_20_23}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   711
integer_0_999   {digit}((_?{digit})?)((_?{digit})?)
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   712
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   713
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   714
binary_integer  2#{bit}((_?{bit})*)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   715
bit		[0-1]
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   716
octal_integer   8#{octal_digit}((_?{octal_digit})*)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   717
hex_integer     16#{hex_digit}((_?{hex_digit})*)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   718
exponent        [Ee]([+-]?){integer}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   719
/* The correct definition for real would be:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   720
 * real		{integer}\.{integer}({exponent}?)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   721
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   722
 * Unfortunately, the spec also defines fixed_point (B 1.2.3.1) as:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   723
 * fixed_point		{integer}\.{integer}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   724
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   725
 * This means that {integer}\.{integer} could be interpreted
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   726
 * as either a fixed_point or a real.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   727
 * I have opted to interpret {integer}\.{integer} as a fixed_point.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   728
 * In order to do this, the definition of real has been changed to:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   729
 * real		{integer}\.{integer}{exponent}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   730
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   731
 * This means that the syntax parser now needs to define a real to be
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   732
 * either a real_token or a fixed_point_token!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   733
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   734
real		{integer}\.{integer}{exponent}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   735
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   736
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   737
/*******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   738
/* B.1.2.2   Character Strings */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   739
/*******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   740
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   741
common_character_representation :=
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   742
<any printable character except '$', '"' or "'">
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   743
|'$$'
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   744
|'$L'|'$N'|'$P'|'$R'|'$T'
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   745
|'$l'|'$n'|'$p'|'$r'|'$t'
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   746
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   747
NOTE: 	$ = 0x24
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   748
	" = 0x22
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   749
	' = 0x27
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   750
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   751
	printable chars in ASCII: 0x20-0x7E
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   752
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   753
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   754
esc_char_u		$L|$N|$P|$R|$T
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   755
esc_char_l		$l|$n|$p|$r|$t
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   756
esc_char		$$|{esc_char_u}|{esc_char_l}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   757
double_byte_char	(${hex_digit}{hex_digit}{hex_digit}{hex_digit})
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   758
single_byte_char	(${hex_digit}{hex_digit})
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   759
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   760
/* WARNING:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   761
 * This definition is only valid in ASCII...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   762
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   763
 * Flex includes the function print_char() that defines
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   764
 * all printable characters portably (i.e. whatever character
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   765
 * encoding is currently being used , ASCII, EBCDIC, etc...)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   766
 * Unfortunately, we cannot generate the definition of
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   767
 * common_character_representation portably, since flex
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   768
 * does not allow definition of sets by subtracting
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   769
 * elements in one set from another set.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   770
 * This means we must build up the defintion of
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   771
 * common_character_representation using only set addition,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   772
 * which leaves us with the only choice of defining the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   773
 * characters non-portably...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   774
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   775
common_character_representation		[\x20\x21\x23\x25\x26\x28-\x7E]|{esc_char}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   776
double_byte_character_representation 	$\"|'|{double_byte_char}|{common_character_representation}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   777
single_byte_character_representation 	$'|\"|{single_byte_char}|{common_character_representation}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   778
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   779
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   780
double_byte_character_string	\"({double_byte_character_representation}*)\"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   781
single_byte_character_string	'({single_byte_character_representation}*)'
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   782
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   783
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   784
/************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   785
/* B 1.2.3.1 - Duration */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   786
/************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   787
fixed_point		{integer}\.{integer}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   788
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   789
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   790
/* NOTE: The IEC 61131-3 v2 standard has an incorrect formal syntax definition of duration,
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   791
 *       as its definition does not match the standard's text.
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   792
 *       IEC 61131-3 v3 (committee draft) seems to have this fixed, so we use that
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   793
 *       definition instead!
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   794
 *
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   795
 *       duration::= ('T' | 'TIME') '#' ['+'|'-'] interval
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   796
 *       interval::= days | hours | minutes | seconds | milliseconds
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   797
 *       fixed_point  ::= integer [ '.' integer]
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   798
 *       days         ::= fixed_point 'd' | integer 'd' ['_'] [ hours ]
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   799
 *       hours        ::= fixed_point 'h' | integer 'h' ['_'] [ minutes ]
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   800
 *       minutes      ::= fixed_point 'm' | integer 'm' ['_'] [ seconds ]
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   801
 *       seconds      ::= fixed_point 's' | integer 's' ['_'] [ milliseconds ]
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   802
 *       milliseconds ::= fixed_point 'ms'
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   803
 * 
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   804
 * 
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   805
 *  The original IEC 61131-3 v2 definition is:
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   806
 *       duration ::= ('T' | 'TIME') '#' ['-'] interval
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   807
 *       interval ::= days | hours | minutes | seconds | milliseconds
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   808
 *       fixed_point  ::= integer [ '.' integer]
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   809
 *       days         ::= fixed_point 'd' | integer 'd' ['_'] hours
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   810
 *       hours        ::= fixed_point 'h' | integer 'h' ['_'] minutes
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   811
 *       minutes      ::= fixed_point 'm' | integer 'm' ['_'] seconds
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   812
 *       seconds      ::= fixed_point 's' | integer 's' ['_'] milliseconds
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   813
 *       milliseconds ::= fixed_point 'ms'
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   814
 */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   815
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   816
interval_ms_X		({integer_0_999}(\.{integer})?)ms
686
9b87606d4c07 Fix processing of TIME literals (submited by Andreas)
Mario de Sousa <msousa@fe.up.pt>
parents: 627
diff changeset
   817
interval_s_X		{integer_0_59}s(_?{interval_ms_X})?|({integer_0_59}(\.{integer})?s)
9b87606d4c07 Fix processing of TIME literals (submited by Andreas)
Mario de Sousa <msousa@fe.up.pt>
parents: 627
diff changeset
   818
interval_m_X		{integer_0_59}m(_?{interval_s_X})?|({integer_0_59}(\.{integer})?m)
9b87606d4c07 Fix processing of TIME literals (submited by Andreas)
Mario de Sousa <msousa@fe.up.pt>
parents: 627
diff changeset
   819
interval_h_X		{integer_0_23}h(_?{interval_m_X})?|({integer_0_23}(\.{integer})?h)
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   820
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   821
interval_ms		{integer}ms|({fixed_point}ms)
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   822
interval_s		{integer}s(_?{interval_ms_X})?|({fixed_point}s)
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   823
interval_m		{integer}m(_?{interval_s_X})?|({fixed_point}m)
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   824
interval_h		{integer}h(_?{interval_m_X})?|({fixed_point}h)
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   825
interval_d		{integer}d(_?{interval_h_X})?|({fixed_point}d)
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   826
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   827
interval		{interval_ms}|{interval_s}|{interval_m}|{interval_h}|{interval_d}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   828
686
9b87606d4c07 Fix processing of TIME literals (submited by Andreas)
Mario de Sousa <msousa@fe.up.pt>
parents: 627
diff changeset
   829
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   830
/* to help provide nice error messages, we also parse an incorrect but plausible interval... */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   831
/* NOTE that this erroneous interval will be parsed outside the time_literal_state, so must not 
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   832
 *      be able to parse any other legal lexcial construct (besides a legal interval, but that
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   833
 *      is OK as this rule will appear _after_ the rule to parse legal intervals!).
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   834
 */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   835
fixed_point_or_integer  {fixed_point}|{integer}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   836
erroneous_interval	({fixed_point_or_integer}d_?)?({fixed_point_or_integer}h_?)?({fixed_point_or_integer}m_?)?({fixed_point_or_integer}s_?)?({fixed_point_or_integer}ms)?
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   837
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   838
/********************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   839
/* B.1.4.1   Directly Represented Variables */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   840
/********************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   841
/* The correct definition, if the standard were to be followed... */
11
8ce37f36d744 Add support for correct syntax of direct variables.
mario
parents: 9
diff changeset
   842
8ce37f36d744 Add support for correct syntax of direct variables.
mario
parents: 9
diff changeset
   843
location_prefix			[IQM]
8ce37f36d744 Add support for correct syntax of direct variables.
mario
parents: 9
diff changeset
   844
size_prefix			[XBWDL]
8ce37f36d744 Add support for correct syntax of direct variables.
mario
parents: 9
diff changeset
   845
direct_variable_standard	%{location_prefix}({size_prefix}?){integer}((.{integer})*)
8ce37f36d744 Add support for correct syntax of direct variables.
mario
parents: 9
diff changeset
   846
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   847
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   848
/* For the MatPLC, we will accept %<identifier>
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   849
 * as a direct variable, this being mapped onto the MatPLC point
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   850
 * named <identifier>
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   851
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   852
/* TODO: we should not restrict it to only the accepted syntax
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   853
 * of <identifier> as specified by the standard. MatPLC point names
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   854
 * have a more permissive syntax.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   855
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   856
 * e.g. "P__234"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   857
 *    Is a valid MatPLC point name, but not a valid <identifier> !!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   858
 *    The same happens with names such as "333", "349+23", etc...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   859
 *    How can we handle these more expressive names in our case?
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   860
 *    Remember that some direct variable may remain anonymous, with
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   861
 *    declarations such as:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   862
 *    VAR
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   863
 *       AT %I3 : BYTE := 255;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   864
 *    END_VAR
11
8ce37f36d744 Add support for correct syntax of direct variables.
mario
parents: 9
diff changeset
   865
 *    in which case we are currently using "%I3" as the variable
8ce37f36d744 Add support for correct syntax of direct variables.
mario
parents: 9
diff changeset
   866
 *    name.
8ce37f36d744 Add support for correct syntax of direct variables.
mario
parents: 9
diff changeset
   867
 */
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   868
/* direct_variable_matplc		%{identifier} */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   869
/* direct_variable			{direct_variable_standard}|{direct_variable_matplc} */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
   870
direct_variable			{direct_variable_standard}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   871
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   872
/******************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   873
/* B 1.4.3 - Declaration & Initialisation */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   874
/******************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   875
incompl_location	%[IQM]\*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   876
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   877
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   878
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   879
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   880
%%
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   881
	/* fprintf(stderr, "flex: state %d\n", YY_START); */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   882
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   883
	/*****************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   884
	/*****************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   885
	/*****************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   886
	/*****                                           *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   887
	/*****                                           *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   888
	/*****   F I R S T    T H I N G S    F I R S T   *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   889
	/*****                                           *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   890
	/*****                                           *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   891
	/*****************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   892
	/*****************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   893
	/*****************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   894
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   895
	/***********************************************************/
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   896
	/* Handle requests sent by bison for flex to change state. */
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   897
	/***********************************************************/
13
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
   898
	if (get_goto_body_state()) {
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   899
	  yy_push_state(body_state);
13
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
   900
	  rst_goto_body_state();
6
94741aa26423 Changing from decl_state directly to sfc_state
mario
parents: 4
diff changeset
   901
	}
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
   902
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   903
	if (get_goto_sfc_qualifier_state()) {
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   904
	  yy_push_state(sfc_qualifier_state);
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   905
	  rst_goto_sfc_qualifier_state();
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   906
	}
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   907
86
1988bf1634da Adding support for use of PRIORITY as identifier inside SFC.
mario
parents: 84
diff changeset
   908
	if (get_goto_sfc_priority_state()) {
1988bf1634da Adding support for use of PRIORITY as identifier inside SFC.
mario
parents: 84
diff changeset
   909
	  yy_push_state(sfc_priority_state);
1988bf1634da Adding support for use of PRIORITY as identifier inside SFC.
mario
parents: 84
diff changeset
   910
	  rst_goto_sfc_priority_state();
1988bf1634da Adding support for use of PRIORITY as identifier inside SFC.
mario
parents: 84
diff changeset
   911
	}
1988bf1634da Adding support for use of PRIORITY as identifier inside SFC.
mario
parents: 84
diff changeset
   912
74
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   913
	if (get_goto_task_init_state()) {
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   914
	  yy_push_state(task_init_state);
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   915
	  rst_goto_task_init_state();
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   916
	}
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
   917
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   918
	if (get_pop_state()) {
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   919
	  yy_pop_state();
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   920
	  rst_pop_state();
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   921
	}
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   922
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   923
	/***************************/
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   924
	/* Handle the pragmas!     */
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   925
	/***************************/
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   926
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   927
	/* We start off by searching for the pragmas we handle in the lexical parser. */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   928
<INITIAL>{file_include_pragma}	unput_text(0); yy_push_state(include_beg);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   929
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   930
	/* Pragmas sent to syntax analyser (bison) */
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   931
{disable_code_generation_pragma}               return disable_code_generation_pragma_token;
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   932
{enable_code_generation_pragma}                return enable_code_generation_pragma_token;
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   933
<body_state,vardecl_list_state>{disable_code_generation_pragma}   return disable_code_generation_pragma_token;
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   934
<body_state,vardecl_list_state>{enable_code_generation_pragma}    return enable_code_generation_pragma_token;
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
   935
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   936
	/* Any other pragma we find, we just pass it up to the syntax parser...   */
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
   937
	/* Note that the <body_state> state is exclusive, so we have to include it here too. */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   938
{pragma}	{/* return the pragmma without the enclosing '{' and '}' */
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
   939
		 int cut = yytext[1]=='{'?2:1;
634
736b36a83548 Added double curly braces for pragma (kept single curly braces for compatibility). Added macro def and undef surrounding pragma to simplify user code. Moved useless comment from generated code back to code generator.
Edouard Tisserant
parents: 627
diff changeset
   940
		 yytext[strlen(yytext)-cut] = '\0';
736b36a83548 Added double curly braces for pragma (kept single curly braces for compatibility). Added macro def and undef surrounding pragma to simplify user code. Moved useless comment from generated code back to code generator.
Edouard Tisserant
parents: 627
diff changeset
   941
		 yylval.ID=strdup(yytext+cut);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   942
		 return pragma_token;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   943
		}
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   944
<body_state,vardecl_list_state>{pragma} {/* return the pragmma without the enclosing '{' and '}' */
701
562c01f82afb Fix pragma with double bracket token stripping
Laurent Bessard
parents: 637
diff changeset
   945
		 int cut = yytext[1]=='{'?2:1;
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
   946
		 yytext[strlen(yytext)-cut] = '\0';
701
562c01f82afb Fix pragma with double bracket token stripping
Laurent Bessard
parents: 637
diff changeset
   947
		 yylval.ID=strdup(yytext+cut);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   948
		 return pragma_token;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   949
		}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   950
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   951
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   952
	/*********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   953
	/* Handle the file includes!     */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   954
	/*********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   955
<include_beg>{file_include_pragma_beg}	BEGIN(include_filename);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   956
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   957
<include_filename>{file_include_pragma_filename}	{
756
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
   958
			  /* set the internal state variables of lexical analyser to process a new include file */
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
   959
			  include_file(yytext);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   960
			  /* switch to whatever state was active before the include file */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   961
			  yy_pop_state();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   962
			  /* now process the new file... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   963
			}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   964
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   965
761
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   966
<<EOF>>			{     /* NOTE: Currently bison is incorrectly using END_OF_INPUT in many rules
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   967
			       *       when checking for syntax errors in the input source code.
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   968
			       *       This means that in reality flex will be asked to carry on reading the input
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   969
			       *       even after it has reached the end of all (including the main) input files.
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   970
			       *       In other owrds, we will be called to return more tokens, even after we have
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   971
			       *       already returned an END_OF_INPUT token. In this case, we must carry on returning
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   972
			       *       more END_OF_INPUT tokens.
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   973
			       * 
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   974
			       *       However, in the above case we will be asked to carry on reading more tokens 
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   975
			       *       from the main input file, after we have reached the end. For this to work
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   976
			       *       correctly, we cannot close the main input file!
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   977
			       * 
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   978
			       *       This is why we WILL be called with include_stack_ptr == 0 multiple times,
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   979
			       *       and why we must handle it as a special case
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   980
			       *       that leaves the include_stack_ptr unchanged, and returns END_OF_INPUT once again.
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   981
			       * 
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   982
			       *       As a corollory, flex can never safely close the main input file, and we must ask
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   983
			       *       bison to close it!
76
ec7799ec929b fixing include bug (only ocured for includes in main program file).
mario
parents: 75
diff changeset
   984
			       */
ec7799ec929b fixing include bug (only ocured for includes in main program file).
mario
parents: 75
diff changeset
   985
			  if (include_stack_ptr == 0) {
761
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   986
			      // fclose(yyin);           // Must not do this!!
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   987
			      // free(current_tracking); // Must not do this!!
73
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
   988
			      /* yyterminate() terminates the scanner and returns a 0 to the 
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
   989
			       * scanner's  caller, indicating "all done".
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
   990
			       *	
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
   991
			       * Our syntax parser (written with bison) has the token	
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
   992
			       * END_OF_INPUT associated to the value 0, so even though
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
   993
			       * we don't explicitly return the token END_OF_INPUT
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
   994
			       * calling yyterminate() is equivalent to doing that. 
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
   995
			       */ 	
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   996
			    yyterminate();
737
f6bc5230aadd Fix comments and code alignment
Mario de Sousa <msousa@fe.up.pt>
parents: 686
diff changeset
   997
			  } else {
761
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   998
			    fclose(yyin);
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
   999
			    free(current_tracking);
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
  1000
			    --include_stack_ptr;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1001
			    yy_delete_buffer(YY_CURRENT_BUFFER);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1002
			    yy_switch_to_buffer((include_stack[include_stack_ptr]).buffer_state);
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
  1003
			    current_tracking = include_stack[include_stack_ptr].env;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1004
			      /* removing constness of char *. This is safe actually,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1005
			       * since the only real const char * that is stored on the stack is
1
5d893a68be6e Changes made since Mario visit at LOLITECH. Thanks again !
etisserant
parents: 0
diff changeset
  1006
			       * the first one (i.e. the one that gets stored in include_stack[0],
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1007
			       * which is never free'd!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1008
			       */
286
a4f4990d5c66 Adding tracking of filename in which token is located.
Mario de Sousa <msousa@fe.up.pt>
parents: 267
diff changeset
  1009
			    /* NOTE: We do __NOT__ free the malloc()'d memory since 
a4f4990d5c66 Adding tracking of filename in which token is located.
Mario de Sousa <msousa@fe.up.pt>
parents: 267
diff changeset
  1010
			     *       pointers to this filename will be kept by many objects
a4f4990d5c66 Adding tracking of filename in which token is located.
Mario de Sousa <msousa@fe.up.pt>
parents: 267
diff changeset
  1011
			     *       in the abstract syntax tree.
a4f4990d5c66 Adding tracking of filename in which token is located.
Mario de Sousa <msousa@fe.up.pt>
parents: 267
diff changeset
  1012
			     *       This will later be used to provide correct error
a4f4990d5c66 Adding tracking of filename in which token is located.
Mario de Sousa <msousa@fe.up.pt>
parents: 267
diff changeset
  1013
			     *       messages during semantic analysis (stage 3)
a4f4990d5c66 Adding tracking of filename in which token is located.
Mario de Sousa <msousa@fe.up.pt>
parents: 267
diff changeset
  1014
			     */
a4f4990d5c66 Adding tracking of filename in which token is located.
Mario de Sousa <msousa@fe.up.pt>
parents: 267
diff changeset
  1015
			    /* free((char *)current_filename); */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1016
			    current_filename = include_stack[include_stack_ptr].filename;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1017
			    yy_push_state(include_end);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1018
			  }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1019
			}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1020
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1021
<include_end>{file_include_pragma_end}	yy_pop_state();
756
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1022
	/* handle the artificial file includes created by include_string(), which do not end with a '}' */
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1023
<include_end>.				unput_text(0); yy_pop_state(); 
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1024
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1025
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1026
	/*********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1027
	/* Handle all the state changes! */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1028
	/*********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1029
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1030
	/* INITIAL -> header_state */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1031
<INITIAL>{
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1032
	/* NOTE: how about functions that do not declare variables, and go directly to the body_state???
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1033
	 *      - According to Section 2.5.1.3 (Function Declaration), item 2 in the list, a FUNCTION
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1034
	 *        must have at least one input argument, so a correct declaration will have at least
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1035
	 *        one VAR_INPUT ... VAR_END construct!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1036
	 *      - According to Section 2.5.2.2 (Function Block Declaration), a FUNCTION_BLOCK
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1037
	 *        must have at least one input argument, so a correct declaration will have at least
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1038
	 *        one VAR_INPUT ... VAR_END construct!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1039
	 *      - According to Section 2.5.3 (Programs), a PROGRAM must have at least one input
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1040
	 *        argument, so a correct declaration will have at least one VAR_INPUT ... VAR_END
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1041
	 *        construct!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1042
	 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1043
	 *       All the above means that we needn't worry about PROGRAMs, FUNCTIONs or
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1044
	 *       FUNCTION_BLOCKs that do not have at least one VAR_END before the body_state.
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1045
	 *       If the code has an error, and no VAR_END before the body, we will simply
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1046
	 *       continue in the <vardecl_state> state, untill the end of the FUNCTION, FUNCTION_BLOCK
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1047
	 *       or PROGAM.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1048
	 */
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1049
FUNCTION				yy_push_state(header_state); return FUNCTION;
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1050
FUNCTION_BLOCK				yy_push_state(header_state); return FUNCTION_BLOCK;
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1051
PROGRAM					yy_push_state(header_state); return PROGRAM;
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
  1052
CONFIGURATION				BEGIN(config_state); return CONFIGURATION;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1053
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1054
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1055
	/* INITIAL -> body_state */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1056
	/* required if the function, program, etc.. has no VAR block! */
6
94741aa26423 Changing from decl_state directly to sfc_state
mario
parents: 4
diff changeset
  1057
	/* We comment it out since the standard does not allow this.  */
94741aa26423 Changing from decl_state directly to sfc_state
mario
parents: 4
diff changeset
  1058
	/* NOTE: Even if we were to include the following code, it    */
94741aa26423 Changing from decl_state directly to sfc_state
mario
parents: 4
diff changeset
  1059
	/*       would have no effect whatsoever since the above      */
94741aa26423 Changing from decl_state directly to sfc_state
mario
parents: 4
diff changeset
  1060
	/*       rules will take precendence!                         */
94741aa26423 Changing from decl_state directly to sfc_state
mario
parents: 4
diff changeset
  1061
	/*
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1062
<INITIAL>{
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1063
FUNCTION	BEGIN(body_state); return FUNCTION;
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1064
FUNCTION_BLOCK	BEGIN(body_state); return FUNCTION_BLOCK;
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1065
PROGRAM		BEGIN(body_state); return PROGRAM;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1066
}
6
94741aa26423 Changing from decl_state directly to sfc_state
mario
parents: 4
diff changeset
  1067
	*/
94741aa26423 Changing from decl_state directly to sfc_state
mario
parents: 4
diff changeset
  1068
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1069
	/* header_state -> (vardecl_list_state) */
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1070
<header_state>{
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1071
VAR				| /* execute the next rule's action, i.e. fall-through! */
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1072
VAR_INPUT			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1073
VAR_OUTPUT			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1074
VAR_IN_OUT			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1075
VAR_EXTERNAL			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1076
VAR_GLOBAL			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1077
VAR_TEMP			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1078
VAR_CONFIG			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1079
VAR_ACCESS			unput_text(0); BEGIN(vardecl_list_state);
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1080
}
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1081
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1082
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1083
	/* vardecl_list_state -> (vardecl_state | body_state | INITIAL) */
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1084
<vardecl_list_state>{
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1085
VAR_INPUT			| /* execute the next rule's action, i.e. fall-through! */
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1086
VAR_OUTPUT			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1087
VAR_IN_OUT			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1088
VAR_EXTERNAL			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1089
VAR_GLOBAL			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1090
VAR_TEMP			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1091
VAR_CONFIG			|
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1092
VAR_ACCESS			|
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1093
VAR				unput_text(0); yy_push_state(vardecl_state);
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1094
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1095
END_FUNCTION			unput_text(0); BEGIN(INITIAL); 
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1096
END_FUNCTION_BLOCK		unput_text(0); BEGIN(INITIAL); 
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1097
END_PROGRAM			unput_text(0); BEGIN(INITIAL); 
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1098
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1099
.				unput_text(0); yy_push_state(body_state); /* anything else, just change to body_state! */
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1100
}
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1101
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1102
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1103
	/* vardecl_list_state -> pop to $previous_state (vardecl_list_state) */
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1104
<vardecl_state>{
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1105
END_VAR				yy_pop_state(); return END_VAR; /* pop back to header_state */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1106
}
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1107
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1108
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1109
	/* body_state -> (il_state | st_state | sfc_state) */
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1110
<body_state>{
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1111
INITIAL_STEP			unput_text(0); BEGIN(sfc_state); 
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1112
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1113
{qualified_identifier}		unput_text(0); BEGIN(st_state); /* will always be followed by '[' for an array access, or ':=' as the left hand of an assignment statement */
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1114
{direct_variable_standard}	unput_text(0); BEGIN(st_state); /* will always be followed by ':=' as the left hand of an assignment statement */
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1115
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1116
RETURN				unput_text(0); BEGIN(st_state);
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1117
IF				unput_text(0); BEGIN(st_state);
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1118
CASE				unput_text(0); BEGIN(st_state);
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1119
FOR				unput_text(0); BEGIN(st_state);
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1120
WHILE				unput_text(0); BEGIN(st_state);
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1121
EXIT				unput_text(0); BEGIN(st_state);
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1122
REPEAT				unput_text(0); BEGIN(st_state);
151
3b898fb11e73 Bug on language selection in SFC Action fixed
lbessard
parents: 136
diff changeset
  1123
6
94741aa26423 Changing from decl_state directly to sfc_state
mario
parents: 4
diff changeset
  1124
	/* ':=' occurs only in transitions, and not Function or FB bodies! */
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1125
:=				unput_text(0); BEGIN(st_state);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1126
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1127
{identifier}	{int token = get_identifier_token(yytext);
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1128
		 if ((token == prev_declared_fb_name_token) || (token == prev_declared_variable_name_token)) {
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1129
		   /* the code has a call to a function block OR has an assingment with a variable as the lvalue */
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1130
		   unput_text(0); BEGIN(st_state);
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1131
		 } else
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1132
 		 if (token == prev_declared_derived_function_name_token) {
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1133
		   /* the code has a call to a function - must be IL */
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1134
		   unput_text(0); BEGIN(il_state);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1135
		 } else {
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1136
		   /* Might be a lable in IL, or a bug in ST/IL code. We jump to IL */
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1137
		   unput_text(0); BEGIN(il_state);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1138
		 }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1139
		}
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1140
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1141
.		unput_text(0); BEGIN(il_state); /* Don't know what it could be. This is most likely a bug. Let's just to a random state... */
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1142
}	/* end of body_state lexical parser */
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
  1143
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1144
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1145
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1146
	/* (il_state | st_state) -> pop to $previous_state (vardecl_list_state or sfc_state) */
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
  1147
<il_state,st_state>{
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
  1148
END_FUNCTION		yy_pop_state(); unput_text(0);
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
  1149
END_FUNCTION_BLOCK	yy_pop_state(); unput_text(0);
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
  1150
END_PROGRAM		yy_pop_state(); unput_text(0);
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
  1151
END_TRANSITION		yy_pop_state(); unput_text(0);
6
94741aa26423 Changing from decl_state directly to sfc_state
mario
parents: 4
diff changeset
  1152
END_ACTION		yy_pop_state(); unput_text(0);
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
  1153
}
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
  1154
868
23f271534a7c Fix the state machine that became broken 2 commits ago (when adding support for nested comments)
mjsousa
parents: 867
diff changeset
  1155
	/* sfc_state -> pop to $previous_state (vardecl_list_state or sfc_state) */
4
0d71456312ab stack overflow problem corrected
lbessard
parents: 3
diff changeset
  1156
<sfc_state>{
0d71456312ab stack overflow problem corrected
lbessard
parents: 3
diff changeset
  1157
END_FUNCTION		yy_pop_state(); unput_text(0);
0d71456312ab stack overflow problem corrected
lbessard
parents: 3
diff changeset
  1158
END_FUNCTION_BLOCK	yy_pop_state(); unput_text(0);
0d71456312ab stack overflow problem corrected
lbessard
parents: 3
diff changeset
  1159
END_PROGRAM		yy_pop_state(); unput_text(0);
0d71456312ab stack overflow problem corrected
lbessard
parents: 3
diff changeset
  1160
}
0d71456312ab stack overflow problem corrected
lbessard
parents: 3
diff changeset
  1161
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1162
	/* config -> INITIAL */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1163
END_CONFIGURATION	BEGIN(INITIAL); return END_CONFIGURATION;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1164
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1165
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1166
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1167
	/***************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1168
	/* Next is to to remove all whitespace */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1169
	/***************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1170
	/* NOTE: pragmas are handled right at the beginning... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1171
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1172
	/* The whitespace */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1173
<INITIAL,header_state,config_state,body_state,vardecl_list_state,vardecl_state,st_state,sfc_state,task_init_state,sfc_qualifier_state>{st_whitespace}	/* Eat any whitespace */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1174
<il_state>{il_whitespace}		/* Eat any whitespace */
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1175
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1176
	/* The comments */
867
a435684a5223 Add option to control support for nested comments (default is off, as defined in IEC 61131-3 v2)
mjsousa
parents: 866
diff changeset
  1177
<body_state,vardecl_list_state>{comment_beg}		yy_push_state(comment_state);
a435684a5223 Add option to control support for nested comments (default is off, as defined in IEC 61131-3 v2)
mjsousa
parents: 866
diff changeset
  1178
{comment_beg}						yy_push_state(comment_state);
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1179
<comment_state>{
867
a435684a5223 Add option to control support for nested comments (default is off, as defined in IEC 61131-3 v2)
mjsousa
parents: 866
diff changeset
  1180
{comment_beg}						{if (get_opt_nested_comments()) yy_push_state(comment_state);}
a435684a5223 Add option to control support for nested comments (default is off, as defined in IEC 61131-3 v2)
mjsousa
parents: 866
diff changeset
  1181
{comment_end}						yy_pop_state();
a435684a5223 Add option to control support for nested comments (default is off, as defined in IEC 61131-3 v2)
mjsousa
parents: 866
diff changeset
  1182
.							/* Ignore text inside comment! */
a435684a5223 Add option to control support for nested comments (default is off, as defined in IEC 61131-3 v2)
mjsousa
parents: 866
diff changeset
  1183
\n							/* Ignore text inside comment! */
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1184
}
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 264
diff changeset
  1185
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1186
	/*****************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1187
	/* B.1.1 Letters, digits and identifiers */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1188
	/*****************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1189
	/* NOTE: 'R1', 'IN', etc... are IL operators, and therefore tokens
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1190
	 *       On the other hand, the spec does not define them as keywords,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1191
	 *       which means they may be re-used for variable names, etc...!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1192
	 *       The syntax parser already caters for the possibility of these
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1193
	 *       tokens being used for variable names in their declarations.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1194
	 *       When they are declared, they will be added to the variable symbol table!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1195
	 *       Further appearances of these tokens must no longer be parsed
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1196
	 *       as R1_tokens etc..., but rather as variable_name_tokens!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1197
	 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1198
	 *       That is why the first thing we do with identifiers, even before
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1199
	 *       checking whether they may be a 'keyword', is to check whether
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1200
	 *       they have been previously declared as a variable name,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1201
	 *
13
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1202
	 *       However, we have a dilema! Should we here also check for
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1203
	 *       prev_declared_derived_function_name_token?
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1204
	 *       If we do, then the 'MOD' default library function (defined in
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1205
	 *       the standard) will always be returned as a function name, and
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1206
	 *       it will therefore not be possible to use it as an operator as 
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1207
	 *       in the following ST expression 'X := Y MOD Z;' !
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1208
	 *       If we don't, then even it will not be possible to use 'MOD'
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1209
	 *       as a funtion as in 'X := MOD(Y, Z);'
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1210
	 *       We solve this by NOT testing for function names here, and
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1211
	 *       handling this function and keyword clash in bison!
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1212
	 */
83
aeb7e0e53855 commenting out code no longer required. To be deleted later.
mario
parents: 82
diff changeset
  1213
 /*
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1214
{identifier} 	{int token = get_identifier_token(yytext);
81
de518eb7bc74 removing debug messages left by mistake in previous commit.
mario
parents: 80
diff changeset
  1215
		 // fprintf(stderr, "flex: analysing identifier '%s'...", yytext); 
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1216
		 if ((token == prev_declared_variable_name_token) ||
13
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1217
//		     (token == prev_declared_derived_function_name_token) || // DO NOT add this condition!
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1218
		     (token == prev_declared_fb_name_token)) {
83
aeb7e0e53855 commenting out code no longer required. To be deleted later.
mario
parents: 82
diff changeset
  1219
		 // if (token != identifier_token)
aeb7e0e53855 commenting out code no longer required. To be deleted later.
mario
parents: 82
diff changeset
  1220
		 // * NOTE: if we replace the above uncommented conditions with
13
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1221
                  *       the simple test of (token != identifier_token), then 
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1222
                  *       'MOD' et al must be removed from the 
77174ccc5471 Many major changes to support SFC!
mario
parents: 11
diff changeset
  1223
                  *       library_symbol_table as a default function name!
83
aeb7e0e53855 commenting out code no longer required. To be deleted later.
mario
parents: 82
diff changeset
  1224
		  * //
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1225
		   yylval.ID=strdup(yytext);
81
de518eb7bc74 removing debug messages left by mistake in previous commit.
mario
parents: 80
diff changeset
  1226
		   // fprintf(stderr, "returning token %d\n", token); 
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1227
		   return token;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1228
		 }
83
aeb7e0e53855 commenting out code no longer required. To be deleted later.
mario
parents: 82
diff changeset
  1229
		 // otherwise, leave it for the other lexical parser rules... 
81
de518eb7bc74 removing debug messages left by mistake in previous commit.
mario
parents: 80
diff changeset
  1230
		 // fprintf(stderr, "rejecting\n"); 
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1231
		 REJECT;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1232
		}
83
aeb7e0e53855 commenting out code no longer required. To be deleted later.
mario
parents: 82
diff changeset
  1233
 */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1234
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1235
	/******************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1236
	/******************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1237
	/******************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1238
	/*****                                            *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1239
	/*****                                            *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1240
	/*****   N O W    D O   T H E   K E Y W O R D S   *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1241
	/*****                                            *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1242
	/*****                                            *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1243
	/******************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1244
	/******************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1245
	/******************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1246
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1247
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1248
EN	return EN;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1249
ENO	return ENO;			/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1250
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1251
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1252
	/******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1253
	/* B 1.2.1 - Numeric Literals */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1254
	/******************************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1255
TRUE		return TRUE;		/* Keyword */
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1256
BOOL#1  	return boolean_true_literal_token;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1257
BOOL#TRUE	return boolean_true_literal_token;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1258
SAFEBOOL#1	{if (get_opt_safe_extensions()) {return safeboolean_true_literal_token;} else{REJECT;}} /* Keyword (Data Type) */ 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1259
SAFEBOOL#TRUE	{if (get_opt_safe_extensions()) {return safeboolean_true_literal_token;} else{REJECT;}} /* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1260
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1261
FALSE		return FALSE;		/* Keyword */
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1262
BOOL#0  	return boolean_false_literal_token;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1263
BOOL#FALSE  	return boolean_false_literal_token;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1264
SAFEBOOL#0	{if (get_opt_safe_extensions()) {return safeboolean_false_literal_token;} else{REJECT;}} /* Keyword (Data Type) */ 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1265
SAFEBOOL#FALSE	{if (get_opt_safe_extensions()) {return safeboolean_false_literal_token;} else{REJECT;}} /* Keyword (Data Type) */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1266
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1267
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1268
	/************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1269
	/* B 1.2.3.1 - Duration */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1270
	/************************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1271
t#		return T_SHARP;		/* Delimiter */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1272
T#		return T_SHARP;		/* Delimiter */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1273
TIME		return TIME;		/* Keyword (Data Type) */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1274
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1275
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1276
	/************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1277
	/* B 1.2.3.2 - Time of day and Date */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1278
	/************************************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1279
TIME_OF_DAY	return TIME_OF_DAY;	/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1280
TOD		return TIME_OF_DAY;	/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1281
DATE		return DATE;		/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1282
d#		return D_SHARP;		/* Delimiter */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1283
D#		return D_SHARP;		/* Delimiter */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1284
DATE_AND_TIME	return DATE_AND_TIME;	/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1285
DT		return DATE_AND_TIME;	/* Keyword (Data Type) */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1286
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1287
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1288
	/***********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1289
	/* B 1.3.1 - Elementary Data Types */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1290
	/***********************************/
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1291
BOOL		return BOOL;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1292
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1293
BYTE		return BYTE;		/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1294
WORD		return WORD;		/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1295
DWORD		return DWORD;		/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1296
LWORD		return LWORD;		/* Keyword (Data Type) */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1297
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1298
SINT		return SINT;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1299
INT		return INT;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1300
DINT		return DINT;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1301
LINT		return LINT;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1302
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1303
USINT		return USINT;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1304
UINT		return UINT;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1305
UDINT		return UDINT;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1306
ULINT		return ULINT;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1307
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1308
REAL		return REAL;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1309
LREAL		return LREAL;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1310
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1311
WSTRING		return WSTRING;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1312
STRING		return STRING;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1313
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1314
TIME		return TIME;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1315
DATE		return DATE;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1316
DT		return DT;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1317
TOD		return TOD;		/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1318
DATE_AND_TIME	return DATE_AND_TIME;	/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1319
TIME_OF_DAY	return TIME_OF_DAY;	/* Keyword (Data Type) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1320
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1321
	/*****************************************************************/
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1322
	/* Keywords defined in "Safety Software Technical Specification" */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1323
	/*****************************************************************/
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1324
        /* 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1325
         * NOTE: The following keywords are define in 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1326
         *       "Safety Software Technical Specification,
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1327
         *        Part 1: Concepts and Function Blocks,  
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1328
         *        Version 1.0 – Official Release"
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1329
         *        written by PLCopen - Technical Committee 5
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1330
         *
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1331
         *        We only support these extensions and keywords
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1332
         *        if the apropriate command line option is given.
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1333
         */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1334
SAFEBOOL	     {if (get_opt_safe_extensions()) {return SAFEBOOL;}          else {REJECT;}} 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1335
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1336
SAFEBYTE	     {if (get_opt_safe_extensions()) {return SAFEBYTE;}          else {REJECT;}} 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1337
SAFEWORD	     {if (get_opt_safe_extensions()) {return SAFEWORD;}          else {REJECT;}} 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1338
SAFEDWORD	     {if (get_opt_safe_extensions()) {return SAFEDWORD;}         else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1339
SAFELWORD	     {if (get_opt_safe_extensions()) {return SAFELWORD;}         else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1340
               
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1341
SAFEREAL	     {if (get_opt_safe_extensions()) {return SAFESINT;}          else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1342
SAFELREAL    	     {if (get_opt_safe_extensions()) {return SAFELREAL;}         else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1343
                  
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1344
SAFESINT	     {if (get_opt_safe_extensions()) {return SAFESINT;}          else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1345
SAFEINT	             {if (get_opt_safe_extensions()) {return SAFEINT;}           else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1346
SAFEDINT	     {if (get_opt_safe_extensions()) {return SAFEDINT;}          else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1347
SAFELINT             {if (get_opt_safe_extensions()) {return SAFELINT;}          else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1348
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1349
SAFEUSINT            {if (get_opt_safe_extensions()) {return SAFEUSINT;}         else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1350
SAFEUINT             {if (get_opt_safe_extensions()) {return SAFEUINT;}          else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1351
SAFEUDINT            {if (get_opt_safe_extensions()) {return SAFEUDINT;}         else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1352
SAFEULINT            {if (get_opt_safe_extensions()) {return SAFEULINT;}         else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1353
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1354
 /* SAFESTRING and SAFEWSTRING are not yet supported, i.e. checked correctly, in the semantic analyser (stage 3) */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1355
 /*  so it is best not to support them at all... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1356
 /*
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1357
SAFEWSTRING          {if (get_opt_safe_extensions()) {return SAFEWSTRING;}       else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1358
SAFESTRING           {if (get_opt_safe_extensions()) {return SAFESTRING;}        else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1359
 */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1360
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1361
SAFETIME             {if (get_opt_safe_extensions()) {return SAFETIME;}          else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1362
SAFEDATE             {if (get_opt_safe_extensions()) {return SAFEDATE;}          else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1363
SAFEDT               {if (get_opt_safe_extensions()) {return SAFEDT;}            else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1364
SAFETOD              {if (get_opt_safe_extensions()) {return SAFETOD;}           else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1365
SAFEDATE_AND_TIME    {if (get_opt_safe_extensions()) {return SAFEDATE_AND_TIME;} else{REJECT;}}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1366
SAFETIME_OF_DAY      {if (get_opt_safe_extensions()) {return SAFETIME_OF_DAY;}   else{REJECT;}}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1367
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1368
	/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1369
	/* B 1.3.2 - Generic data types */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1370
	/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1371
	/* Strangely, the following symbols do not seem to be required! */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1372
	/* But we include them so they become reserved words, and do not
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1373
	 * get passed up to bison as an identifier...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1374
	 */
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1375
ANY		return ANY;		/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1376
ANY_DERIVED	return ANY_DERIVED;	/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1377
ANY_ELEMENTARY	return ANY_ELEMENTARY;	/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1378
ANY_MAGNITUDE	return ANY_MAGNITUDE;	/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1379
ANY_NUM		return ANY_NUM;		/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1380
ANY_REAL	return ANY_REAL;	/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1381
ANY_INT		return ANY_INT;		/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1382
ANY_BIT		return ANY_BIT;		/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1383
ANY_STRING	return ANY_STRING;	/* Keyword (Data Type) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1384
ANY_DATE	return ANY_DATE;	/* Keyword (Data Type) */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1385
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1386
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1387
	/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1388
	/* B 1.3.3 - Derived data types */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1389
	/********************************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1390
":="		return ASSIGN;		/* Delimiter */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1391
".."		return DOTDOT;		/* Delimiter */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1392
TYPE		return TYPE;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1393
END_TYPE	return END_TYPE;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1394
ARRAY		return ARRAY;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1395
OF		return OF;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1396
STRUCT		return STRUCT;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1397
END_STRUCT	return END_STRUCT;	/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1398
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1399
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1400
	/*********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1401
	/* B 1.4 - Variables */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1402
	/*********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1403
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1404
	/******************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1405
	/* B 1.4.3 - Declaration & Initialisation */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1406
	/******************************************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1407
VAR_INPUT	return VAR_INPUT;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1408
VAR_OUTPUT	return VAR_OUTPUT;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1409
VAR_IN_OUT	return VAR_IN_OUT;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1410
VAR_EXTERNAL	return VAR_EXTERNAL;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1411
VAR_GLOBAL	return VAR_GLOBAL;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1412
END_VAR		return END_VAR;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1413
RETAIN		return RETAIN;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1414
NON_RETAIN	return NON_RETAIN;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1415
R_EDGE		return R_EDGE;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1416
F_EDGE		return F_EDGE;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1417
AT		return AT;		/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1418
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1419
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1420
	/***********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1421
	/* B 1.5.1 - Functions */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1422
	/***********************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1423
FUNCTION	return FUNCTION;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1424
END_FUNCTION	return END_FUNCTION;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1425
VAR		return VAR;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1426
CONSTANT	return CONSTANT;	/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1427
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1428
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1429
	/*****************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1430
	/* B 1.5.2 - Function Blocks */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1431
	/*****************************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1432
FUNCTION_BLOCK		return FUNCTION_BLOCK;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1433
END_FUNCTION_BLOCK	return END_FUNCTION_BLOCK;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1434
VAR_TEMP		return VAR_TEMP;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1435
VAR			return VAR;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1436
NON_RETAIN		return NON_RETAIN;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1437
END_VAR			return END_VAR;			/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1438
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1439
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1440
	/**********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1441
	/* B 1.5.3 - Programs */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1442
	/**********************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1443
PROGRAM		return PROGRAM;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1444
END_PROGRAM	return END_PROGRAM;		/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1445
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1446
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1447
	/********************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1448
	/* B 1.6 Sequential Function Chart elements */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1449
	/********************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1450
	/* NOTE: the following identifiers/tokens clash with the R and S IL operators, as well
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1451
	.* as other identifiers that may be used as variable names inside IL and ST programs.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1452
	 * They will have to be handled when we include parsing of SFC... For now, simply
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1453
	 * ignore them!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1454
	 */
1
5d893a68be6e Changes made since Mario visit at LOLITECH. Thanks again !
etisserant
parents: 0
diff changeset
  1455
	 
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1456
ACTION		return ACTION;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1457
END_ACTION	return END_ACTION;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1458
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1459
TRANSITION	return TRANSITION;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1460
END_TRANSITION	return END_TRANSITION;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1461
FROM		return FROM;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1462
TO		return TO;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1463
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1464
INITIAL_STEP	return INITIAL_STEP;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1465
STEP		return STEP;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1466
END_STEP	return END_STEP;		/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1467
74
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1468
	/* PRIORITY is not a keyword, so we only return it when 
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1469
	 * it is explicitly required and we are not expecting any identifiers
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1470
	 * that could also use the same letter sequence (i.e. an identifier: piority)
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1471
	 */
86
1988bf1634da Adding support for use of PRIORITY as identifier inside SFC.
mario
parents: 84
diff changeset
  1472
<sfc_priority_state>PRIORITY	return PRIORITY;
74
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1473
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1474
<sfc_qualifier_state>{
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1475
L		return L;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1476
D		return D;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1477
SD		return SD;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1478
DS		return DS;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1479
SL		return SL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1480
N		return N;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1481
P		return P;
627
e7caa7d32ef5 Adding support for P0 and P1 qualifiers and fixing code generated for SL qualifier
Laurent Bessard
parents: 616
diff changeset
  1482
P0		return P0;
e7caa7d32ef5 Adding support for P0 and P1 qualifiers and fixing code generated for SL qualifier
Laurent Bessard
parents: 616
diff changeset
  1483
P1		return P1;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1484
R		return R;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1485
S		return S;
1
5d893a68be6e Changes made since Mario visit at LOLITECH. Thanks again !
etisserant
parents: 0
diff changeset
  1486
}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1487
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1488
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1489
	/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1490
	/* B 1.7 Configuration elements */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1491
	/********************************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1492
CONFIGURATION		return CONFIGURATION;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1493
END_CONFIGURATION	return END_CONFIGURATION;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1494
TASK			return TASK;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1495
RESOURCE		return RESOURCE;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1496
ON			return ON;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1497
END_RESOURCE		return END_RESOURCE;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1498
VAR_CONFIG		return VAR_CONFIG;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1499
VAR_ACCESS		return VAR_ACCESS;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1500
END_VAR			return END_VAR;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1501
WITH			return WITH;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1502
PROGRAM			return PROGRAM;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1503
RETAIN			return RETAIN;			/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1504
NON_RETAIN		return NON_RETAIN;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1505
READ_WRITE		return READ_WRITE;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1506
READ_ONLY		return READ_ONLY;		/* Keyword */
74
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1507
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1508
	/* PRIORITY, SINGLE and INTERVAL are not a keywords, so we only return them when 
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1509
	 * it is explicitly required and we are not expecting any identifiers
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1510
	 * that could also use the same letter sequence (i.e. an identifier: piority, ...)
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1511
	 */
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1512
<task_init_state>{
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1513
PRIORITY		return PRIORITY;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1514
SINGLE			return SINGLE;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1515
INTERVAL		return INTERVAL;
74
85af9521bf63 fixing identifier issues of PRIORITY, SINGLE, and INTERVAL
mario
parents: 73
diff changeset
  1516
}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1517
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1518
	/***********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1519
	/* B 2.1 Instructions and Operands */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1520
	/***********************************/
3
38850ee685e6 ST and IL parsing added into flex-bison analyser
lbessard
parents: 1
diff changeset
  1521
<il_state>\n		return EOL;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1522
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1523
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1524
	/*******************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1525
	/* B 2.2 Operators */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1526
	/*******************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1527
	/* NOTE: we can't have flex return the same token for
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1528
	 *       ANDN and &N, neither for AND and &, since
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1529
	 *       AND and ANDN are considered valid variable
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1530
	 *       function or functionblock type names!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1531
	 *       This means that the parser may decide that the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1532
	 *       AND or ANDN strings found in the source code
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1533
	 *       are being used as variable names
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1534
	 *       and not as operators, and will therefore transform
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1535
	 *       these tokens into indentifier tokens!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1536
	 *       We can't have the parser thinking that the source
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1537
	 *       code contained the string AND (which may be interpreted
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1538
	 *       as a vairable name) when in reality the source code
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1539
	 *       merely contained the character &, so we use two
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1540
	 *       different tokens for & and AND (and similarly
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1541
	 *       ANDN and &N)!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1542
	 */
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1543
 /* The following tokens clash with ST expression operators and Standard Functions */
73
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
  1544
 /* They are also keywords! */
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1545
AND		return AND;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1546
MOD		return MOD;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1547
OR		return OR;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1548
XOR		return XOR;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1549
NOT		return NOT;		/* Keyword */
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1550
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1551
 /* The following tokens clash with Standard Functions */
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1552
 /* They are keywords because they are a function name */
73
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
  1553
<il_state>{
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1554
ADD		return ADD;		/* Keyword (Standard Function) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1555
DIV		return DIV;		/* Keyword (Standard Function) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1556
EQ		return EQ;		/* Keyword (Standard Function) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1557
GE		return GE;		/* Keyword (Standard Function) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1558
GT		return GT;		/* Keyword (Standard Function) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1559
LE		return LE;		/* Keyword (Standard Function) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1560
LT		return LT;		/* Keyword (Standard Function) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1561
MUL		return MUL;		/* Keyword (Standard Function) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1562
NE		return NE;		/* Keyword (Standard Function) */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1563
SUB		return SUB;		/* Keyword (Standard Function) */
73
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
  1564
}
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1565
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1566
 /* The following tokens clash with SFC action qualifiers */
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1567
 /* They are not keywords! */
73
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
  1568
<il_state>{
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1569
S		return S;
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1570
R		return R;
73
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
  1571
}
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1572
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1573
 /* The following tokens clash with ST expression operators */
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1574
&		return AND2;		/* NOT a Delimiter! */
68
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1575
b0a43002dcac Adding basic error checking.
mario
parents: 58
diff changeset
  1576
 /* The following tokens have no clashes */
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1577
 /* They are not keywords! */
73
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
  1578
<il_state>{
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1579
LD		return LD;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1580
LDN		return LDN;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1581
ST		return ST;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1582
STN		return STN;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1583
S1		return S1;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1584
R1		return R1;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1585
CLK		return CLK;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1586
CU		return CU;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1587
CD		return CD;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1588
PV		return PV;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1589
IN		return IN;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1590
PT		return PT;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1591
ANDN		return ANDN;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1592
&N		return ANDN2;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1593
ORN		return ORN;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1594
XORN		return XORN;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1595
CAL		return CAL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1596
CALC		return CALC;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1597
CALCN		return CALCN;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1598
RET		return RET;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1599
RETC		return RETC;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1600
RETCN		return RETCN;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1601
JMP		return JMP;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1602
JMPC		return JMPC;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1603
JMPCN		return JMPCN;
73
0e623bbdee95 fixing infinite error loops at library level, and ...
mario
parents: 72
diff changeset
  1604
}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1605
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1606
	/***********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1607
	/* B 3.1 - Expressions */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1608
	/***********************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1609
"**"		return OPER_EXP;	/* NOT a Delimiter! */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1610
"<>"		return OPER_NE;		/* NOT a Delimiter! */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1611
">="		return OPER_GE;		/* NOT a Delimiter! */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1612
"<="		return OPER_LE;		/* NOT a Delimiter! */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1613
&		return AND2;		/* NOT a Delimiter! */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1614
AND		return AND;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1615
XOR		return XOR;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1616
OR		return OR;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1617
NOT		return NOT;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1618
MOD		return MOD;		/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1619
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1620
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1621
	/*****************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1622
	/* B 3.2.2 Subprogram Control Statements */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1623
	/*****************************************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1624
:=		return ASSIGN;		/* Delimiter */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1625
=>		return SENDTO;		/* Delimiter */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1626
RETURN		return RETURN;		/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1627
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1628
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1629
	/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1630
	/* B 3.2.3 Selection Statements */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1631
	/********************************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1632
IF		return IF;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1633
THEN		return THEN;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1634
ELSIF		return ELSIF;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1635
ELSE		return ELSE;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1636
END_IF		return END_IF;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1637
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1638
CASE		return CASE;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1639
OF		return OF;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1640
ELSE		return ELSE;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1641
END_CASE	return END_CASE;	/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1642
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1643
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1644
	/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1645
	/* B 3.2.4 Iteration Statements */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1646
	/********************************/
82
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1647
FOR		return FOR;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1648
TO		return TO;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1649
BY		return BY;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1650
DO		return DO;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1651
END_FOR		return END_FOR;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1652
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1653
WHILE		return WHILE;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1654
DO		return DO;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1655
END_WHILE	return END_WHILE;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1656
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1657
REPEAT		return REPEAT;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1658
UNTIL		return UNTIL;		/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1659
END_REPEAT	return END_REPEAT;	/* Keyword */
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1660
2b6e9eeeff2c Adding some comments.
mario
parents: 81
diff changeset
  1661
EXIT		return EXIT;		/* Keyword */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1662
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1663
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 177
diff changeset
  1664
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1665
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1666
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1667
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1668
	/********************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1669
	/********************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1670
	/********************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1671
	/*****                                              *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1672
	/*****                                              *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1673
	/*****  N O W    W O R K    W I T H    V A L U E S  *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1674
	/*****                                              *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1675
	/*****                                              *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1676
	/********************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1677
	/********************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1678
	/********************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1679
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1680
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1681
	/********************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1682
	/* B.1.4.1   Directly Represented Variables */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1683
	/********************************************/
175
dadda1b5401e Adding support for checking direct variable declared before using
lbessard
parents: 152
diff changeset
  1684
{direct_variable}   {yylval.ID=strdup(yytext); return get_direct_variable_token(yytext);}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1685
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1686
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1687
	/******************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1688
	/* B 1.4.3 - Declaration & Initialisation */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1689
	/******************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1690
{incompl_location}	{yylval.ID=strdup(yytext); return incompl_location_token;}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1691
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1692
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1693
	/************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1694
	/* B 1.2.3.1 - Duration */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1695
	/************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1696
{fixed_point}		{yylval.ID=strdup(yytext); return fixed_point_token;}
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1697
{interval}		{/*fprintf(stderr, "entering time_literal_state ##%s##\n", yytext);*/ unput_and_mark('#'); yy_push_state(time_literal_state);}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1698
{erroneous_interval}	{return erroneous_interval_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1699
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1700
<time_literal_state>{
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1701
{integer}d		{yylval.ID=strdup(yytext); yylval.ID[yyleng-1] = '\0'; return integer_d_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1702
{integer}h		{yylval.ID=strdup(yytext); yylval.ID[yyleng-1] = '\0'; return integer_h_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1703
{integer}m		{yylval.ID=strdup(yytext); yylval.ID[yyleng-1] = '\0'; return integer_m_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1704
{integer}s		{yylval.ID=strdup(yytext); yylval.ID[yyleng-1] = '\0'; return integer_s_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1705
{integer}ms		{yylval.ID=strdup(yytext); yylval.ID[yyleng-2] = '\0'; return integer_ms_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1706
{fixed_point}d		{yylval.ID=strdup(yytext); yylval.ID[yyleng-1] = '\0'; return fixed_point_d_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1707
{fixed_point}h		{yylval.ID=strdup(yytext); yylval.ID[yyleng-1] = '\0'; return fixed_point_h_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1708
{fixed_point}m		{yylval.ID=strdup(yytext); yylval.ID[yyleng-1] = '\0'; return fixed_point_m_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1709
{fixed_point}s		{yylval.ID=strdup(yytext); yylval.ID[yyleng-1] = '\0'; return fixed_point_s_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1710
{fixed_point}ms		{yylval.ID=strdup(yytext); yylval.ID[yyleng-2] = '\0'; return fixed_point_ms_token;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1711
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1712
_			/* do nothing - eat it up!*/
616
0c7663fdc8d3 Aloow use of SFC STEPs as variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 547
diff changeset
  1713
\#			{/*fprintf(stderr, "popping from time_literal_state (###)\n");*/ yy_pop_state(); return end_interval_token;}
0c7663fdc8d3 Aloow use of SFC STEPs as variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 547
diff changeset
  1714
.			{/*fprintf(stderr, "time_literal_state: found invalid character '%s'. Aborting!\n", yytext);*/ ERROR;}
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1715
\n			{ERROR;}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1716
}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1717
	/*******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1718
	/* B.1.2.2   Character Strings */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1719
	/*******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1720
{double_byte_character_string} {yylval.ID=strdup(yytext); return double_byte_character_string_token;}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1721
{single_byte_character_string} {yylval.ID=strdup(yytext); return single_byte_character_string_token;}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1722
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1723
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1724
	/******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1725
	/* B.1.2.1   Numeric literals */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1726
	/******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1727
{integer}		{yylval.ID=strdup(yytext); return integer_token;}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1728
{real}			{yylval.ID=strdup(yytext); return real_token;}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1729
{binary_integer}	{yylval.ID=strdup(yytext); return binary_integer_token;}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1730
{octal_integer} 	{yylval.ID=strdup(yytext); return octal_integer_token;}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1731
{hex_integer} 		{yylval.ID=strdup(yytext); return hex_integer_token;}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1732
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1733
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1734
	/*****************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1735
	/* B.1.1 Letters, digits and identifiers */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1736
	/*****************************************/
866
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1737
<st_state>{identifier}/({st_whitespace_or_pragma_or_comment})"=>"	{yylval.ID=strdup(yytext); return sendto_identifier_token;}
c8c48ab075e0 Add support for nested comments
mjsousa
parents: 793
diff changeset
  1738
<il_state>{identifier}/({il_whitespace_or_pragma_or_comment})"=>"	{yylval.ID=strdup(yytext); return sendto_identifier_token;}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1739
{identifier} 				{yylval.ID=strdup(yytext);
75
0e381bdb8888 Fixing handling of task initialisation.
mario
parents: 74
diff changeset
  1740
					 // printf("returning identifier...: %s, %d\n", yytext, get_identifier_token(yytext));
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1741
					 return get_identifier_token(yytext);}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1742
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1743
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1744
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1745
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1746
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1747
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1748
	/************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1749
	/************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1750
	/************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1751
	/*****                                      *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1752
	/*****                                      *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1753
	/*****   T H E    L E F T O V E R S . . .   *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1754
	/*****                                      *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1755
	/*****                                      *****/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1756
	/************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1757
	/************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1758
	/************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1759
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1760
	/* do the single character tokens...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1761
	 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1762
	 *  e.g.:  ':'  '('  ')'  '+'  '*'  ...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1763
	 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1764
.	{return yytext[0];}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1765
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1766
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1767
%%
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1768
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1769
757
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1770
/*************************/
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1771
/* Tracking Functions... */
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1772
/*************************/
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1773
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1774
#define MAX_BUFFER_LENGTH 1000
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1775
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1776
tracking_t *GetNewTracking(FILE* in_file) {
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1777
  tracking_t* new_env = new tracking_t;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1778
  new_env->eof = 0;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1779
  new_env->lineNumber = 0;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1780
  new_env->currentChar = 0;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1781
  new_env->lineLength = 0;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1782
  new_env->currentTokenStart = 0;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1783
  new_env->buffer = (char*)malloc(MAX_BUFFER_LENGTH);
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1784
  new_env->in_file = in_file;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1785
  return new_env;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1786
}
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1787
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1788
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1789
/* GetNextChar: reads a character from input */
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1790
int GetNextChar(char *b, int maxBuffer) {
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1791
  char *p;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1792
  
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1793
  if (  current_tracking->eof  )
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1794
    return 0;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1795
  
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1796
  while (  current_tracking->currentChar >= current_tracking->lineLength  ) {
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1797
    current_tracking->currentChar = 0;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1798
    current_tracking->currentTokenStart = 1;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1799
    current_tracking->eof = false;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1800
    
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1801
    p = fgets(current_tracking->buffer, MAX_BUFFER_LENGTH, current_tracking->in_file);
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1802
    if (  p == NULL  ) {
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1803
      if (  ferror(current_tracking->in_file)  )
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1804
        return 0;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1805
      current_tracking->eof = true;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1806
      return 0;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1807
    }
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1808
    
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1809
    current_tracking->lineNumber++;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1810
    current_tracking->lineLength = strlen(current_tracking->buffer);
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1811
  }
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1812
  
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1813
  b[0] = current_tracking->buffer[current_tracking->currentChar];
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1814
  if (b[0] == ' ' || b[0] == '\t')
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1815
    current_tracking->currentTokenStart++;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1816
  current_tracking->currentChar++;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1817
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1818
  return b[0]==0?0:1;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1819
}
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1820
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1821
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1822
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1823
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1824
/***********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1825
/* Utility function definitions... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1826
/***********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1827
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1828
/* print the include file stack to stderr... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1829
void print_include_stack(void) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1830
  int i;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1831
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1832
  if ((include_stack_ptr - 1) >= 0)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1833
    fprintf (stderr, "in file "); 
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1834
  for (i = include_stack_ptr - 1; i >= 0; i--)
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
  1835
    fprintf (stderr, "included from file %s:%d\n", include_stack[i].filename, include_stack[i].env->lineNumber);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1836
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1837
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1838
756
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1839
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1840
/* set the internal state variables of lexical analyser to process a new include file */
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1841
void handle_include_file_(FILE *filehandle, const char *filename) {
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1842
  if (include_stack_ptr >= MAX_INCLUDE_DEPTH) {
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1843
    fprintf(stderr, "Includes nested too deeply\n");
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1844
    exit( 1 );
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1845
  }
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1846
  
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1847
  yyin = filehandle;
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1848
  
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1849
  include_stack[include_stack_ptr].buffer_state = YY_CURRENT_BUFFER;
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1850
  include_stack[include_stack_ptr].env = current_tracking;
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1851
  include_stack[include_stack_ptr].filename = current_filename;
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1852
  
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1853
  current_filename = strdup(filename);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1854
  current_tracking = GetNewTracking(yyin);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1855
  include_stack_ptr++;
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1856
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1857
  /* switch input buffer to new file... */
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1858
  yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1859
}
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1860
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1861
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1862
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1863
/* insert the code (in <source_code>) into the source code we are parsing.
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1864
 * This is done by creating an artificial file with that new source code, and then 'including' the file
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1865
 */
757
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1866
void include_string_(const char *source_code) {
756
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1867
  FILE *tmp_file = tmpfile();
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1868
  
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1869
  if(tmp_file == NULL) {
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1870
    perror("Error creating temp file.");
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1871
    exit(EXIT_FAILURE);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1872
  }
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1873
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1874
  fwrite((void *)source_code, 1, strlen(source_code), tmp_file);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1875
  rewind(tmp_file);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1876
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1877
  /* now parse the tmp file, by asking flex to handle it as if it had been included with the (*#include ... *) pragma... */
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1878
  handle_include_file_(tmp_file, "");
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1879
//fclose(tmp_file);  /* do NOT close file. It must only be closed when we finish reading from it! */
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1880
}
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1881
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1882
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1883
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1884
/* Open an include file, and set the internal state variables of lexical analyser to process a new include file */
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1885
void include_file(const char *filename) {
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1886
  FILE *filehandle = NULL;
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1887
  
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1888
  for (int i = 0; (INCLUDE_DIRECTORIES[i] != NULL) && (filehandle == NULL); i++) {
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1889
    char *full_name;
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1890
    full_name = strdup3(INCLUDE_DIRECTORIES[i], "/", filename);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1891
    if (full_name == NULL) {
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1892
      fprintf(stderr, "Out of memory!\n");
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1893
      exit( 1 );
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1894
    }
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1895
    filehandle = fopen(full_name, "r");
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1896
    free(full_name);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1897
  }
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1898
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1899
  if (NULL == filehandle) {
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1900
    fprintf(stderr, "Error opening included file %s\n", filename);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1901
    exit( 1 );
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1902
  }
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1903
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1904
  /* now process the new file... */
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1905
  handle_include_file_(filehandle, filename);
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1906
}
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1907
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1908
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1909
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1910
634f476cb60f Insert the auto generated enum datatype conversion functions after the TYPE...END_TYPE, instead of at the end of input file.
Mario de Sousa <msousa@fe.up.pt>
parents: 737
diff changeset
  1911
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1912
/* return all the text in the current token back to the input stream, except the first n chars. */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1913
void unput_text(unsigned int n) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1914
  /* it seems that flex has a bug in that it will not correctly count the line numbers
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1915
   * if we return newlines back to the input stream. These newlines will be re-counted
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1916
   * a second time when they are processed again by flex.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1917
   * We therefore determine how many newlines are in the text we are returning,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1918
   * and decrement the line counter acordingly...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1919
   */
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
  1920
  /*unsigned int i;
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
  1921
  
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1922
  for (i = n; i < strlen(yytext); i++)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1923
    if (yytext[i] == '\n')
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
  1924
      current_tracking->lineNumber--;*/
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1925
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1926
  /* now return all the text back to the input stream... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1927
  yyless(n);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1928
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1929
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1930
547
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1931
/* return all the text in the current token back to the input stream, 
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1932
 * but first return to the stream an additional character to mark the end of the token. 
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1933
 */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1934
void unput_and_mark(const char c) {
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1935
  char *yycopy = strdup( yytext ); /* unput() destroys yytext, so we copy it first */
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1936
  unput(c);
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1937
  for (int i = yyleng-1; i >= 0; i--)
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1938
    unput(yycopy[i]);
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1939
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1940
  free(yycopy);
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1941
}
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1942
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1943
dab341e80664 Fix parsing os TIME literals & rename the extract_integer() function.
mjsousa <msousa@fe.up.pt>
parents: 415
diff changeset
  1944
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1945
/* Called by flex when it reaches the end-of-file */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1946
int yywrap(void)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1947
{
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1948
  /* We reached the end of the input file... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1949
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1950
  /* Should we continue with another file? */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1951
  /* If so:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1952
   *   open the new file...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1953
   *   return 0;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1954
   */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1955
737
f6bc5230aadd Fix comments and code alignment
Mario de Sousa <msousa@fe.up.pt>
parents: 686
diff changeset
  1956
  /* to stop processing...
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1957
   *   return 1;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1958
   */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1959
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1960
  return 1;  /* Stop scanning at end of input file. */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1961
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1962
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1963
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1964
757
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1965
/*******************************/
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1966
/* Public Interface for Bison. */
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1967
/*******************************/
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1968
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1969
/* The following functions will be called from inside bison code! */
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1970
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1971
void include_string(const char *source_code) {include_string_(source_code);}
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1972
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1973
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1974
/* Tell flex which file to parse. This function will not imediately start parsing the file.
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1975
 * To parse the file, you then need to call yyparse()
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1976
 *
761
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
  1977
 * Returns NULL on error opening the file (and a valid errno), or 0 on success.
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
  1978
 * Caller must close the file!
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
  1979
 */
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
  1980
FILE *parse_file(const char *filename) {
757
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1981
  FILE *filehandle = NULL;
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1982
761
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
  1983
  if((filehandle = fopen(filename, "r")) != NULL) {
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
  1984
    yyin = filehandle;
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
  1985
    current_filename = strdup(filename);
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
  1986
    current_tracking = GetNewTracking(yyin);
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
  1987
  }
7b52623a2f37 Allow bison to ask for an END_OF_INPUT token multiple times!
mjsousa
parents: 757
diff changeset
  1988
  return filehandle;
757
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1989
}
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1990
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1991
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1992
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1993
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1994
f1fc4aa6f0e3 Code cleanup: move tracking functions to flex.
Mario de Sousa <msousa@fe.up.pt>
parents: 756
diff changeset
  1995
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1996
/*************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1997
/* Include a main() function to test */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1998
/* the token parsing by flex....     */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1999
/*************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2000
#ifdef TEST_MAIN
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2001
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2002
#include "../util/symtable.hh"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2003
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2004
yystype yylval;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2005
YYLTYPE yylloc;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2006
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2007
15
0b472e25eb16 Adding changes to make the compiler compatible with bison ver 2.3
mario
parents: 13
diff changeset
  2008
0b472e25eb16 Adding changes to make the compiler compatible with bison ver 2.3
mario
parents: 13
diff changeset
  2009
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2010
int get_identifier_token(const char *identifier_str) {return 0;}
175
dadda1b5401e Adding support for checking direct variable declared before using
lbessard
parents: 152
diff changeset
  2011
int get_direct_variable_token(const char *direct_variable_str) {return 0;}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2012
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2013
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2014
int main(int argc, char **argv) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2015
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2016
  FILE *in_file;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2017
  int res;
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
  2018
	
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2019
  if (argc == 1) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2020
    /* Work as an interactive (command line) parser... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2021
    while((res=yylex()))
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2022
      fprintf(stderr, "(line %d)token: %d\n", yylineno, res);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2023
  } else {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2024
    /* Work as non-interactive (file) parser... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2025
    if((in_file = fopen(argv[1], "r")) == NULL) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2026
      char *errmsg = strdup2("Error opening main file ", argv[1]);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2027
      perror(errmsg);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2028
      free(errmsg);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2029
      return -1;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2030
    }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2031
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2032
    /* parse the file... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2033
    yyin = in_file;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2034
    current_filename = argv[1];
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2035
    while(1) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2036
      res=yylex();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2037
      fprintf(stderr, "(line %d)token: %d (%s)\n", yylineno, res, yylval.ID);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2038
    }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2039
  }
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
  2040
	
32bd7ef40897 Adding some improvements:
lbessard
parents: 131
diff changeset
  2041
	return 0;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2042
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2043
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  2044
#endif