use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class EventBParser method main.
public static void main(final String[] args) {
if (args.length < 1) {
System.err.println("usage: BParser [options] <BMachine file>");
System.err.println();
System.err.println("Available options are:");
System.err.println(CLI_SWITCH_VERBOSE + "\t\tVerbose output during lexing and parsing");
System.err.println(CLI_SWITCH_TIME + "\t\tOutput time used for complete parsing process.");
System.err.println(CLI_SWITCH_AST + "\t\tPrint AST on standard output.");
System.err.println(CLI_SWITCH_UI + "\t\tShow AST as Swing UI.");
System.exit(-1);
}
try {
final long start = System.currentTimeMillis();
final EventBParser parser = new EventBParser();
final Start tree = parser.parseFile(new File(args[args.length - 1]), isCliSwitchSet(args, CLI_SWITCH_VERBOSE));
final long end = System.currentTimeMillis();
System.out.println();
if (isCliSwitchSet(args, CLI_SWITCH_TIME)) {
System.out.println("Time for parsing: " + (end - start) + "ms");
}
if (isCliSwitchSet(args, CLI_SWITCH_AST)) {
System.out.println("AST:");
tree.apply(new ASTPrinter());
}
if (isCliSwitchSet(args, CLI_SWITCH_UI)) {
tree.apply(new ASTDisplay());
}
} catch (final IOException e) {
System.err.println();
System.err.println("Error reading input file: " + e.getLocalizedMessage());
System.exit(-2);
} catch (final BException e) {
System.err.println();
System.err.println("Error parsing input file: " + e.getLocalizedMessage());
System.exit(-3);
}
}
use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class EventBParser method main.
public static void main(final String[] args) {
if (args.length < 1) {
System.err.println("usage: BParser [options] <BMachine file>");
System.err.println();
System.err.println("Available options are:");
System.err.println(CLI_SWITCH_VERBOSE + "\t\tVerbose output during lexing and parsing");
System.err.println(CLI_SWITCH_TIME + "\t\tOutput time used for complete parsing process.");
System.err.println(CLI_SWITCH_AST + "\t\tPrint AST on standard output.");
System.err.println(CLI_SWITCH_UI + "\t\tShow AST as Swing UI.");
System.exit(-1);
}
try {
final long start = System.currentTimeMillis();
final EventBParser parser = new EventBParser();
final Start tree = parser.parseFile(new File(args[args.length - 1]), isCliSwitchSet(args, CLI_SWITCH_VERBOSE));
final long end = System.currentTimeMillis();
System.out.println();
if (isCliSwitchSet(args, CLI_SWITCH_TIME)) {
System.out.println("Time for parsing: " + (end - start) + "ms");
}
if (isCliSwitchSet(args, CLI_SWITCH_AST)) {
System.out.println("AST:");
tree.apply(new ASTPrinter());
}
if (isCliSwitchSet(args, CLI_SWITCH_UI)) {
tree.apply(new ASTDisplay());
}
} catch (final IOException e) {
System.err.println();
System.err.println("Error reading input file: " + e.getLocalizedMessage());
System.exit(-2);
} catch (final BException e) {
System.err.println();
System.err.println("Error parsing input file: " + e.getLocalizedMessage());
System.exit(-3);
}
}
use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class BatchParser method parseFile.
private static void parseFile(final String filename) throws IOException, BCompoundException {
final int dot = filename.lastIndexOf('.');
if (dot >= 0) {
final File machineFile = new File(filename);
final String probfilename = filename.substring(0, dot) + ".prob";
BParser parser = new BParser(filename);
Start tree = parser.parseFile(machineFile, false);
PrintStream output = new PrintStream(probfilename);
BParser.printASTasProlog(output, parser, machineFile, tree, new ParsingBehaviour(), parser.getContentProvider());
output.close();
} else
throw new IllegalArgumentException("Filename '" + filename + "' has no extension");
}
use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class BParser method printASTasProlog.
public static void printASTasProlog(final PrintStream out, final BParser parser, final File bfile, final Start tree, final ParsingBehaviour parsingBehaviour, IDefinitionFileProvider contentProvider) throws BCompoundException {
final RecursiveMachineLoader rml = new RecursiveMachineLoader(bfile.getParent(), contentProvider, parsingBehaviour);
rml.loadAllMachines(bfile, tree, parser.getDefinitions());
rml.printAsProlog(new PrintWriter(out));
}
use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class BParser method getASTasFastProlog.
private static String getASTasFastProlog(final BParser parser, final File bfile, final Start tree, final ParsingBehaviour parsingBehaviour, IDefinitionFileProvider contentProvider) throws BCompoundException {
final RecursiveMachineLoader rml = new RecursiveMachineLoader(bfile.getParent(), contentProvider, parsingBehaviour);
rml.loadAllMachines(bfile, tree, parser.getDefinitions());
StructuredPrologOutput structuredPrologOutput = new StructuredPrologOutput();
rml.printAsProlog(structuredPrologOutput);
Collection<PrologTerm> sentences = structuredPrologOutput.getSentences();
StructuredPrologOutput output = new StructuredPrologOutput();
output.openList();
for (PrologTerm term : sentences) {
output.printTerm(term);
}
output.closeList();
output.fullstop();
FastReadTransformer transformer = new FastReadTransformer(output);
return transformer.write();
}
Aggregations