Search in sources :

Example 11 with ASTPrinter

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

Example 12 with ASTPrinter

use of de.be4.eventbalg.core.parser.analysis.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));
}
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 13 with ASTPrinter

use of de.be4.eventbalg.core.parser.analysis.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));
}
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)

Example 14 with ASTPrinter

use of de.be4.eventbalg.core.parser.analysis.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);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) ASTPrinter(de.be4.classicalb.core.parser.visualisation.ASTPrinter) BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 15 with ASTPrinter

use of de.be4.eventbalg.core.parser.analysis.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);
    }
}
Also used : Start(de.be4.eventbalg.core.parser.node.Start) ASTPrinter(de.be4.eventbalg.core.parser.analysis.ASTPrinter) ASTDisplay(de.be4.eventbalg.core.parser.analysis.ASTDisplay) IOException(java.io.IOException) File(java.io.File)

Aggregations

Start (de.be4.classicalb.core.parser.node.Start)14 BParser (de.be4.classicalb.core.parser.BParser)8 Ast2String (util.Ast2String)7 ASTPrinter (de.be4.classicalb.core.parser.visualisation.ASTPrinter)6 Test (org.junit.Test)5 BLexer (de.be4.classicalb.core.parser.BLexer)3 EOF (de.be4.classicalb.core.parser.node.EOF)3 Token (de.be4.classicalb.core.parser.node.Token)3 File (java.io.File)3 IOException (java.io.IOException)3 PushbackReader (java.io.PushbackReader)3 StringReader (java.io.StringReader)3 ASTPrinter (de.be4.eventbalg.core.parser.analysis.ASTPrinter)2 Start (de.be4.eventbalg.core.parser.node.Start)2 Helpers.getTreeAsString (util.Helpers.getTreeAsString)2 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)1 ParserException (de.be4.classicalb.core.parser.parser.ParserException)1 ASTDisplay (de.be4.classicalb.core.parser.visualisation.ASTDisplay)1 ASTDisplay (de.be4.eventb.core.parser.analysis.ASTDisplay)1 ASTPrinter (de.be4.eventb.core.parser.analysis.ASTPrinter)1