Skip to content

Commit

Permalink
antlr 4.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Thome committed Dec 15, 2017
1 parent cbcc33c commit 5cad915
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public void load(MemoryTupleSet mset) {
/**
* do the compilation for the antlr artifacts
* @param units string code generation pipeline
* @param oprov compiler option provider
* @throws CompilationErrorException if the compilation was not successful
*/
public void compile(Set<CunitProvider> units, CompilerOptionsProvider
oprov)
public void compile(Set<CunitProvider> units, CompilerOptionsProvider oprov)
throws
CompilationErrorException {
JavaCompiler javac = new EclipseCompiler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public DefaultTreeListener() {

/**
* constructor
* @param includeTerminals include terminal nodes in resulting tree
*/
public DefaultTreeListener(boolean includeTerminals) {
this(x -> !x.isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@

package org.snt.inmemantlr.tool;

import org.antlr.v4.analysis.AnalysisPipeline;
import org.antlr.v4.automata.ATNFactory;
import org.antlr.v4.automata.LexerATNFactory;
import org.antlr.v4.automata.ParserATNFactory;
import org.antlr.v4.codegen.CodeGenPipeline;
import org.antlr.v4.codegen.CodeGenerator;
import org.antlr.v4.misc.Graph;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.semantics.SemanticPipeline;
import org.antlr.v4.tool.*;
import org.antlr.v4.tool.ast.GrammarAST;
import org.antlr.v4.tool.ast.GrammarASTErrorNode;
Expand Down Expand Up @@ -347,4 +354,56 @@ public void exit(int e) {
System.exit(e);
}


/**
* this method is taken from the superclass
* @param g grammar to process
* @param gencode flag to switch on codegeneration
*/
public void processNonCombinedGrammar(Grammar g, boolean gencode) {
if ( g.ast==null || g.ast.hasErrors ) return;
if ( internalOption_PrintGrammarTree ) System.out.println(g.ast.toStringTree());

boolean ruleFail = checkForRuleIssues(g);
if ( ruleFail ) return;

int prevErrors = errMgr.getNumErrors();
// MAKE SURE GRAMMAR IS SEMANTICALLY CORRECT (FILL IN GRAMMAR OBJECT)
SemanticPipeline sem = new SemanticPipeline(g);
sem.process();

String language = g.getOptionString("language");
if ( !CodeGenerator.targetExists(language) ) {
errMgr.toolError(ErrorType.CANNOT_CREATE_TARGET_GENERATOR, language);
return;
}

if ( errMgr.getNumErrors()>prevErrors ) return;

// BUILD ATN FROM AST
ATNFactory factory;
if ( g.isLexer() ) factory = new LexerATNFactory((LexerGrammar)g);
else factory = new ParserATNFactory(g);
g.atn = factory.createATN();

if ( generate_ATN_dot ) generateATNs(g);

//if ( g.tool.getNumErrors()==0 ) generateInterpreterData(g);

// PERFORM GRAMMAR ANALYSIS ON ATN: BUILD DECISION DFAs
AnalysisPipeline anal = new AnalysisPipeline(g);
anal.process();

//if ( generate_DFA_dot ) generateDFAs(g);

if ( g.tool.getNumErrors()>prevErrors ) return;

// GENERATE CODE
if ( gencode ) {
CodeGenPipeline gen = new CodeGenPipeline(g);
gen.process();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static String getStringFromStream(InputStream is) {
* writes string to file
* @param string string to write
* @param file file to which the string shall be written
* @throws FileExistsException
* @throws FileExistsException is thrown if file already exists
*/
public static void writeStringToFile(String string, String file) throws
FileExistsException {
Expand Down
2 changes: 1 addition & 1 deletion inmemantlr-tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<dependency>
<groupId>com.github.julianthome</groupId>
<artifactId>inmemantlr-api</artifactId>
<version>1.4-SNAPSHOT</version>
<version>1.4</version>
</dependency>

</dependencies>
Expand Down

0 comments on commit 5cad915

Please sign in to comment.