ref: efdd42c6a80945c78b396054ebfdbd4fd9f1f1a6
parent: c1a97f6541b6a1b0e5144e0bfa4c37ecaf0f7e85
author: Antonio Niño Díaz <antonio_nd@outlook.com>
date: Fri Mar 30 19:50:57 EDT 2018
Simplify parsing of variable-length lists This change removes 2 reduce/reduce conflicts in the parser while preserving the behaviour of the rules. Note that now each list with empty elements will only print a warning per line. Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
--- a/src/asm/asmy.y
+++ b/src/asm/asmy.y
@@ -28,6 +28,7 @@
#include "common.h"
#include "linkdefs.h"
+uint32_t nListCountEmpty;
char *tzNewMacro;
uint32_t ulNewMacroSize;
@@ -579,10 +580,12 @@
/* Note: The lexer adds '\n' at the end of the input */
lines : /* empty */
- | lines line '\n' {
- nLineNo += 1;
- nTotalLines += 1;
- }
+ | lines {
+ nListCountEmpty = 0;
+ } line '\n' {
+ nLineNo += 1;
+ nTotalLines += 1;
+ }
;
line : label
@@ -802,16 +805,28 @@
}
;
-db : T_POP_DB constlist_8bit_entry comma constlist_8bit
- | T_POP_DB constlist_8bit_entry_single
+db : T_POP_DB constlist_8bit_entry comma constlist_8bit {
+ if ((nPass == 1) && (nListCountEmpty > 0)) {
+ warning("Empty entry in list of 8-bit elements (treated as 0).");
+ }
+ }
+ | T_POP_DB constlist_8bit_entry
;
-dw : T_POP_DW constlist_16bit_entry comma constlist_16bit
- | T_POP_DW constlist_16bit_entry_single
+dw : T_POP_DW constlist_16bit_entry comma constlist_16bit {
+ if ((nPass == 1) && (nListCountEmpty > 0)) {
+ warning("Empty entry in list of 16-bit elements (treated as 0).");
+ }
+ }
+ | T_POP_DW constlist_16bit_entry
;
-dl : T_POP_DL constlist_32bit_entry comma constlist_32bit
- | T_POP_DL constlist_32bit_entry_single
+dl : T_POP_DL constlist_32bit_entry comma constlist_32bit {
+ if ((nPass == 1) && (nListCountEmpty > 0)) {
+ warning("Empty entry in list of 32-bit elements (treated as 0).");
+ }
+ }
+ | T_POP_DL constlist_32bit_entry
;
purge : T_POP_PURGE {
@@ -1028,8 +1043,7 @@
constlist_8bit_entry : /* empty */
{
out_Skip(1);
- if (nPass == 1)
- warning("Empty entry in list of 8-bit elements (treated as 0).");
+ nListCountEmpty++;
}
| const_8bit
{
@@ -1045,24 +1059,6 @@
}
;
-constlist_8bit_entry_single : /* empty */
- {
- out_Skip(1);
- }
- | const_8bit
- {
- out_RelByte(&$1);
- }
- | string
- {
- char *s = $1;
- int32_t length = charmap_Convert(&s);
-
- out_AbsByteGroup(s, length);
- free(s);
- }
-;
-
constlist_16bit : constlist_16bit_entry
| constlist_16bit_entry comma constlist_16bit
;
@@ -1070,8 +1066,7 @@
constlist_16bit_entry : /* empty */
{
out_Skip(2);
- if (nPass == 1)
- warning("Empty entry in list of 16-bit elements (treated as 0).");
+ nListCountEmpty++;
}
| const_16bit
{
@@ -1079,16 +1074,6 @@
}
;
-constlist_16bit_entry_single : /* empty */
- {
- out_Skip(2);
- }
- | const_16bit
- {
- out_RelWord(&$1);
- }
-;
-
constlist_32bit : constlist_32bit_entry
| constlist_32bit_entry comma constlist_32bit
;
@@ -1096,18 +1081,7 @@
constlist_32bit_entry : /* empty */
{
out_Skip(4);
- if (nPass == 1)
- warning("Empty entry in list of 32-bit elements (treated as 0).");
- }
- | relocconst
- {
- out_RelLong(&$1);
- }
-;
-
-constlist_32bit_entry_single : /* empty */
- {
- out_Skip(4);
+ nListCountEmpty++;
}
| relocconst
{