etisserant@0: /* etisserant@0: * (c) 2003 Mario de Sousa etisserant@0: * etisserant@0: * Offered to the public under the terms of the GNU General Public License etisserant@0: * as published by the Free Software Foundation; either version 2 of the etisserant@0: * License, or (at your option) any later version. etisserant@0: * etisserant@0: * This program is distributed in the hope that it will be useful, but etisserant@0: * WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General etisserant@0: * Public License for more details. etisserant@0: * etisserant@0: * This code is made available on the understanding that it will not be etisserant@0: * used in safety-critical situations without a full and competent review. etisserant@0: */ etisserant@0: etisserant@0: /* etisserant@0: * An IEC 61131-3 IL and ST compiler. etisserant@0: * etisserant@0: * Based on the etisserant@0: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) etisserant@0: * etisserant@0: */ etisserant@0: etisserant@0: /* etisserant@0: * Declaration of the Abstract Syntax data structure components etisserant@0: */ etisserant@0: etisserant@0: /* etisserant@0: * ABSYNTAX.H etisserant@0: * etisserant@0: * This generates the parse tree structure used to bind the components etisserant@0: * identified by Bison in the correct syntax order. At the end of the etisserant@0: * Bison analysis the tree is walked in a sequential fashion generating etisserant@0: * the relavent code. etisserant@0: */ etisserant@0: etisserant@0: #ifndef _ABSYNTAX_HH etisserant@0: #define _ABSYNTAX_HH etisserant@0: etisserant@0: etisserant@0: #include // required for NULL etisserant@0: etisserant@0: /* Forward declaration of the visitor interface etisserant@0: * dclared in the visitor.hh file etisserant@0: * We cannot include the visitor.hh file, as it will etisserant@0: * include this same file first, as it too requires references etisserant@0: * to the abstract syntax classes defined here. etisserant@0: */ etisserant@0: class visitor_c; // forward declaration etisserant@0: etisserant@0: etisserant@0: class symbol_c; // forward declaration etisserant@0: //extern symbol_c *tree_root; etisserant@0: etisserant@0: etisserant@0: etisserant@0: /* The base class of all symbols */ etisserant@0: class symbol_c { etisserant@0: etisserant@0: public: etisserant@0: /* etisserant@0: * Line number for the purposes of error checking etisserant@0: */ etisserant@0: long lineno; etisserant@0: etisserant@0: public: etisserant@0: /* default constructor */ etisserant@0: symbol_c(void); etisserant@0: symbol_c(long lineno); etisserant@0: etisserant@0: /* default destructor */ etisserant@0: /* must be virtual so compiler does not complain... */ etisserant@0: virtual ~symbol_c(void) {return;}; etisserant@0: etisserant@0: virtual void *accept(visitor_c &visitor) {return NULL;}; etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: class token_c: public symbol_c { etisserant@0: public: etisserant@0: /* the value of the symbol. */ etisserant@0: const char *value; etisserant@0: etisserant@0: public: etisserant@0: token_c(const char *value); etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: /* a list of symbols... */ etisserant@0: class list_c: public symbol_c { etisserant@0: public: etisserant@0: int n; etisserant@0: symbol_c **elements; etisserant@0: etisserant@0: public: etisserant@0: list_c(void); etisserant@0: list_c(symbol_c *elem); etisserant@0: /* insert a new element */ etisserant@0: virtual void add_element(symbol_c *elem); etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: #define SYM_LIST(class_name_c) \ etisserant@0: class class_name_c: public list_c { \ etisserant@0: public: \ etisserant@0: virtual void *accept(visitor_c &visitor); \ etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: #define SYM_TOKEN(class_name_c) \ etisserant@0: class class_name_c: public token_c { \ etisserant@0: public: \ etisserant@0: class_name_c(const char *value); \ etisserant@0: virtual void *accept(visitor_c &visitor); \ etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: #define SYM_REF0(class_name_c) \ etisserant@0: class class_name_c: public symbol_c { \ etisserant@0: public: \ etisserant@0: virtual void *accept(visitor_c &visitor); \ etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: #define SYM_REF2(class_name_c, ref1, ref2) \ etisserant@0: class class_name_c: public symbol_c { \ etisserant@0: public: \ etisserant@0: symbol_c *ref1; \ etisserant@0: symbol_c *ref2; \ etisserant@0: public: \ etisserant@0: class_name_c(symbol_c *ref1, \ etisserant@0: symbol_c *ref2 = NULL); \ etisserant@0: virtual void *accept(visitor_c &visitor); \ etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4) \ etisserant@0: class class_name_c: public symbol_c { \ etisserant@0: public: \ etisserant@0: symbol_c *ref1; \ etisserant@0: symbol_c *ref2; \ etisserant@0: symbol_c *ref3; \ etisserant@0: symbol_c *ref4; \ etisserant@0: public: \ etisserant@0: class_name_c(symbol_c *ref1, \ etisserant@0: symbol_c *ref2, \ etisserant@0: symbol_c *ref3, \ etisserant@0: symbol_c *ref4 = NULL); \ etisserant@0: virtual void *accept(visitor_c &visitor); \ etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6) \ etisserant@0: class class_name_c: public symbol_c { \ etisserant@0: public: \ etisserant@0: symbol_c *ref1; \ etisserant@0: symbol_c *ref2; \ etisserant@0: symbol_c *ref3; \ etisserant@0: symbol_c *ref4; \ etisserant@0: symbol_c *ref5; \ etisserant@0: symbol_c *ref6; \ etisserant@0: public: \ etisserant@0: class_name_c(symbol_c *ref1, \ etisserant@0: symbol_c *ref2, \ etisserant@0: symbol_c *ref3, \ etisserant@0: symbol_c *ref4, \ etisserant@0: symbol_c *ref5, \ etisserant@0: symbol_c *ref6 = NULL); \ etisserant@0: virtual void *accept(visitor_c &visitor); \ etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: #include "absyntax.def" etisserant@0: etisserant@0: etisserant@0: etisserant@0: #undef SYM_LIST etisserant@0: #undef SYM_TOKEN etisserant@0: #undef SYM_REF0 etisserant@0: #undef SYM_REF2 etisserant@0: #undef SYM_REF4 etisserant@0: #undef SYM_REF6 etisserant@0: etisserant@0: etisserant@0: etisserant@0: #endif /* _ABSYNTAX_HH */