use of de.be4.classicalb.core.parser.visualisation.ASTPrinter in project probparsers by bendisposto.
the class StringLiteralNotClosedTest method getTreeAsString.
private String getTreeAsString(final String testMachine) throws BCompoundException {
// System.out.println("Parsing \"" + testMachine + "\"");
final BParser parser = new BParser("testcase");
parser.getOptions().setGrammar(RulesGrammar.getInstance());
final Start startNode = parser.parse(testMachine, false);
// startNode.apply(new ASTPrinter());
final Ast2String ast2String = new Ast2String();
startNode.apply(ast2String);
final String string = ast2String.toString();
// System.out.println(string);
return string;
}
use of de.be4.classicalb.core.parser.visualisation.ASTPrinter in project probparsers by bendisposto.
the class UnitPragmaTest method testLexer.
@Test
public void testLexer() throws Exception {
String input = "MACHINE UnitPragmaExpressions1 VARIABLES lala, /*@ unit \"10**1 * m**1\" */ xx, /*@ unit \"10**1 * m**1\" */ yy, /*@ unit \"10**2 * m**2\" */ zz, test INVARIANT /*@ label \"lol\" */ lala = \"trololo\" &xx:NAT & yy:NAT & zz:NAT & test:NAT INITIALISATION xx,yy,zz,test:=1,2,3,4 OPERATIONS multiply = zz := xx*yy; add = xx := yy+1; sub = xx := yy-1; type = test := yy END";
BLexer lex = new BLexer(new PushbackReader(new StringReader(input), 500));
Token t;
while (!((t = lex.next()) instanceof EOF)) {
System.out.print(t.getClass().getSimpleName() + "(" + t.getText() + ")");
System.out.print(" ");
}
BParser p = new BParser();
Start ast = p.parse(input, false);
ASTPrinter pr = new ASTPrinter();
ast.apply(pr);
System.out.println(printAST(ast));
}
use of de.be4.classicalb.core.parser.visualisation.ASTPrinter in project probparsers by bendisposto.
the class PragmaTest method testLexer.
@Test
public void testLexer() throws Exception {
// String input = "/*@ generated */ MACHINE foo(x) \n"
// + "/* look at me. */ \n"
// + "DEFINITIONS \n"
// + " /*@ conversion */ foo(m) == m \n"
// + "PROPERTIES \n"
// + "/*@ label foo */ \n"
// + "/*@ label bar */ \n"
// + "x = /*@ symbolic */ {y|->z| y < z } \n"
// + "/*@ desc prop */ \n"
// + "SETS A;B={a,b} /*@ desc trololo !!! */;C END";
// String input =
// "MACHINE foo PROPERTIES /*@ label foo */ x = /*@ symbolic */ {y|->z|
// y < z } END";
String input = "MACHINE foo CONSTANTS c /*@ desc konstante nummero uno */ PROPERTIES c = 5 VARIABLES x /*@ desc Hallo du variable */ INVARIANT x=1 INITIALISATION x:= 1 END";
BLexer lex = new BLexer(new PushbackReader(new StringReader(input), 500));
Token t;
while (!((t = lex.next()) instanceof EOF)) {
System.out.print(t.getClass().getSimpleName() + "(" + t.getText() + ")");
System.out.print(" ");
}
BParser p = new BParser();
System.out.println("\n" + input);
Start ast = p.parse(input, false);
ASTPrinter pr = new ASTPrinter();
ast.apply(pr);
System.out.println(printAST(ast));
}
use of de.be4.classicalb.core.parser.visualisation.ASTPrinter in project probparsers by bendisposto.
the class ParserBugTest method test.
@Test
public void test() throws Exception {
BParser parser = new BParser();
Start ast = parser.parse(s, true);
ast.apply(new ASTPrinter());
assertTrue(true);
}
use of de.be4.classicalb.core.parser.visualisation.ASTPrinter 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);
}
}
Aggregations