shithub: rgbds

Download patch

ref: 5b98beec8b2ff81c8f25229d9d406fd2ec1c1f60
parent: 6662c86d5e886e08aae178a1f9748a7339e0658e
author: ISSOtm <eldredhabert0@gmail.com>
date: Sat Mar 14 12:22:33 EDT 2020

Use left recursion instead of right

> Any kind of sequence can be defined using either left recursion or right
> recursion, but you should always use left recursion, because it can
> parse a sequence of any number of elements with bounded stack space.
https://www.gnu.org/software/bison/manual/html_node/Recursion.html

--- a/src/asm/asmy.y
+++ b/src/asm/asmy.y
@@ -775,7 +775,7 @@
 ;
 
 opt_list	: opt_list_entry
-		| opt_list_entry ',' opt_list
+		| opt_list ',' opt_list_entry
 ;
 
 opt_list_entry	: T_STRING		{ opt_Parse($1); }
@@ -883,6 +883,7 @@
 		}
 ;
 
+/* Authorize empty entries if there is only one */
 db		: T_POP_DB constlist_8bit_entry ',' constlist_8bit {
 			if (nListCountEmpty > 0)
 				warning(WARNING_EMPTY_ENTRY, "Empty entry in list of 8-bit elements (treated as padding).");
@@ -912,7 +913,7 @@
 ;
 
 purge_list	: purge_list_entry
-		| purge_list_entry ',' purge_list
+		| purge_list ',' purge_list_entry
 ;
 
 purge_list_entry : scoped_id	{ sym_Purge($1); }
@@ -931,7 +932,7 @@
 ;
 
 export_list	: export_list_entry
-		| export_list_entry ',' export_list
+		| export_list ',' export_list_entry
 ;
 
 export_list_entry : scoped_id	{ sym_Export($1); }
@@ -1066,7 +1067,7 @@
 ;
 
 constlist_8bit	: constlist_8bit_entry
-		| constlist_8bit_entry ',' constlist_8bit
+		| constlist_8bit ',' constlist_8bit_entry
 ;
 
 constlist_8bit_entry : /* empty */ {
@@ -1084,7 +1085,7 @@
 ;
 
 constlist_16bit : constlist_16bit_entry
-		| constlist_16bit_entry ',' constlist_16bit
+		| constlist_16bit ',' constlist_16bit_entry
 ;
 
 constlist_16bit_entry : /* empty */ {
@@ -1095,7 +1096,7 @@
 ;
 
 constlist_32bit : constlist_32bit_entry
-		| constlist_32bit_entry ',' constlist_32bit
+		| constlist_32bit ',' constlist_32bit_entry
 ;
 
 constlist_32bit_entry : /* empty */ {