From db582cdaa04a1f967829e93f98f24bb3ce5dd594 Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Thu, 16 May 2024 15:31:23 +0200 Subject: [PATCH] Inline a few local variables in generated Parser --- .../org/sablecc/sablecc/parser/Parser.java | 19 ++++++++----------- .../resources/org/sablecc/sablecc/parser.txt | 19 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/sablecc/sablecc/parser/Parser.java b/src/main/java/org/sablecc/sablecc/parser/Parser.java index 1f17b9a..9399991 100644 --- a/src/main/java/org/sablecc/sablecc/parser/Parser.java +++ b/src/main/java/org/sablecc/sablecc/parser/Parser.java @@ -178,11 +178,9 @@ public class Parser implements IParser switch(action) { case SHIFT: - { - List<?> list = Collections.singletonList(this.lexer.next()); - push(destination, list); - } - break; + push(destination, Collections.singletonList(this.lexer.next())); + break; + case REDUCE: switch(destination) { @@ -1804,13 +1802,12 @@ public class Parser implements IParser throw new ParserException(lastToken, "[" + lastToken.getLine() + "," + lastToken.getPos() + "] Internal parser error: invalid action table REDUCE destination " + destination + ", current state " + state()); } break; + case ACCEPT: - { - EOF node2 = (EOF) this.lexer.next(); - PGrammar node1 = (PGrammar) pop().get(0); - Start node = new Start(node1, node2); - return node; - } + EOF eof = (EOF) this.lexer.next(); + PGrammar top = (PGrammar) pop().get(0); + return new Start(top, eof); + case ERROR: throw new ParserException(lastToken, "[" + lastToken.getLine() + "," + lastToken.getPos() + "] " , diff --git a/src/main/resources/org/sablecc/sablecc/parser.txt b/src/main/resources/org/sablecc/sablecc/parser.txt index 3d28b80..1c23fcf 100644 --- a/src/main/resources/org/sablecc/sablecc/parser.txt +++ b/src/main/resources/org/sablecc/sablecc/parser.txt @@ -186,11 +186,9 @@ public class Parser implements IParser switch(action) { case SHIFT: - { - List<?> list = Collections.singletonList(this.lexer.next()); - push(destination, list); - } - break; + push(destination, Collections.singletonList(this.lexer.next())); + break; + case REDUCE: switch(destination) { @@ -212,13 +210,12 @@ Macro:ParserParseTail throw new ParserException(lastToken, "[" + lastToken.getLine() + "," + lastToken.getPos() + "] Internal parser error: invalid action table REDUCE destination " + destination + ", current state " + state()); } break; + case ACCEPT: - { - EOF node2 = (EOF) this.lexer.next(); - $0$ node1 = ($0$) pop().get(0); - Start node = new Start(node1, node2); - return node; - } + EOF eof = (EOF) this.lexer.next(); + $0$ top = ($0$) pop().get(0); + return new Start(top, eof); + case ERROR: throw new ParserException(lastToken, "[" + lastToken.getLine() + "," + lastToken.getPos() + "] " , -- GitLab