absyntax/absyntax.cc
changeset 69 41cb5b80416e
parent 15 0b472e25eb16
child 261 db2ad6541d92
equal deleted inserted replaced
68:b0a43002dcac 69:41cb5b80416e
    41 
    41 
    42 
    42 
    43 
    43 
    44 /* The base class of all symbols */
    44 /* The base class of all symbols */
    45 symbol_c::symbol_c(void) {
    45 symbol_c::symbol_c(void) {
    46   lineno = 0;
    46   this->first_line   = 0;
    47 }
    47   this->first_column = 0;
    48 
    48   this->last_line    = 0;
    49 symbol_c::symbol_c(long lineno) {
    49   this->last_column  = 0;
    50   this->lineno = lineno;
    50 }
    51 }
    51 
    52 
    52 symbol_c::symbol_c(int first_line, int first_column, int last_line, int last_column) {
    53 
    53   this->first_line   = first_line;
    54 
    54   this->first_column = first_column;
    55 token_c::token_c(const char *value) {
    55   this->last_line    = last_line;
       
    56   this->last_column  = last_column;
       
    57 }
       
    58 
       
    59 
       
    60 
       
    61 token_c::token_c(const char *value, int fl, int fc, int ll, int lc)
       
    62   :symbol_c(fl, fc, ll, lc) {
    56   this->value = value;
    63   this->value = value;
    57 //  printf("New token: %s\n", value);
    64 //  printf("New token: %s\n", value);
    58 }
    65 }
    59 
    66 
    60 
    67 
    61 
    68 
    62 
    69 
    63 
    70 
    64 
    71 
    65 list_c::list_c(void) {
    72 list_c::list_c(int fl, int fc, int ll, int lc)
       
    73   :symbol_c(fl, fc, ll, lc) {
    66   n = 0;
    74   n = 0;
    67   elements = NULL;
    75   elements = NULL;
    68 }
    76 }
    69 
    77 
    70 list_c::list_c(symbol_c *elem) {
    78 list_c::list_c(symbol_c *elem, int fl, int fc, int ll, int lc)
       
    79   :symbol_c(fl, fc, ll, lc) {
    71   n = 0;
    80   n = 0;
    72   elements = NULL;
    81   elements = NULL;
    73   add_element(elem);
    82   add_element(elem);
    74 }
    83 }
    75 
    84 
    79   n++;
    88   n++;
    80   elements = (symbol_c **)realloc(elements, n * sizeof(symbol_c *));
    89   elements = (symbol_c **)realloc(elements, n * sizeof(symbol_c *));
    81   if (elements == NULL)
    90   if (elements == NULL)
    82     ABORT("Out of memory");
    91     ABORT("Out of memory");
    83   elements[n - 1] = elem;
    92   elements[n - 1] = elem;
    84 }
    93  
    85 
    94   if (elem == NULL)
       
    95     return;
       
    96 
       
    97   /* adjust the location parameters, taking into account the new element. */
       
    98   if ((first_line == elem->first_line) &&
       
    99       (first_column > elem->first_column)) {
       
   100     first_column = elem->first_column;
       
   101   }
       
   102   if (first_line > elem->first_line) {
       
   103     first_line = elem->first_line;
       
   104     first_column = elem->first_column;
       
   105   }
       
   106   if ((last_line == elem->last_line) &&
       
   107       (last_column < elem->last_column)) {
       
   108     last_column = elem->last_column;
       
   109   }
       
   110   if (last_line < elem->last_line) {
       
   111     last_line = elem->last_line;
       
   112     last_column = elem->last_column;
       
   113   }
       
   114 }
    86 
   115 
    87 
   116 
    88 
   117 
    89 
   118 
    90 #define SYM_LIST(class_name_c)							\
   119 #define SYM_LIST(class_name_c)							\
       
   120 class_name_c::class_name_c(int fl, int fc, int ll, int lc)			\
       
   121 			:list_c(fl, fc, ll, lc) {}				\
       
   122 class_name_c::class_name_c(symbol_c *elem, int fl, int fc, int ll, int lc)	\
       
   123 			:list_c(elem, fl, fc, ll, lc) {}			\
    91 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   124 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
    92 
   125 
    93 #define SYM_TOKEN(class_name_c)							\
   126 #define SYM_TOKEN(class_name_c)							\
    94 class_name_c::class_name_c(const char *value): token_c(value) {}			\
   127 class_name_c::class_name_c(const char *value, int fl, int fc, int ll, int lc)	\
    95 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   128 			:token_c(value, fl, fc, ll, lc) {}			\
    96 
   129 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
    97 #define SYM_REF0(class_name_c)			\
   130 
    98 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   131 #define SYM_REF0(class_name_c)					\
    99 
   132 class_name_c::class_name_c(int fl, int fc,			\
   100 
   133 			   int ll, int lc			\
   101 #define SYM_REF2(class_name_c, ref1, ref2)	\
   134 			  ): symbol_c(fl, fc, ll, lc) {}	\
   102 class_name_c::class_name_c(symbol_c *ref1,	\
   135 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   103 			   symbol_c *ref2) {	\
   136 
   104   this->ref1 = ref1;				\
   137 
   105   this->ref2 = ref2;				\
   138 #define SYM_REF1(class_name_c, ref1)			\
   106 }						\
   139 class_name_c::class_name_c(symbol_c *ref1,		\
   107 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   140 			   int fl, int fc,		\
   108 
   141 			   int ll, int lc		\
   109 
   142 			  ): symbol_c(fl, fc, ll, lc) {	\
   110 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4)	\
   143   this->ref1 = ref1;					\
       
   144 }							\
       
   145 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
       
   146 
       
   147 
       
   148 #define SYM_REF2(class_name_c, ref1, ref2)		\
       
   149 class_name_c::class_name_c(symbol_c *ref1,		\
       
   150 			   symbol_c *ref2,		\
       
   151 			   int fl, int fc,		\
       
   152 			   int ll, int lc		\
       
   153 			  ): symbol_c(fl, fc, ll, lc) {	\
       
   154   this->ref1 = ref1;					\
       
   155   this->ref2 = ref2;					\
       
   156 }							\
       
   157 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
       
   158 
       
   159 
       
   160 #define SYM_REF3(class_name_c, ref1, ref2, ref3)	\
   111 class_name_c::class_name_c(symbol_c *ref1,		\
   161 class_name_c::class_name_c(symbol_c *ref1,		\
   112 			   symbol_c *ref2,		\
   162 			   symbol_c *ref2,		\
   113 			   symbol_c *ref3,		\
   163 			   symbol_c *ref3,		\
   114 			   symbol_c *ref4) {		\
   164 			   int fl, int fc,		\
       
   165 			   int ll, int lc		\
       
   166 			  ): symbol_c(fl, fc, ll, lc) {	\
       
   167   this->ref1 = ref1;					\
       
   168   this->ref2 = ref2;					\
       
   169   this->ref3 = ref3;					\
       
   170 }							\
       
   171 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
       
   172 
       
   173 
       
   174 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4)	\
       
   175 class_name_c::class_name_c(symbol_c *ref1,		\
       
   176 			   symbol_c *ref2,		\
       
   177 			   symbol_c *ref3,		\
       
   178 			   symbol_c *ref4,		\
       
   179 			   int fl, int fc,		\
       
   180 			   int ll, int lc		\
       
   181 			  ): symbol_c(fl, fc, ll, lc) {	\
   115   this->ref1 = ref1;					\
   182   this->ref1 = ref1;					\
   116   this->ref2 = ref2;					\
   183   this->ref2 = ref2;					\
   117   this->ref3 = ref3;					\
   184   this->ref3 = ref3;					\
   118   this->ref4 = ref4;					\
   185   this->ref4 = ref4;					\
   119 }							\
   186 }							\
   120 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   187 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
       
   188 
       
   189 
       
   190 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5)		\
       
   191 class_name_c::class_name_c(symbol_c *ref1,				\
       
   192 			   symbol_c *ref2,				\
       
   193 			   symbol_c *ref3,				\
       
   194 			   symbol_c *ref4,				\
       
   195 			   symbol_c *ref5,				\
       
   196 			   int fl, int fc,				\
       
   197 			   int ll, int lc				\
       
   198 			  ): symbol_c(fl, fc, ll, lc) {			\
       
   199   this->ref1 = ref1;							\
       
   200   this->ref2 = ref2;							\
       
   201   this->ref3 = ref3;							\
       
   202   this->ref4 = ref4;							\
       
   203   this->ref5 = ref5;							\
       
   204 }									\
       
   205 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
       
   206 
   121 
   207 
   122 
   208 
   123 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6)	\
   209 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6)	\
   124 class_name_c::class_name_c(symbol_c *ref1,				\
   210 class_name_c::class_name_c(symbol_c *ref1,				\
   125 			   symbol_c *ref2,				\
   211 			   symbol_c *ref2,				\
   126 			   symbol_c *ref3,				\
   212 			   symbol_c *ref3,				\
   127 			   symbol_c *ref4,				\
   213 			   symbol_c *ref4,				\
   128 			   symbol_c *ref5,				\
   214 			   symbol_c *ref5,				\
   129 			   symbol_c *ref6) {				\
   215 			   symbol_c *ref6,				\
   130   this->ref1 = ref1;						\
   216 			   int fl, int fc,				\
   131   this->ref2 = ref2;						\
   217 			   int ll, int lc				\
   132   this->ref3 = ref3;						\
   218 			  ): symbol_c(fl, fc, ll, lc) {			\
   133   this->ref4 = ref4;						\
   219   this->ref1 = ref1;							\
   134   this->ref5 = ref5;						\
   220   this->ref2 = ref2;							\
   135   this->ref6 = ref6;						\
   221   this->ref3 = ref3;							\
   136 }								\
   222   this->ref4 = ref4;							\
       
   223   this->ref5 = ref5;							\
       
   224   this->ref6 = ref6;							\
       
   225 }									\
   137 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   226 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   138 
   227 
   139 
   228 
   140 
   229 
   141 #include "absyntax.def"
   230 #include "absyntax.def"
   145 
   234 
   146 #undef SYM_LIST
   235 #undef SYM_LIST
   147 #undef SYM_TOKEN
   236 #undef SYM_TOKEN
   148 #undef SYM_TOKEN
   237 #undef SYM_TOKEN
   149 #undef SYM_REF0
   238 #undef SYM_REF0
       
   239 #undef SYM_REF1
   150 #undef SYM_REF2
   240 #undef SYM_REF2
       
   241 #undef SYM_REF3
   151 #undef SYM_REF4
   242 #undef SYM_REF4
       
   243 #undef SYM_REF5
   152 #undef SYM_REF6
   244 #undef SYM_REF6
   153 
   245 
   154 
   246 
   155 
   247 
   156 
   248