--- a/stage1_2/iec.y Mon Feb 12 14:06:59 2007 +0100
+++ b/stage1_2/iec.y Wed Feb 14 19:57:01 2007 +0100
@@ -77,10 +77,9 @@
#include "../absyntax/absyntax.hh"
/* file with declaration of token constants. Generated by bison! */
-#include "iec.y.hh"
-
-/* file with the declarations of symbol tables... */
-#include "../util/symtable.hh"
+// #include "iec.y.hh"
+
+#include "stage1_2_priv.hh"
/* an ugly hack!!
@@ -110,45 +109,30 @@
extern void error_exit(const char *file_name, int line_no);
-/*********************************/
-/* The global symbol tables... */
-/*********************************/
-/* NOTE: declared static because they are not accessed
- * directly by the lexical parser (flex), but rather
- * through the function get_identifier_token()
- */
-/* A symbol table to store all the library elements */
-/* e.g.: <function_name , function_decl>
- * <fb_name , fb_decl>
- * <type_name , type_decl>
- * <program_name , program_decl>
- * <configuration_name , configuration_decl>
- */
-static symtable_c<int, BOGUS_TOKEN_ID> library_element_symtable;
-
-/* A symbol table to store the declared variables of
- * the function currently being parsed...
- */
-static symtable_c<int, BOGUS_TOKEN_ID> variable_name_symtable;
-
/*************************/
/* global variables... */
/*************************/
-static symbol_c *tree_root = NULL;
-
-/* The name of the file currently being parsed...
- * Note that flex accesses and updates this global variable
- * apropriately whenever it comes across an (*#include <filename> *)
- * directive...
- */
-const char *current_filename = NULL;
+/* NOTE: For some strange reason bison ver 2.3 is including these declarations
+ * in the iec.y.hh file, which is in turn included by flex.
+ * We cannot therefore define any variables over here, but merely declare
+ * their existance (otherwise we get errors when linking the code, since we
+ * would get a new variable defined each time iec.y.hh is included!).
+ * Even though the variables are declared 'extern' over here, they will in
+ * fact be defined towards the end of this same file (i.e. in the prologue)
+ */
/* A global flag used to tell the parser if overloaded funtions should be allowed.
* The IEC 61131-3 standard allows overloaded funtions in the standard library,
* but disallows them in user code...
*/
-bool allow_function_overloading = false;
+extern bool allow_function_overloading;
+
+/* A pointer to the root of the parsing tree that will be generated
+ * by bison.
+ */
+extern symbol_c *tree_root;
+
/************************/
@@ -162,20 +146,11 @@
/* print an error message */
void print_err_msg(const char *filename, int lineno, const char *additional_error_msg);
-
-/************************/
-/* forward declarations */
-/************************/
-/* The functions declared here are defined in iec.flex... */
-void print_include_stack(void);
-void cmd_goto_body_state(void);
-int get_goto_body_state(void);
-void rst_goto_body_state(void);
-
%}
+
%glr-parser
// %expect-rr 1
@@ -206,37 +181,6 @@
/*****************************/
/* Prelimenary constructs... */
/*****************************/
-%type <leaf> start
-
-%type <leaf> any_identifier
-
-%token <ID> prev_declared_variable_name_token
-%token <ID> prev_declared_fb_name_token
-%type <leaf> prev_declared_variable_name
-%type <leaf> prev_declared_fb_name
-
-%token <ID> prev_declared_simple_type_name_token
-%token <ID> prev_declared_subrange_type_name_token
-%token <ID> prev_declared_enumerated_type_name_token
-%token <ID> prev_declared_array_type_name_token
-%token <ID> prev_declared_structure_type_name_token
-%token <ID> prev_declared_string_type_name_token
-
-%type <leaf> prev_declared_simple_type_name
-%type <leaf> prev_declared_subrange_type_name
-%type <leaf> prev_declared_enumerated_type_name
-%type <leaf> prev_declared_array_type_name
-%type <leaf> prev_declared_structure_type_name
-%type <leaf> prev_declared_string_type_name
-
-%token <ID> prev_declared_derived_function_name_token
-%token <ID> prev_declared_derived_function_block_name_token
-%token <ID> prev_declared_program_type_name_token
-%type <leaf> prev_declared_derived_function_name
-%type <leaf> prev_declared_derived_function_block_name
-%type <leaf> prev_declared_program_type_name
-
-
/* A bogus token that, in principle, flex MUST NEVER generate */
/* USE 1:
* ======
@@ -256,6 +200,47 @@
%token BOGUS_TOKEN_ID
+
+%{
+/* The interface through which bison and flex interact. */
+/* May only be included after the definition of BOGUS_TOKEN_ID */
+#include "stage1_2_priv.hh"
+%}
+
+
+%type <leaf> start
+
+%type <leaf> any_identifier
+
+%token <ID> prev_declared_variable_name_token
+%token <ID> prev_declared_fb_name_token
+%type <leaf> prev_declared_variable_name
+%type <leaf> prev_declared_fb_name
+
+%token <ID> prev_declared_simple_type_name_token
+%token <ID> prev_declared_subrange_type_name_token
+%token <ID> prev_declared_enumerated_type_name_token
+%token <ID> prev_declared_array_type_name_token
+%token <ID> prev_declared_structure_type_name_token
+%token <ID> prev_declared_string_type_name_token
+
+%type <leaf> prev_declared_simple_type_name
+%type <leaf> prev_declared_subrange_type_name
+%type <leaf> prev_declared_enumerated_type_name
+%type <leaf> prev_declared_array_type_name
+%type <leaf> prev_declared_structure_type_name
+%type <leaf> prev_declared_string_type_name
+
+%token <ID> prev_declared_derived_function_name_token
+%token <ID> prev_declared_derived_function_block_name_token
+%token <ID> prev_declared_program_type_name_token
+%type <leaf> prev_declared_derived_function_name
+%type <leaf> prev_declared_derived_function_block_name
+%type <leaf> prev_declared_program_type_name
+
+
+
+
/* The pragmas... */
%token <ID> pragma_token
%type <leaf> pragma
@@ -488,11 +473,11 @@
%token STRING
%token BOOL
-%token TIME
-%token DATE
-%token DATE_AND_TIME
+// %token TIME
+// %token DATE
+// %token DATE_AND_TIME
%token DT
-%token TIME_OF_DAY
+// %token TIME_OF_DAY
%token TOD
@@ -783,10 +768,10 @@
%token FUNCTION_BLOCK
%token END_FUNCTION_BLOCK
%token VAR_TEMP
-%token END_VAR
+// %token END_VAR
%token VAR
-%token NON_RETAIN
-%token END_VAR
+// %token NON_RETAIN
+// %token END_VAR
/**********************/
@@ -831,7 +816,7 @@
%type <leaf> transition_name
-%token ASSIGN
+// %token ASSIGN
%token ACTION
%token END_ACTION
@@ -942,12 +927,12 @@
%token END_RESOURCE
%token VAR_CONFIG
%token VAR_ACCESS
-%token END_VAR
+// %token END_VAR
%token WITH
-%token PROGRAM
-%token RETAIN
-%token NON_RETAIN
-%token PRIORITY
+// %token PROGRAM
+// %token RETAIN
+// %token NON_RETAIN
+// %token PRIORITY
%token SINGLE
%token INTERVAL
%token READ_WRITE
@@ -1125,11 +1110,11 @@
/* intermediate helper symbol for primary_expression */
%type <leaf> function_invocation
-%token AND
-%token XOR
-%token OR
-%token MOD
-%token NOT
+// %token AND
+// %token XOR
+// %token OR
+// %token MOD
+// %token NOT
%token OPER_NE
%token OPER_GE
%token OPER_LE
@@ -1148,7 +1133,7 @@
/* B 3.2.1 Assignment Statements */
/*********************************/
%type <leaf> assignment_statement
-%token ASSIGN /* ":=" */
+// %token ASSIGN /* ":=" */
/*****************************************/
@@ -1161,8 +1146,8 @@
/* helper symbol for fb_invocation */
%type <list> param_assignment_list
-%token ASSIGN
-%token SENDTO /* "=>" */
+// %token ASSIGN
+// %token SENDTO /* "=>" */
%token RETURN
@@ -1189,8 +1174,8 @@
%token END_IF
%token CASE
-%token OF
-%token ELSE
+// %token OF
+// %token ELSE
%token END_CASE
@@ -1208,14 +1193,14 @@
// %type <leaf> for_list
%token FOR
-%token ASSIGN
-%token TO
+// %token ASSIGN
+// %token TO
%token BY
%token DO
%token END_FOR
%token WHILE
-%token DO
+// %token DO
%token END_WHILE
%token REPEAT
@@ -5178,6 +5163,21 @@
extern FILE *yyin;
extern int yylineno;
+
+
+/* A global flag used to tell the parser if overloaded funtions should be allowed.
+ * The IEC 61131-3 standard allows overloaded funtions in the standard library,
+ * but disallows them in user code...
+ */
+bool allow_function_overloading = false;
+
+/* A pointer to the root of the parsing tree that will be generated
+ * by bison.
+ */
+symbol_c *tree_root;
+
+
+
/* The following function is called automatically by bison whenever it comes across
* an error. Unfortunately it calls this function before executing the code that handles
* the error itself, so we cannot print out the correct line numbers of the error location
@@ -5200,24 +5200,6 @@
fprintf(stderr, "%s:%d: %s\n", filename, lineno, current_error_msg);
}
-/* Function only called from within flex!
- *
- * search for a symbol in either of the two symbol tables
- * declared above, and return the token id of the first
- * symbol found.
- * Searches first in the variables, and only if not found
- * does it continue searching in the library elements
- */
-int get_identifier_token(const char *identifier_str) {
-// std::cout << "get_identifier_token(" << identifier_str << "): \n";
- int token_id;
-
- if ((token_id = variable_name_symtable.find_value(identifier_str)) == variable_name_symtable.end_value())
- if ((token_id = library_element_symtable.find_value(identifier_str)) == library_element_symtable.end_value())
- return identifier_token;
- return token_id;
-}
-
/* convert between an il_operator to a function name */
@@ -5306,31 +5288,6 @@
-/*
- * Join two strings together. Allocate space with malloc(3).
- */
-static char *strdup2(const char *a, const char *b) {
- char *res = (char *)malloc(strlen(a) + strlen(b) + 1);
-
- if (!res)
- return NULL;
- return strcat(strcpy(res, a), b); /* safe, actually */
-}
-
-/*
- * Join three strings together. Allocate space with malloc(3).
- */
-static char *strdup3(const char *a, const char *b, const char *c) {
- char *res = (char *)malloc(strlen(a) + strlen(b) + strlen(c) + 1);
-
- if (!res)
- return NULL;
- return strcat(strcat(strcpy(res, a), b), c); /* safe, actually */
-}
-
-
-
-
const char *standard_function_names[] = {
// 2.5.1.5.1 Type conversion functions
/*
@@ -5410,7 +5367,7 @@
#define LIBFILE "ieclib.txt"
#define DEF_LIBFILENAME LIBDIRECTORY "/" LIBFILE
-int stage1_2(const char *filename, const char *includedir, symbol_c **tree_root_ref) {
+int stage1_2__(const char *filename, const char *includedir, symbol_c **tree_root_ref) {
FILE *in_file = NULL, *lib_file = NULL;
char *libfilename = NULL;