use of de.be4.classicalb.core.parser.BParser 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.BParser 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.BParser in project probparsers by bendisposto.
the class SatProblem method getTreeAsString.
private String getTreeAsString(final String testMachine) throws BCompoundException, LexerException, IOException {
final BParser parser = new BParser("testcase");
Start ast = parser.eparse(testMachine, new Definitions());
final Ast2String ast2String = new Ast2String();
ast.apply(ast2String);
final String string = ast2String.toString();
return string;
}
use of de.be4.classicalb.core.parser.BParser in project probparsers by bendisposto.
the class RulesProjectExceptionTest method testRulesMachineInOrdinaryMachineFileException.
@Test
public void testRulesMachineInOrdinaryMachineFileException() throws Exception {
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b);
}
@Override
public String toString() {
return this.string.toString();
}
};
PrintStream pStream = new PrintStream(output);
ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
parsingBehaviour.setPrologOutput(true);
BParser bParser = new BParser("RulesMachineInOrdinaryMachineFile.mch");
bParser.fullParsing(new File("src/test/resources/rules/project/RulesMachineInOrdinaryMachineFile.mch"), parsingBehaviour, pStream, pStream);
System.out.println(output.toString());
assertTrue(output.toString().contains("parse_exception"));
}
use of de.be4.classicalb.core.parser.BParser 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));
}
Aggregations