diff --git a/src/main/java/org/sablecc/sablecc/GenParser.java b/src/main/java/org/sablecc/sablecc/GenParser.java index 20592f25f0f079a03a58815281950c9aa3c77683..98bcc81d5b59ba2fbad6f9f45743472fa86fe8f6 100644 --- a/src/main/java/org/sablecc/sablecc/GenParser.java +++ b/src/main/java/org/sablecc/sablecc/GenParser.java @@ -69,11 +69,6 @@ public class GenParser extends DepthFirstAdapter private String firstProductionName; private boolean processInlining; private boolean prettyPrinting; - private boolean grammarHasTransformations; - - // This boolean is used to check weither the filter() method in class Parser.java - // should be present or not. - private boolean activateFilter = true; //This tree-walker field generate the code of parsing and construction of the AST. GenerateAlternativeCodeForParser aParsedAltAdapter; @@ -89,15 +84,13 @@ public class GenParser extends DepthFirstAdapter private Map<String, Node> alts; public GenParser(ResolveIds ids, ResolveAltIds altIds, ResolveTransformIds transformIds, - String firstProductionName, boolean processInlining, boolean prettyPrinting, - boolean grammarHasTransformations) + String firstProductionName, boolean processInlining, boolean prettyPrinting) { this.ids = ids; this.altIds = altIds; this.transformIds = transformIds; this.processInlining = processInlining; this.prettyPrinting = prettyPrinting; - this.grammarHasTransformations = grammarHasTransformations; AET = new AlternativeElementTypes(ids); CG = new ComputeCGNomenclature(ids, transformIds.getProdTransformIds()); @@ -232,11 +225,6 @@ public class GenParser extends DepthFirstAdapter } catch(ConflictException ce) { - if(activateFilter) - { - activateFilter = false; - } - //Here, we are trying to inline the grammar with production imply in the conflict. if(processInlining) { @@ -375,37 +363,14 @@ public class GenParser extends DepthFirstAdapter macros.apply(file, "ParserHeader", new String[] {ids.pkgNameDot}); - if(activateFilter && !grammarHasTransformations) - { - macros.apply(file, "ParserNoInliningPushHeader"); - macros.apply(file, "ParserCommon", new String[] {", true", ", false"}); - } - else - { - macros.apply(file, "ParserInliningPushHeader"); - macros.apply(file, "ParserCommon", new String[] {"", ""}); - } - //this loop generates the code for all possible reductions and the type of //the node needed to be created at a local point. for(int i = 0; i < (productions.length - 1); i++) { - if(activateFilter && !grammarHasTransformations) - { - macros.apply(file, "ParserNoInliningReduce", new String[] { - "" + productions[i].index, - "" + productions[i].leftside, - "" + (productions[i].name.startsWith("ANonTerminal$") || - productions[i].name.startsWith("ATerminal$")), - productions[i].name}); - } - else - { - macros.apply(file, "ParserInliningReduce", new String[] { - "" + productions[i].index, - "" + productions[i].leftside, - productions[i].name}); - } + macros.apply(file, "ParserParseReduce", new String[] { + "" + productions[i].index, + "" + productions[i].leftside, + productions[i].name}); } macros.apply(file, "ParserParseTail", new String[] {firstProductionName}); diff --git a/src/main/java/org/sablecc/sablecc/SableCC.java b/src/main/java/org/sablecc/sablecc/SableCC.java index be66d8924e2b682897ad3c72e2e2fd6b5214631a..9524c41017ee9f5ad42567baa3a271c3275b4351 100644 --- a/src/main/java/org/sablecc/sablecc/SableCC.java +++ b/src/main/java/org/sablecc/sablecc/SableCC.java @@ -197,15 +197,11 @@ public class SableCC { tree = new Parser(new Lexer(reader)).parse(); } - boolean hasTransformations = false; - if (((AGrammar) tree.getPGrammar()).getAst() == null) { System.out .println("Adding productions and alternative of section AST."); // AddAstProductions astProductions = new AddAstProductions(); tree.apply(new AddAstProductions()); - } else { - hasTransformations = true; } System.out.println("Verifying identifiers."); @@ -269,8 +265,7 @@ public class SableCC { try { System.out.println("Generating the parser."); tree.apply(new GenParser(ids, alt_ids, transform_ids, ast_ids - .getFirstAstProduction(), processInlining, prettyPrinting, - hasTransformations)); + .getFirstAstProduction(), processInlining, prettyPrinting)); } catch (RuntimeException e) { System.out.println(e.getMessage()); throw e; diff --git a/src/main/java/org/sablecc/sablecc/parser/Parser.java b/src/main/java/org/sablecc/sablecc/parser/Parser.java index 6610247258416913ea7f1c4fc6b90d186dcc5e4d..195cd557c217120238db4f8256aece28c675294a 100644 --- a/src/main/java/org/sablecc/sablecc/parser/Parser.java +++ b/src/main/java/org/sablecc/sablecc/parser/Parser.java @@ -23,8 +23,6 @@ import org.sablecc.sablecc.node.*; @SuppressWarnings({"unchecked", "unused"}) public class Parser implements IParser { - protected List<Object> nodeList; - private final Lexer lexer; private final ListIterator<State> stack = new LinkedList<State>().listIterator(); private final TokenIndex converter = new TokenIndex(); @@ -105,7 +103,7 @@ public class Parser implements IParser return (PositionedNode)last; } - private void push(int numstate, List<Object> listNode) throws ParserException, LexerException, IOException + private void push(int numstate, List<Object> listNode) { if(!this.stack.hasNext()) { diff --git a/src/main/resources/org/sablecc/sablecc/parser.txt b/src/main/resources/org/sablecc/sablecc/parser.txt index e436a95587ddf98b7cb6ea92683b66b747a188b3..274a2d7ba77a839635bbd7fbd6a4c136f6aaaa2f 100644 --- a/src/main/resources/org/sablecc/sablecc/parser.txt +++ b/src/main/resources/org/sablecc/sablecc/parser.txt @@ -31,8 +31,6 @@ import $0$node.*; @SuppressWarnings({"unchecked", "unused"}) public class Parser implements IParser { - protected List<Object> nodeList; - private final Lexer lexer; private final ListIterator<State> stack = new LinkedList<State>().listIterator(); private final TokenIndex converter = new TokenIndex(); @@ -113,11 +111,7 @@ public class Parser implements IParser return (PositionedNode)last; } -$ - -Macro:ParserInliningPushHeader - - private void push(int numstate, List<Object> listNode) throws ParserException, LexerException, IOException + private void push(int numstate, List<Object> listNode) { if(!this.stack.hasNext()) { @@ -130,37 +124,6 @@ Macro:ParserInliningPushHeader s.nodes = listNode; } - -$ - -Macro:ParserNoInliningPushHeader - protected void filter() throws ParserException, LexerException, IOException - {} - - private void push(int numstate, List<Object> listNode, boolean hidden) throws ParserException, LexerException, IOException - { - this.nodeList = listNode; - - if(!hidden) - { - filter(); - } - - if(!this.stack.hasNext()) - { - this.stack.add(new State(numstate, this.nodeList)); - return; - } - - State s = this.stack.next(); - s.state = numstate; - s.nodes = this.nodeList; - } - - -$ - -Macro:ParserCommon private int goTo(int index) { int state = state(); @@ -213,7 +176,7 @@ Macro:ParserCommon public Start parse() throws ParserException, LexerException, IOException { - push(0, null$0$); + push(0, null); while(true) { Token lastToken = this.lexer.peek(); @@ -259,7 +222,7 @@ Macro:ParserCommon case SHIFT: { List<Object> list = Collections.<Object>singletonList(this.lexer.next()); - push(destination, list$1$); + push(destination, list); } break; case REDUCE: @@ -268,7 +231,7 @@ Macro:ParserCommon $ -Macro:ParserInliningReduce +Macro:ParserParseReduce case $0$: /* reduce $2$ */ { List<Object> list = new$0$(); @@ -278,16 +241,6 @@ Macro:ParserInliningReduce $ -Macro:ParserNoInliningReduce - case $0$: /* reduce $3$ */ - { - List<Object> list = new$0$(); - push(goTo($1$), list, $2$); - } - break; - -$ - Macro:ParserParseTail } break;