Added tracking of order by which tokens are processed by lexical analyser.
authorMario de Sousa <msousa@fe.up.pt>
Thu, 14 Apr 2011 18:12:59 +0100
changeset 287 9df7fcb9bde5
parent 286 a4f4990d5c66
child 288 200efef43c3e
Added tracking of order by which tokens are processed by lexical analyser.
This helps in correctly formating error messages when constructs begin in one file, and end in another.
absyntax/absyntax.cc
absyntax/absyntax.hh
stage1_2/iec.flex
stage1_2/iec.y
stage3/visit_expression_type.cc
--- a/absyntax/absyntax.cc	Thu Apr 14 17:35:25 2011 +0100
+++ b/absyntax/absyntax.cc	Thu Apr 14 18:12:59 2011 +0100
@@ -50,22 +50,24 @@
 
 /* The base class of all symbols */
 symbol_c::symbol_c(
-                   int first_line, int first_column, const char *ffile,
-                   int last_line,  int last_column,  const char *lfile) {
+                   int first_line, int first_column, const char *ffile, long int first_order,
+                   int last_line,  int last_column,  const char *lfile, long int last_order ) {
   this->first_file   = ffile,
   this->first_line   = first_line;
   this->first_column = first_column;
+  this->first_order  = first_order;
   this->last_file    = lfile,
   this->last_line    = last_line;
   this->last_column  = last_column;
+  this->last_order   = last_order;
 }
 
 
 
 token_c::token_c(const char *value, 
-                 int fl, int fc, const char *ffile,
-                 int ll, int lc, const char *lfile)
-  :symbol_c(fl, fc, ffile, ll, lc, lfile) {
+                 int fl, int fc, const char *ffile, long int forder,
+                 int ll, int lc, const char *lfile, long int lorder)
+  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {
   this->value = value;
 //  printf("New token: %s\n", value);
 }
@@ -76,17 +78,17 @@
 
 
 list_c::list_c(
-               int fl, int fc, const char *ffile,
-               int ll, int lc, const char *lfile)
-  :symbol_c(fl, fc, ffile, ll, lc, lfile) {
+               int fl, int fc, const char *ffile, long int forder,
+               int ll, int lc, const char *lfile, long int lorder)
+  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {
   n = 0;
   elements = NULL;
 }
 
 list_c::list_c(symbol_c *elem, 
-               int fl, int fc, const char *ffile,
-               int ll, int lc, const char *lfile)
-  :symbol_c(fl, fc, ffile, ll, lc, lfile) {
+               int fl, int fc, const char *ffile, long int forder,
+               int ll, int lc, const char *lfile, long int lorder)
+  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {
   n = 0;
   elements = NULL;
   add_element(elem);
@@ -128,35 +130,35 @@
 
 #define SYM_LIST(class_name_c)									\
 class_name_c::class_name_c(									\
-                           int fl, int fc, const char *ffile,					\
-                           int ll, int lc, const char *lfile)					\
-                        :list_c(fl, fc, ffile, ll, lc, lfile) {}				\
+                           int fl, int fc, const char *ffile, long int forder,			\
+                           int ll, int lc, const char *lfile, long int lorder)			\
+                        :list_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {}		\
 class_name_c::class_name_c(symbol_c *elem, 							\
-                           int fl, int fc, const char *ffile,					\
-                           int ll, int lc, const char *lfile)					\
-			:list_c(elem, fl, fc, ffile, ll, lc, lfile) {}				\
+                           int fl, int fc, const char *ffile, long int forder,			\
+                           int ll, int lc, const char *lfile, long int lorder)			\
+			:list_c(elem, fl, fc, ffile, forder, ll, lc, lfile, lorder) {}		\
 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
 
 #define SYM_TOKEN(class_name_c)									\
 class_name_c::class_name_c(const char *value, 							\
-                           int fl, int fc, const char *ffile,					\
-                           int ll, int lc, const char *lfile)					\
-			:token_c(value, fl, fc, ffile, ll, lc, lfile) {}			\
+                           int fl, int fc, const char *ffile, long int forder,			\
+                           int ll, int lc, const char *lfile, long int lorder)			\
+			:token_c(value, fl, fc, ffile, forder, ll, lc, lfile, lorder) {}	\
 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
 
 #define SYM_REF0(class_name_c)									\
 class_name_c::class_name_c(									\
-                           int fl, int fc, const char *ffile,					\
-                           int ll, int lc, const char *lfile)					\
-			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {}				\
+                           int fl, int fc, const char *ffile, long int forder,			\
+                           int ll, int lc, const char *lfile, long int lorder)			\
+			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {}		\
 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
 
 
 #define SYM_REF1(class_name_c, ref1)								\
 class_name_c::class_name_c(symbol_c *ref1,							\
-                           int fl, int fc, const char *ffile,					\
-                           int ll, int lc, const char *lfile)					\
-			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
+                           int fl, int fc, const char *ffile, long int forder,			\
+                           int ll, int lc, const char *lfile, long int lorder)			\
+			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   this->ref1 = ref1;										\
 }												\
 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
@@ -165,9 +167,9 @@
 #define SYM_REF2(class_name_c, ref1, ref2)							\
 class_name_c::class_name_c(symbol_c *ref1,							\
 			   symbol_c *ref2,							\
-                           int fl, int fc, const char *ffile,					\
-                           int ll, int lc, const char *lfile)					\
-			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
+                           int fl, int fc, const char *ffile, long int forder,			\
+                           int ll, int lc, const char *lfile, long int lorder)			\
+			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   this->ref1 = ref1;										\
   this->ref2 = ref2;										\
 }												\
@@ -178,9 +180,9 @@
 class_name_c::class_name_c(symbol_c *ref1,							\
 			   symbol_c *ref2,							\
 			   symbol_c *ref3,							\
-                           int fl, int fc, const char *ffile,					\
-                           int ll, int lc, const char *lfile)					\
-			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
+                           int fl, int fc, const char *ffile, long int forder,			\
+                           int ll, int lc, const char *lfile, long int lorder)			\
+			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   this->ref1 = ref1;										\
   this->ref2 = ref2;										\
   this->ref3 = ref3;										\
@@ -193,9 +195,9 @@
 			   symbol_c *ref2,							\
 			   symbol_c *ref3,							\
 			   symbol_c *ref4,							\
-                           int fl, int fc, const char *ffile,					\
-                           int ll, int lc, const char *lfile)					\
-			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
+                           int fl, int fc, const char *ffile, long int forder,			\
+                           int ll, int lc, const char *lfile, long int lorder)			\
+			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   this->ref1 = ref1;										\
   this->ref2 = ref2;										\
   this->ref3 = ref3;										\
@@ -210,9 +212,9 @@
 			   symbol_c *ref3,							\
 			   symbol_c *ref4,							\
 			   symbol_c *ref5,							\
-                           int fl, int fc, const char *ffile,					\
-                           int ll, int lc, const char *lfile)					\
-			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
+                           int fl, int fc, const char *ffile, long int forder,			\
+                           int ll, int lc, const char *lfile, long int lorder)			\
+			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   this->ref1 = ref1;										\
   this->ref2 = ref2;										\
   this->ref3 = ref3;										\
@@ -230,9 +232,9 @@
 			   symbol_c *ref4,							\
 			   symbol_c *ref5,							\
 			   symbol_c *ref6,							\
-                           int fl, int fc, const char *ffile,					\
-                           int ll, int lc, const char *lfile)					\
-			  :symbol_c(fl, fc, ffile, ll, lc, lfile) {				\
+                           int fl, int fc, const char *ffile, long int forder,			\
+                           int ll, int lc, const char *lfile, long int lorder)			\
+			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   this->ref1 = ref1;										\
   this->ref2 = ref2;										\
   this->ref3 = ref3;										\
--- a/absyntax/absyntax.hh	Thu Apr 14 17:35:25 2011 +0100
+++ b/absyntax/absyntax.hh	Thu Apr 14 18:12:59 2011 +0100
@@ -71,14 +71,16 @@
     int first_line;
     int first_column;
     const char *first_file;  /* filename referenced by first line/column */
+    long int first_order;    /* relative order in which it is read by lexcial analyser */
     int last_line;
     int last_column;
     const char *last_file;  /* filename referenced by last line/column */
+    long int last_order;    /* relative order in which it is read by lexcial analyser */
 
   public:
     /* default constructor */
-    symbol_c(int fl = 0, int fc = 0, const char *ffile = NULL /* filename */,
-             int ll = 0, int lc = 0, const char *lfile = NULL /* filename */
+    symbol_c(int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */
+             int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0  /* order in which it is read by lexcial analyser */
             );
 
     /* default destructor */
@@ -96,8 +98,8 @@
 
   public:
     token_c(const char *value, 
-            int fl = 0, int fc = 0, const char *ffile = NULL /* filename */,
-            int ll = 0, int lc = 0, const char *lfile = NULL /* filename */
+            int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */
+            int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0  /* order in which it is read by lexcial analyser */
            );
 };
 
@@ -109,13 +111,13 @@
     symbol_c **elements;
 
   public:
-    list_c(int fl = 0, int fc = 0, const char *ffile = NULL /* filename */,
-           int ll = 0, int lc = 0, const char *lfile = NULL /* filename */
+    list_c(int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */
+           int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0  /* order in which it is read by lexcial analyser */
           );
 
     list_c(symbol_c *elem, 
-	   int fl = 0, int fc = 0, const char *ffile = NULL /* filename */,
-           int ll = 0, int lc = 0, const char *lfile = NULL /* filename */
+           int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */
+           int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0  /* order in which it is read by lexcial analyser */
           );
      /* insert a new element */
     virtual void add_element(symbol_c *elem);
@@ -128,11 +130,11 @@
 class class_name_c:	public list_c {											\
   public:														\
     class_name_c(													\
-                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, 					\
-                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */);					\
+                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0,			\
+                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0);			\
     class_name_c(symbol_c *elem, 											\
-                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, 					\
-                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */);					\
+                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0,			\
+                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0);			\
     virtual void *accept(visitor_c &visitor);										\
 };
 
@@ -141,8 +143,8 @@
 class class_name_c: 	public token_c {										\
   public:														\
     class_name_c(const char *value, 											\
-                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, 					\
-                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */);					\
+                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0,			\
+                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0);			\
     virtual void *accept(visitor_c &visitor);										\
 };
 
@@ -151,8 +153,8 @@
 class class_name_c: public symbol_c {											\
   public:														\
     class_name_c(		 											\
-                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, 					\
-                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */);					\
+                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0,			\
+                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0);			\
     virtual void *accept(visitor_c &visitor);										\
 };
 
@@ -163,8 +165,8 @@
     symbol_c *ref1;													\
   public:														\
     class_name_c(symbol_c *ref1,											\
-                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, 					\
-                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */);					\
+                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0,			\
+                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0);			\
     virtual void *accept(visitor_c &visitor);										\
 };
 
@@ -177,8 +179,8 @@
   public:														\
     class_name_c(symbol_c *ref1,											\
 		 symbol_c *ref2 = NULL,											\
-                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, 					\
-                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */);					\
+                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0,			\
+                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0);			\
     virtual void *accept(visitor_c &visitor);										\
 };
 
@@ -193,8 +195,8 @@
     class_name_c(symbol_c *ref1,											\
 		 symbol_c *ref2,											\
 		 symbol_c *ref3,											\
-                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, 					\
-                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */);					\
+                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0,			\
+                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0);			\
     virtual void *accept(visitor_c &visitor);										\
 };
 
@@ -211,8 +213,8 @@
 		 symbol_c *ref2,											\
 		 symbol_c *ref3,											\
 		 symbol_c *ref4 = NULL,											\
-                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, 					\
-                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */);					\
+                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0,			\
+                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0);			\
     virtual void *accept(visitor_c &visitor);										\
 };
 
@@ -231,8 +233,8 @@
 		 symbol_c *ref3,											\
 		 symbol_c *ref4,											\
 		 symbol_c *ref5,											\
-                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, 					\
-                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */);					\
+                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0,			\
+                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0);			\
     virtual void *accept(visitor_c &visitor);										\
 };
 
@@ -253,8 +255,8 @@
 		 symbol_c *ref4,											\
 		 symbol_c *ref5,											\
 		 symbol_c *ref6 = NULL,											\
-                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, 					\
-                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */);					\
+                 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0,			\
+                 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0);			\
     virtual void *accept(visitor_c &visitor);										\
 };
 
--- a/stage1_2/iec.flex	Thu Apr 14 17:35:25 2011 +0100
+++ b/stage1_2/iec.flex	Thu Apr 14 18:12:59 2011 +0100
@@ -179,18 +179,33 @@
       result = YY_NULL;\
     }
 
+
+/* A counter to track the order by which each token is processed.
+ * NOTE: This counter is not exactly linear (i.e., it does not get incremented by 1 for each token).
+ *       i.e.. it may get incremented by more than one between two consecutive tokens.
+ *       This is due to the fact that the counter gets incremented every 'user action' in flex,
+ *       however not every user action will result in a token being passed to bison.
+ *       Nevertheless this is still OK, as we are only interested in the relative
+ *       ordering of tokens...
+ */
+static long int current_order = 0;
+
+
 /* Macro that is executed for every action.
  * We use it to pass the location of the token
  * back to the bison parser...
  */
 #define YY_USER_ACTION {\
-	yylloc.first_line = current_tracking->lineNumber;\
-	yylloc.first_column = current_tracking->currentTokenStart;\
-	yylloc.first_file = current_filename;\
-	yylloc.last_line = current_tracking->lineNumber;\
-	yylloc.last_column = current_tracking->currentChar - 1;\
-	yylloc.last_file = current_filename;\
-	current_tracking->currentTokenStart = current_tracking->currentChar;\
+	yylloc.first_line = current_tracking->lineNumber;			\
+	yylloc.first_column = current_tracking->currentTokenStart;		\
+	yylloc.first_file = current_filename;					\
+	yylloc.first_order = current_order;					\
+	yylloc.last_line = current_tracking->lineNumber;			\
+	yylloc.last_column = current_tracking->currentChar - 1;			\
+	yylloc.last_file = current_filename;					\
+	yylloc.last_order = current_order;					\
+	current_tracking->currentTokenStart = current_tracking->currentChar;	\
+	current_order++;							\
 	}
 
 
--- a/stage1_2/iec.y	Thu Apr 14 17:35:25 2011 +0100
+++ b/stage1_2/iec.y	Thu Apr 14 18:12:59 2011 +0100
@@ -116,9 +116,9 @@
 /* Macros used to pass the line and column locations when
  * creating a new object for the abstract syntax tree.
  */
-#define locloc(foo) foo.first_line, foo.first_column, foo.first_file, foo.last_line, foo.last_column, foo.last_file
-#define   locf(foo) foo.first_line, foo.first_column, foo.first_file
-#define   locl(foo) foo.last_line,  foo.last_column, foo.last_file
+#define locloc(foo) foo.first_line, foo.first_column, foo.first_file, foo.first_order, foo.last_line, foo.last_column, foo.last_file, foo.last_order
+#define   locf(foo) foo.first_line, foo.first_column, foo.first_file, foo.first_order
+#define   locl(foo) foo.last_line,  foo.last_column,  foo.last_file,  foo.last_order
 
 /* Redefine the default action to take for each rule, so that the filenames are correctly processed... */
 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
@@ -128,9 +128,11 @@
                (Current).first_line   = YYRHSLOC(Rhs, 1).first_line;         \
                (Current).first_column = YYRHSLOC(Rhs, 1).first_column;       \
                (Current).first_file   = YYRHSLOC(Rhs, 1).first_file;         \
+               (Current).first_order  = YYRHSLOC(Rhs, 1).first_order;        \
                (Current).last_line    = YYRHSLOC(Rhs, N).last_line;          \
                (Current).last_column  = YYRHSLOC(Rhs, N).last_column;        \
                (Current).last_file    = YYRHSLOC(Rhs, 1).last_file;          \
+               (Current).last_order   = YYRHSLOC(Rhs, 1).last_order;         \
              }                                                               \
            else                                                              \
              {                                                               \
@@ -140,6 +142,8 @@
                  YYRHSLOC(Rhs, 0).last_column;                               \
                (Current).first_file   = (Current).last_file   =              \
                  YYRHSLOC(Rhs, 0).last_file;                                 \
+               (Current).first_order  = (Current).last_order  =              \
+                 YYRHSLOC(Rhs, 0).last_order;                                \
              }                                                               \
          while (0)
 
@@ -205,9 +209,11 @@
 void print_err_msg(int first_line,
                    int first_column,
                    const char *first_filename,
+                   long int first_order,
                    int last_line,
                    int last_column,
                    const char *last_filename,
+                   long int last_order,
                    const char *additional_error_msg);
 %}
 
@@ -245,12 +251,14 @@
  */
 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
   typedef struct {
-    int first_line;
-    int first_column;
+    int         first_line;
+    int         first_column;
     const char *first_file;
-    int last_line;
-    int last_column;
+    long int    first_order;
+    int         last_line;
+    int         last_column;
     const char *last_file;
+    long int    last_order;
   } yyltype__local;
   #define YYLTYPE yyltype__local
 #endif
@@ -7892,9 +7900,11 @@
 void print_err_msg(int first_line,
                    int first_column,
                    const char *first_filename,
+                   long int first_order,
                    int last_line,
                    int last_column,
                    const char *last_filename,
+                   long int last_order,
                    const char *additional_error_msg) {
 
   const char *unknown_file = "<unknown_file>";
@@ -8000,9 +8010,11 @@
                          il_operator->first_line,
                          il_operator->first_column,
                          il_operator->first_file,
+                         il_operator->first_order,
                          il_operator->last_line,
                          il_operator->last_column,
-                         il_operator->last_file
+                         il_operator->last_file,
+                         il_operator->last_order
                         );
   free(il_operator);
   return res;
--- a/stage3/visit_expression_type.cc	Thu Apr 14 17:35:25 2011 +0100
+++ b/stage3/visit_expression_type.cc	Thu Apr 14 18:12:59 2011 +0100
@@ -43,25 +43,8 @@
 #include <string.h>
 #include <strings.h>
 
+
 /*
-static inline symbol_c * FIRST_(symbol_c *symbol1, symbol_c *symbol2) {
-  if (symbol1->first_file  == symbol2->first_file)   return symbol1;
-
-  if (symbol1->first_line   < symbol2->first_line)   return symbol1;
-  if (symbol1->first_line   > symbol2->first_line)   return symbol2;
-  if (symbol1->first_column < symbol2->first_column) return symbol1;
-  if (symbol1->first_column > symbol2->first_column) return symbol2;
-  return symbol1;
-}
-
-#define FIRST_(symbol1, symbol2) (((symbol1)->last_file   == (symbol2)->first_file)   ? (symbol1) :    \
-                                  ((symbol1)->first_file  == (symbol2)->last_file)    ? (symbol2) :    \
-                                  ((symbol1)->first_line   < (symbol2)->first_line)   ? (symbol1) :    \
-                                  ((symbol1)->first_line   > (symbol2)->first_line)   ? (symbol2) :    \
-                                  ((symbol1)->first_column < (symbol2)->first_column) ? (symbol1) :    \
-                                  ((symbol1)->first_column > (symbol2)->first_column) ? (symbol2) :    \
-                                  (symbol1))
-*/
 #define FIRST_(symbol1, symbol2) (((symbol1)->first_line   < (symbol2)->first_line)   ? (symbol1) :    \
                                   ((symbol1)->first_line   > (symbol2)->first_line)   ? (symbol2) :    \
                                   ((symbol1)->first_column < (symbol2)->first_column) ? (symbol1) :    \
@@ -73,6 +56,9 @@
                                   ((symbol1)->last_column  < (symbol2)->last_column)  ? (symbol2) :    \
                                   ((symbol1)->last_column  > (symbol2)->last_column)  ? (symbol1) :    \
                                   (symbol1))
+*/
+#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order)   ? (symbol1) : (symbol2))
+#define  LAST_(symbol1, symbol2) (((symbol1)->last_order  > (symbol2)->last_order)    ? (symbol1) : (symbol2))
 
 #define STAGE3_ERROR(symbol1, symbol2, msg) {                                          \
     fprintf(stderr, "%s:(%d:%d) .. %s(%d:%d): %s\n",                                   \