|
1 /* |
|
2 * (c) 2007 Mario de Sousa |
|
3 * |
|
4 * Offered to the public under the terms of the GNU General Public License |
|
5 * as published by the Free Software Foundation; either version 2 of the |
|
6 * License, or (at your option) any later version. |
|
7 * |
|
8 * This program is distributed in the hope that it will be useful, but |
|
9 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 * Public License for more details. |
|
12 * |
|
13 * This code is made available on the understanding that it will not be |
|
14 * used in safety-critical situations without a full and competent review. |
|
15 */ |
|
16 |
|
17 /* |
|
18 * An IEC 61131-3 IL and ST compiler. |
|
19 * |
|
20 * Based on the |
|
21 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 * |
|
23 */ |
|
24 |
|
25 |
|
26 /* |
|
27 * The private interface to stage1_2.cc |
|
28 */ |
|
29 |
|
30 |
|
31 |
|
32 /* file with the declarations of symbol tables... */ |
|
33 #include "../util/symtable.hh" |
|
34 |
|
35 |
|
36 |
|
37 /* |
|
38 * This file includes the interface through which the lexical parser (stage 1 - flex) |
|
39 * and the syntax analyser (stage 2 - bison) interact between themselves. |
|
40 * |
|
41 * This is mostly through direct access to shared global variables, however some |
|
42 * of the global variables will only be accessed through some accessor functions. |
|
43 * |
|
44 * This file also includes some utility functions (strdupX() ) that are both used |
|
45 * in the lexical and syntax analysers. |
|
46 */ |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 /*********************************************/ |
|
53 /* print the include file stack to stderr... */ |
|
54 /*********************************************/ |
|
55 /* This is a service that flex provides to bison... */ |
|
56 void print_include_stack(void); |
|
57 |
|
58 |
|
59 |
|
60 /**************************************/ |
|
61 /* The name of the file being parsed. */ |
|
62 /**************************************/ |
|
63 /* The name of the file currently being parsed... |
|
64 * Note that flex accesses and updates this global variable |
|
65 * apropriately whenever it comes across an (*#include <filename> *) |
|
66 * directive... |
|
67 * ... and bison will use it when producing error messages. |
|
68 * Note that bison also sets this variable correctly to the first |
|
69 * file being parsed. |
|
70 */ |
|
71 extern const char *current_filename; |
|
72 |
|
73 |
|
74 |
|
75 /*****************************************************/ |
|
76 /* Controlling the entry to the st_il_state in flex. */ |
|
77 /*****************************************************/ |
|
78 void cmd_goto_body_state(void); |
|
79 int get_goto_body_state(void); |
|
80 void rst_goto_body_state(void); |
|
81 |
|
82 |
|
83 /*********************************/ |
|
84 /* The global symbol tables... */ |
|
85 /*********************************/ |
|
86 /* NOTE: only accessed indirectly by the lexical parser (flex) |
|
87 * through the function get_identifier_token() |
|
88 */ |
|
89 /* NOTE: BOGUS_TOKEN_ID is defined in the bison generated file iec.y.hh. |
|
90 * We need this constant defined before we can declare the symbol tables. |
|
91 * However, we cannot #include "iec.y.hh" in this file (stage1_2_priv.hh) directly |
|
92 * because of the way bison ver. 3.2 is copying all declarations in the prologue |
|
93 * of iec.y to the iec.y.hh file (including an #include stage1_2_priv.hh). |
|
94 * So, if we were to include "iec.y.hh" here, we would get a circular include. |
|
95 * All this means that whoever includes this file (stage1_2_priv.hh) will need |
|
96 * to take care to first inlcude iec.y.hh !! |
|
97 */ |
|
98 /* A symbol table to store all the library elements */ |
|
99 /* e.g.: <function_name , function_decl> |
|
100 * <fb_name , fb_decl> |
|
101 * <type_name , type_decl> |
|
102 * <program_name , program_decl> |
|
103 * <configuration_name , configuration_decl> |
|
104 */ |
|
105 extern symtable_c<int, BOGUS_TOKEN_ID> library_element_symtable; |
|
106 |
|
107 /* A symbol table to store the declared variables of |
|
108 * the function currently being parsed... |
|
109 */ |
|
110 extern symtable_c<int, BOGUS_TOKEN_ID> variable_name_symtable; |
|
111 |
|
112 /* Function only called from within flex! |
|
113 * |
|
114 * search for a symbol in either of the two symbol tables |
|
115 * declared above, and return the token id of the first |
|
116 * symbol found. |
|
117 * Searches first in the variables, and only if not found |
|
118 * does it continue searching in the library elements |
|
119 */ |
|
120 int get_identifier_token(const char *identifier_str); |
|
121 |
|
122 |
|
123 |
|
124 /************************/ |
|
125 /* Utility Functions... */ |
|
126 /************************/ |
|
127 |
|
128 /* Join two strings together. Allocate space with malloc(3). */ |
|
129 char *strdup2(const char *a, const char *b); |
|
130 |
|
131 /* Join three strings together. Allocate space with malloc(3). */ |
|
132 char *strdup3(const char *a, const char *b, const char *c); |
|
133 |
|
134 |
|
135 |