absyntax/absyntax.cc
changeset 286 a4f4990d5c66
parent 279 c0453b7f99df
child 287 9df7fcb9bde5
equal deleted inserted replaced
284:64a4504633d4 286:a4f4990d5c66
    47 
    47 
    48 
    48 
    49 
    49 
    50 
    50 
    51 /* The base class of all symbols */
    51 /* The base class of all symbols */
    52 symbol_c::symbol_c(void) {
    52 symbol_c::symbol_c(
    53   this->first_line   = 0;
    53                    int first_line, int first_column, const char *ffile,
    54   this->first_column = 0;
    54                    int last_line,  int last_column,  const char *lfile) {
    55   this->last_line    = 0;
    55   this->first_file   = ffile,
    56   this->last_column  = 0;
       
    57 }
       
    58 
       
    59 symbol_c::symbol_c(int first_line, int first_column, int last_line, int last_column) {
       
    60   this->first_line   = first_line;
    56   this->first_line   = first_line;
    61   this->first_column = first_column;
    57   this->first_column = first_column;
       
    58   this->last_file    = lfile,
    62   this->last_line    = last_line;
    59   this->last_line    = last_line;
    63   this->last_column  = last_column;
    60   this->last_column  = last_column;
    64 }
    61 }
    65 
    62 
    66 
    63 
    67 
    64 
    68 token_c::token_c(const char *value, int fl, int fc, int ll, int lc)
    65 token_c::token_c(const char *value, 
    69   :symbol_c(fl, fc, ll, lc) {
    66                  int fl, int fc, const char *ffile,
       
    67                  int ll, int lc, const char *lfile)
       
    68   :symbol_c(fl, fc, ffile, ll, lc, lfile) {
    70   this->value = value;
    69   this->value = value;
    71 //  printf("New token: %s\n", value);
    70 //  printf("New token: %s\n", value);
    72 }
    71 }
    73 
    72 
    74 
    73 
    75 
    74 
    76 
    75 
    77 
    76 
    78 
    77 
    79 list_c::list_c(int fl, int fc, int ll, int lc)
    78 list_c::list_c(
    80   :symbol_c(fl, fc, ll, lc) {
    79                int fl, int fc, const char *ffile,
       
    80                int ll, int lc, const char *lfile)
       
    81   :symbol_c(fl, fc, ffile, ll, lc, lfile) {
    81   n = 0;
    82   n = 0;
    82   elements = NULL;
    83   elements = NULL;
    83 }
    84 }
    84 
    85 
    85 list_c::list_c(symbol_c *elem, int fl, int fc, int ll, int lc)
    86 list_c::list_c(symbol_c *elem, 
    86   :symbol_c(fl, fc, ll, lc) {
    87                int fl, int fc, const char *ffile,
       
    88                int ll, int lc, const char *lfile)
       
    89   :symbol_c(fl, fc, ffile, ll, lc, lfile) {
    87   n = 0;
    90   n = 0;
    88   elements = NULL;
    91   elements = NULL;
    89   add_element(elem);
    92   add_element(elem);
    90 }
    93 }
    91 
    94 
   121 }
   124 }
   122 
   125 
   123 
   126 
   124 
   127 
   125 
   128 
   126 #define SYM_LIST(class_name_c)							\
   129 #define SYM_LIST(class_name_c)									\
   127 class_name_c::class_name_c(int fl, int fc, int ll, int lc)			\
   130 class_name_c::class_name_c(									\
   128 			:list_c(fl, fc, ll, lc) {}				\
   131                            int fl, int fc, const char *ffile,					\
   129 class_name_c::class_name_c(symbol_c *elem, int fl, int fc, int ll, int lc)	\
   132                            int ll, int lc, const char *lfile)					\
   130 			:list_c(elem, fl, fc, ll, lc) {}			\
   133                         :list_c(fl, fc, ffile, ll, lc, lfile) {}				\
   131 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   134 class_name_c::class_name_c(symbol_c *elem, 							\
   132 
   135                            int fl, int fc, const char *ffile,					\
   133 #define SYM_TOKEN(class_name_c)							\
   136                            int ll, int lc, const char *lfile)					\
   134 class_name_c::class_name_c(const char *value, int fl, int fc, int ll, int lc)	\
   137 			:list_c(elem, fl, fc, ffile, ll, lc, lfile) {}				\
   135 			:token_c(value, fl, fc, ll, lc) {}			\
   138 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   136 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   139 
   137 
   140 #define SYM_TOKEN(class_name_c)									\
   138 #define SYM_REF0(class_name_c)					\
   141 class_name_c::class_name_c(const char *value, 							\
   139 class_name_c::class_name_c(int fl, int fc,			\
   142                            int fl, int fc, const char *ffile,					\
   140 			   int ll, int lc			\
   143                            int ll, int lc, const char *lfile)					\
   141 			  ): symbol_c(fl, fc, ll, lc) {}	\
   144 			:token_c(value, fl, fc, ffile, ll, lc, lfile) {}			\
   142 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   145 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   143 
   146 
   144 
   147 #define SYM_REF0(class_name_c)									\
   145 #define SYM_REF1(class_name_c, ref1)			\
   148 class_name_c::class_name_c(									\
   146 class_name_c::class_name_c(symbol_c *ref1,		\
   149                            int fl, int fc, const char *ffile,					\
   147 			   int fl, int fc,		\
   150                            int ll, int lc, const char *lfile)					\
   148 			   int ll, int lc		\
   151 			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {}				\
   149 			  ): symbol_c(fl, fc, ll, lc) {	\
   152 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   150   this->ref1 = ref1;					\
   153 
   151 }							\
   154 
   152 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   155 #define SYM_REF1(class_name_c, ref1)								\
   153 
   156 class_name_c::class_name_c(symbol_c *ref1,							\
   154 
   157                            int fl, int fc, const char *ffile,					\
   155 #define SYM_REF2(class_name_c, ref1, ref2)		\
   158                            int ll, int lc, const char *lfile)					\
   156 class_name_c::class_name_c(symbol_c *ref1,		\
   159 			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
   157 			   symbol_c *ref2,		\
   160   this->ref1 = ref1;										\
   158 			   int fl, int fc,		\
   161 }												\
   159 			   int ll, int lc		\
   162 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   160 			  ): symbol_c(fl, fc, ll, lc) {	\
   163 
   161   this->ref1 = ref1;					\
   164 
   162   this->ref2 = ref2;					\
   165 #define SYM_REF2(class_name_c, ref1, ref2)							\
   163 }							\
   166 class_name_c::class_name_c(symbol_c *ref1,							\
   164 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   167 			   symbol_c *ref2,							\
   165 
   168                            int fl, int fc, const char *ffile,					\
   166 
   169                            int ll, int lc, const char *lfile)					\
   167 #define SYM_REF3(class_name_c, ref1, ref2, ref3)	\
   170 			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
   168 class_name_c::class_name_c(symbol_c *ref1,		\
   171   this->ref1 = ref1;										\
   169 			   symbol_c *ref2,		\
   172   this->ref2 = ref2;										\
   170 			   symbol_c *ref3,		\
   173 }												\
   171 			   int fl, int fc,		\
   174 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   172 			   int ll, int lc		\
   175 
   173 			  ): symbol_c(fl, fc, ll, lc) {	\
   176 
   174   this->ref1 = ref1;					\
   177 #define SYM_REF3(class_name_c, ref1, ref2, ref3)						\
   175   this->ref2 = ref2;					\
   178 class_name_c::class_name_c(symbol_c *ref1,							\
   176   this->ref3 = ref3;					\
   179 			   symbol_c *ref2,							\
   177 }							\
   180 			   symbol_c *ref3,							\
   178 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   181                            int fl, int fc, const char *ffile,					\
   179 
   182                            int ll, int lc, const char *lfile)					\
   180 
   183 			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
   181 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4)	\
   184   this->ref1 = ref1;										\
   182 class_name_c::class_name_c(symbol_c *ref1,		\
   185   this->ref2 = ref2;										\
   183 			   symbol_c *ref2,		\
   186   this->ref3 = ref3;										\
   184 			   symbol_c *ref3,		\
   187 }												\
   185 			   symbol_c *ref4,		\
   188 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   186 			   int fl, int fc,		\
   189 
   187 			   int ll, int lc		\
   190 
   188 			  ): symbol_c(fl, fc, ll, lc) {	\
   191 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4)						\
   189   this->ref1 = ref1;					\
   192 class_name_c::class_name_c(symbol_c *ref1,							\
   190   this->ref2 = ref2;					\
   193 			   symbol_c *ref2,							\
   191   this->ref3 = ref3;					\
   194 			   symbol_c *ref3,							\
   192   this->ref4 = ref4;					\
   195 			   symbol_c *ref4,							\
   193 }							\
   196                            int fl, int fc, const char *ffile,					\
   194 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   197                            int ll, int lc, const char *lfile)					\
   195 
   198 			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
   196 
   199   this->ref1 = ref1;										\
   197 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5)		\
   200   this->ref2 = ref2;										\
   198 class_name_c::class_name_c(symbol_c *ref1,				\
   201   this->ref3 = ref3;										\
   199 			   symbol_c *ref2,				\
   202   this->ref4 = ref4;										\
   200 			   symbol_c *ref3,				\
   203 }												\
   201 			   symbol_c *ref4,				\
   204 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   202 			   symbol_c *ref5,				\
   205 
   203 			   int fl, int fc,				\
   206 
   204 			   int ll, int lc				\
   207 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5)					\
   205 			  ): symbol_c(fl, fc, ll, lc) {			\
   208 class_name_c::class_name_c(symbol_c *ref1,							\
   206   this->ref1 = ref1;							\
   209 			   symbol_c *ref2,							\
   207   this->ref2 = ref2;							\
   210 			   symbol_c *ref3,							\
   208   this->ref3 = ref3;							\
   211 			   symbol_c *ref4,							\
   209   this->ref4 = ref4;							\
   212 			   symbol_c *ref5,							\
   210   this->ref5 = ref5;							\
   213                            int fl, int fc, const char *ffile,					\
   211 }									\
   214                            int ll, int lc, const char *lfile)					\
   212 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   215 			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
   213 
   216   this->ref1 = ref1;										\
   214 
   217   this->ref2 = ref2;										\
   215 
   218   this->ref3 = ref3;										\
   216 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6)	\
   219   this->ref4 = ref4;										\
   217 class_name_c::class_name_c(symbol_c *ref1,				\
   220   this->ref5 = ref5;										\
   218 			   symbol_c *ref2,				\
   221 }												\
   219 			   symbol_c *ref3,				\
   222 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   220 			   symbol_c *ref4,				\
   223 
   221 			   symbol_c *ref5,				\
   224 
   222 			   symbol_c *ref6,				\
   225 
   223 			   int fl, int fc,				\
   226 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6)				\
   224 			   int ll, int lc				\
   227 class_name_c::class_name_c(symbol_c *ref1,							\
   225 			  ): symbol_c(fl, fc, ll, lc) {			\
   228 			   symbol_c *ref2,							\
   226   this->ref1 = ref1;							\
   229 			   symbol_c *ref3,							\
   227   this->ref2 = ref2;							\
   230 			   symbol_c *ref4,							\
   228   this->ref3 = ref3;							\
   231 			   symbol_c *ref5,							\
   229   this->ref4 = ref4;							\
   232 			   symbol_c *ref6,							\
   230   this->ref5 = ref5;							\
   233                            int fl, int fc, const char *ffile,					\
   231   this->ref6 = ref6;							\
   234                            int ll, int lc, const char *lfile)					\
   232 }									\
   235 			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
       
   236   this->ref1 = ref1;										\
       
   237   this->ref2 = ref2;										\
       
   238   this->ref3 = ref3;										\
       
   239   this->ref4 = ref4;										\
       
   240   this->ref5 = ref5;										\
       
   241   this->ref6 = ref6;										\
       
   242 }												\
   233 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   243 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   234 
   244 
   235 
   245 
   236 
   246 
   237 #include "absyntax.def"
   247 #include "absyntax.def"