use of org.antlr.v4.runtime.CharStream in project claw-compiler by C2SM-RCM.
the class FortranLineBreaksFinder method run.
public List<LineBreakInfo> run(InputStream input) throws FortranSyntaxException, IOException {
lexer.reset();
parser.reset();
lexerErrorListener.reset();
parserErrorListener.reset();
CharStream chrStrm = CharStreams.fromStream(input, StandardCharsets.US_ASCII);
lexer.setInputStream(chrStrm);
CommonTokenStream tokStrm = new CommonTokenStream(lexer);
parser.setInputStream(tokStrm);
parser.setBuildParseTree(true);
ParseTree tree = null;
try {
tree = parser.root();
} catch (CancellationException e) {
}
if (lexerErrorListener.error() != null) {
throw lexerErrorListener.error();
}
if (parserErrorListener.error() != null) {
throw parserErrorListener.error();
}
ParseTreeWalker walker = new ParseTreeWalker();
Listener listener = new Listener();
try {
walker.walk(listener, tree);
} catch (CancellationException e) {
}
if (listener.error() != null) {
throw listener.error();
}
return listener.lineBreaks;
}
use of org.antlr.v4.runtime.CharStream in project claw-compiler by C2SM-RCM.
the class PreprocessorOutputScanner method run.
/**
* Only absolute paths are recognized, so the preprocessor should be given only
* absolute paths to include directories and source file.
*/
public Set<Path> run(InputStream input, OutputStream nonPPOutput) throws Exception {
lexer.reset();
parser.reset();
lexerErrorListener.reset();
parserErrorListener.reset();
CharStream chrStrm = CharStreams.fromStream(input, StandardCharsets.US_ASCII);
lexer.setInputStream(chrStrm);
CommonTokenStream tokStrm = new CommonTokenStream(lexer);
parser.setInputStream(tokStrm);
parser.setBuildParseTree(true);
ParseTree tree = null;
try {
tree = parser.root();
} catch (CancellationException e) {
}
if (lexerErrorListener.error() != null) {
throw lexerErrorListener.error();
}
if (parserErrorListener.error() != null) {
throw parserErrorListener.error();
}
ParseTreeWalker walker = new ParseTreeWalker();
Listener listener = new Listener(nonPPOutput);
try {
walker.walk(listener, tree);
} catch (CancellationException e) {
}
if (listener.error() != null) {
throw listener.error();
}
return listener.includes;
}
use of org.antlr.v4.runtime.CharStream in project claw-compiler by C2SM-RCM.
the class FortranDepParser method parse.
public List<StatementInfo> parse(InputStream input) throws FortranException, IOException, Exception {
lexer.reset();
parser.reset();
lexerErrorListener.reset();
parserErrorListener.reset();
CharStream chrStrm = CharStreams.fromStream(input, StandardCharsets.US_ASCII);
lexer.setInputStream(chrStrm);
CommonTokenStream tokStrm = new CommonTokenStream(lexer);
parser.setInputStream(tokStrm);
parser.setBuildParseTree(true);
ParseTree tree = null;
try {
tree = parser.root();
} catch (CancellationException e) {
}
if (lexerErrorListener.error() != null) {
throw lexerErrorListener.error();
}
if (parserErrorListener.error() != null) {
throw parserErrorListener.error();
}
ParseTreeWalker walker = new ParseTreeWalker();
Listener listener = new Listener(statementsParser, procStatementsParser);
try {
walker.walk(listener, tree);
} catch (CancellationException e) {
}
if (listener.error() != null) {
throw listener.error();
}
return listener.statements;
}
use of org.antlr.v4.runtime.CharStream in project claw-compiler by C2SM-RCM.
the class FortranDepStatementsRecognizer method run.
Listener run(StatementType type, String input) throws IOException, Exception {
lexer.reset();
parser.reset();
lexerErrorListener.reset();
parserErrorListener.reset();
CharStream chrStrm = toCharStream(input);
lexer.setInputStream(chrStrm);
CommonTokenStream tokStrm = new CommonTokenStream(lexer);
parser.setInputStream(tokStrm);
parser.setBuildParseTree(true);
ParseTree tree = null;
try {
switch(type) {
case MODULE_OPEN:
tree = parser.module_open_stmt();
break;
case MODULE_CLOSE:
tree = parser.module_close_stmt();
break;
case PROGRAM_OPEN:
tree = parser.program_open_stmt();
break;
case PROGRAM_CLOSE:
tree = parser.program_close_stmt();
break;
case BLOCK_DATA_OPEN:
tree = parser.block_data_open_stmt();
break;
case BLOCK_DATA_CLOSE:
tree = parser.block_data_close_stmt();
break;
case USE_MODULE:
tree = parser.use_stmt();
break;
default:
throw new Exception("Unexpected statement type");
}
} catch (CancellationException e) {
}
if (lexerErrorListener.error() != null) {
throw lexerErrorListener.error();
}
if (parserErrorListener.error() != null) {
throw parserErrorListener.error();
}
ParseTreeWalker walker = new ParseTreeWalker();
Listener listener = new Listener(type);
walker.walk(listener, tree);
if (listener.error() != null) {
throw listener.error();
}
return listener;
}
use of org.antlr.v4.runtime.CharStream in project claw-compiler by C2SM-RCM.
the class Utils method toCharStream.
public static CharStream toCharStream(String str) throws IOException {
InputStream inStrm = toInputStream(str);
CharStream chrStrm = CharStreams.fromStream(inStrm, StandardCharsets.US_ASCII);
return chrStrm;
}
Aggregations