absyntax/absyntax.hh
changeset 0 fb772792efd1
child 69 41cb5b80416e
equal deleted inserted replaced
-1:000000000000 0:fb772792efd1
       
     1 /*
       
     2  * (c) 2003 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  * Declaration of the Abstract Syntax data structure components
       
    27  */
       
    28 
       
    29 /*
       
    30  * ABSYNTAX.H
       
    31  *
       
    32  * This generates the parse tree structure used to bind the components
       
    33  * identified by Bison in the correct syntax order. At the end of the
       
    34  * Bison analysis the tree is walked in a sequential fashion generating
       
    35  * the relavent code.
       
    36  */
       
    37 
       
    38 #ifndef _ABSYNTAX_HH
       
    39 #define _ABSYNTAX_HH
       
    40 
       
    41 
       
    42 #include <stdio.h> // required for NULL
       
    43 
       
    44 /* Forward declaration of the visitor interface
       
    45  * dclared in the visitor.hh file
       
    46  * We cannot include the visitor.hh file, as it will
       
    47  * include this same file first, as it too requires references
       
    48  * to the abstract syntax classes defined here.
       
    49  */
       
    50 class visitor_c; // forward declaration
       
    51 
       
    52 
       
    53 class symbol_c; // forward declaration
       
    54 //extern symbol_c *tree_root;
       
    55 
       
    56 
       
    57 
       
    58 /* The base class of all symbols */
       
    59 class symbol_c {
       
    60 
       
    61   public:
       
    62     /*
       
    63      * Line number for the purposes of error checking
       
    64      */
       
    65     long lineno;
       
    66 
       
    67   public:
       
    68     /* default constructor */
       
    69     symbol_c(void);
       
    70     symbol_c(long lineno);
       
    71 
       
    72     /* default destructor */
       
    73     /* must be virtual so compiler does not complain... */ 
       
    74     virtual ~symbol_c(void) {return;};
       
    75 
       
    76     virtual void *accept(visitor_c &visitor) {return NULL;};
       
    77 };
       
    78 
       
    79 
       
    80 class token_c: public symbol_c {
       
    81   public:
       
    82     /* the value of the symbol. */
       
    83     const char *value;
       
    84 
       
    85   public:
       
    86     token_c(const char *value);
       
    87 };
       
    88 
       
    89 
       
    90  /* a list of symbols... */
       
    91 class list_c: public symbol_c {
       
    92   public:
       
    93     int n;
       
    94     symbol_c **elements;
       
    95 
       
    96   public:
       
    97     list_c(void);
       
    98     list_c(symbol_c *elem);
       
    99      /* insert a new element */
       
   100     virtual void add_element(symbol_c *elem);
       
   101 };
       
   102 
       
   103 
       
   104 
       
   105 
       
   106 #define SYM_LIST(class_name_c)			\
       
   107 class class_name_c:	public list_c {		\
       
   108   public:					\
       
   109     virtual void *accept(visitor_c &visitor);	\
       
   110 };
       
   111 
       
   112 
       
   113 #define SYM_TOKEN(class_name_c)			\
       
   114 class class_name_c: 	public token_c {	\
       
   115   public:					\
       
   116     class_name_c(const char *value);			\
       
   117     virtual void *accept(visitor_c &visitor);	\
       
   118 };
       
   119 
       
   120 
       
   121 #define SYM_REF0(class_name_c)			\
       
   122 class class_name_c: public symbol_c {		\
       
   123   public:					\
       
   124     virtual void *accept(visitor_c &visitor);	\
       
   125 };
       
   126 
       
   127 
       
   128 #define SYM_REF2(class_name_c, ref1, ref2)	\
       
   129 class class_name_c: public symbol_c {		\
       
   130   public:					\
       
   131     symbol_c *ref1;				\
       
   132     symbol_c *ref2;				\
       
   133   public:					\
       
   134     class_name_c(symbol_c *ref1,		\
       
   135 		 symbol_c *ref2 = NULL);	\
       
   136     virtual void *accept(visitor_c &visitor);	\
       
   137 };
       
   138 
       
   139 
       
   140 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4)	\
       
   141 class class_name_c: public symbol_c {			\
       
   142   public:						\
       
   143     symbol_c *ref1;					\
       
   144     symbol_c *ref2;					\
       
   145     symbol_c *ref3;					\
       
   146     symbol_c *ref4;					\
       
   147   public:						\
       
   148     class_name_c(symbol_c *ref1,			\
       
   149 		 symbol_c *ref2,			\
       
   150 		 symbol_c *ref3,			\
       
   151 		 symbol_c *ref4 = NULL);		\
       
   152     virtual void *accept(visitor_c &visitor);		\
       
   153 };
       
   154 
       
   155 
       
   156 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6)	\
       
   157 class class_name_c: public symbol_c {					\
       
   158   public:								\
       
   159     symbol_c *ref1;							\
       
   160     symbol_c *ref2;							\
       
   161     symbol_c *ref3;							\
       
   162     symbol_c *ref4;							\
       
   163     symbol_c *ref5;							\
       
   164     symbol_c *ref6;							\
       
   165   public:								\
       
   166     class_name_c(symbol_c *ref1,					\
       
   167 		 symbol_c *ref2,					\
       
   168 		 symbol_c *ref3,					\
       
   169 		 symbol_c *ref4,					\
       
   170 		 symbol_c *ref5,					\
       
   171 		 symbol_c *ref6 = NULL);		\
       
   172     virtual void *accept(visitor_c &visitor);				\
       
   173 };
       
   174 
       
   175 
       
   176 #include "absyntax.def"
       
   177 
       
   178 
       
   179 
       
   180 #undef SYM_LIST
       
   181 #undef SYM_TOKEN
       
   182 #undef SYM_REF0
       
   183 #undef SYM_REF2
       
   184 #undef SYM_REF4
       
   185 #undef SYM_REF6
       
   186 
       
   187 
       
   188 
       
   189 #endif /*  _ABSYNTAX_HH */