From bc72a6621f9cb7c68ad5b9bbf6db749e6753f1c4 Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Thu, 20 Jul 2023 22:41:47 +0200 Subject: [PATCH] Simplify null handling a bit in alternative code generation --- .../GenerateAlternativeCodeForParser.java | 21 +++---------------- .../resources/org/sablecc/sablecc/parser.txt | 5 ----- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java b/src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java index d350a2c..ee69c03 100644 --- a/src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java +++ b/src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java @@ -80,7 +80,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter { if("null".equals(typeName)) { - throw new IllegalArgumentException("Null values have no variable name"); + return "null"; } else if(typeName.startsWith("L")) { @@ -156,15 +156,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter position = CG.getTermNumbers().get(term); - if("null".equals(type_name)) - { - macros.apply(file, "ParserNewBodyListAddNull", null); - } - else - { - macros.apply(file, "ParserNewBodyListAdd", new String[] {getVariableName(type_name, position)}); - } - + macros.apply(file, "ParserNewBodyListAdd", new String[] {getVariableName(type_name, position)}); } if (popCount > 0) { // The nodeArrayList variables are numbered starting at 1, so the first popped variable has the number popCount and not popCount-1. @@ -344,14 +336,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter type_name = lookupInternalTypeName(term); position = CG.getTermNumbers().get(term); - if(type_name.equals("null")) - { - macros.apply(file, "ParserNewBodyParam", new String[] {isNotTheFirstParam+"null"}); - } - else - { - macros.apply(file, "ParserNewBodyParam", new String[] {isNotTheFirstParam + getVariableName(type_name, position)}); - } + macros.apply(file, "ParserNewBodyParam", new String[] {isNotTheFirstParam + getVariableName(type_name, position)}); isNotTheFirstParam = ", "; } diff --git a/src/main/resources/org/sablecc/sablecc/parser.txt b/src/main/resources/org/sablecc/sablecc/parser.txt index 82811fe..ea838ea 100644 --- a/src/main/resources/org/sablecc/sablecc/parser.txt +++ b/src/main/resources/org/sablecc/sablecc/parser.txt @@ -386,11 +386,6 @@ Macro:ParserNewBodyListAdd $ -Macro:ParserNewBodyListAddNull - nodeList.add(null); - -$ - Macro:ParserNewCheck checkResult(nodeList.get(0), nodeArrayList1, nodeArrayList$0$); -- GitLab