Search in sources :

Example 61 with BParser

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;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 62 with BParser

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));
}
Also used : BLexer(de.be4.classicalb.core.parser.BLexer) Start(de.be4.classicalb.core.parser.node.Start) ASTPrinter(de.be4.classicalb.core.parser.visualisation.ASTPrinter) StringReader(java.io.StringReader) Token(de.be4.classicalb.core.parser.node.Token) BParser(de.be4.classicalb.core.parser.BParser) Helpers.getTreeAsString(util.Helpers.getTreeAsString) EOF(de.be4.classicalb.core.parser.node.EOF) PushbackReader(java.io.PushbackReader) Test(org.junit.Test)

Example 63 with BParser

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;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Definitions(de.be4.classicalb.core.parser.Definitions) BParser(de.be4.classicalb.core.parser.BParser) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 64 with BParser

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"));
}
Also used : PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) BParser(de.be4.classicalb.core.parser.BParser) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) File(java.io.File) Test(org.junit.Test)

Example 65 with BParser

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));
}
Also used : BLexer(de.be4.classicalb.core.parser.BLexer) Start(de.be4.classicalb.core.parser.node.Start) ASTPrinter(de.be4.classicalb.core.parser.visualisation.ASTPrinter) StringReader(java.io.StringReader) Token(de.be4.classicalb.core.parser.node.Token) BParser(de.be4.classicalb.core.parser.BParser) EOF(de.be4.classicalb.core.parser.node.EOF) PushbackReader(java.io.PushbackReader) Test(org.junit.Test)

Aggregations

Start (de.be4.classicalb.core.parser.node.Start)63 BParser (de.be4.classicalb.core.parser.BParser)53 Test (org.junit.Test)39 File (java.io.File)23 Ast2String (util.Ast2String)21 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)18 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)11 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)7 PrintStream (java.io.PrintStream)7 AbstractParseMachineTest (util.AbstractParseMachineTest)7 IOException (java.io.IOException)6 ASTPrinter (de.be4.classicalb.core.parser.visualisation.ASTPrinter)5 ClassicalBModel (de.prob.model.classicalb.ClassicalBModel)4 OutputStream (java.io.OutputStream)4 BLexer (de.be4.classicalb.core.parser.BLexer)3 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)3 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)3 EOF (de.be4.classicalb.core.parser.node.EOF)3 Token (de.be4.classicalb.core.parser.node.Token)3 ProBError (de.prob.exception.ProBError)3