Search in sources :

Example 1 with EventBParser

use of de.be4.eventbalg.core.parser.EventBParser in project probparsers by bendisposto.

the class AbstractTest method parseInput.

protected Start parseInput(final String input, final boolean debugOutput) throws BException {
    if (debugOutput) {
        System.out.println();
        System.out.println();
    }
    final EventBParser parser = new EventBParser();
    final Start rootNode = parser.parse(input, debugOutput);
    return rootNode;
}
Also used : Start(de.be4.eventb.core.parser.node.Start) EventBParser(de.be4.eventb.core.parser.EventBParser)

Example 2 with EventBParser

use of de.be4.eventbalg.core.parser.EventBParser in project prob2 by bendisposto.

the class ModelGenerator method addComponent.

private ModelModifier addComponent(ModelModifier modelM, String name, String componentDesc, Map<String, String> components) throws BException {
    EventBParser parser = new EventBParser();
    Start ast = parser.parse(componentDesc, false);
    ReferenceExtractor e = new ReferenceExtractor();
    ast.apply(e);
    if (e.isContext()) {
        for (String s : e.getExtends()) {
            String fileN = s + ".ctx";
            if (modelM.getModel().getComponent(fileN) == null) {
                if (components.get(fileN) == null) {
                    throw new IllegalArgumentException("no component description for context " + s);
                }
                modelM = addComponent(modelM, s, components.get(fileN), components);
            }
        }
        modelM = addComponent(modelM, ast);
    } else if (e.isMachine()) {
        for (String s : e.getSees()) {
            String fileN = s + ".ctx";
            if (modelM.getModel().getComponent(fileN) == null) {
                if (components.get(fileN) == null) {
                    throw new IllegalArgumentException("no component description for context " + s);
                }
                modelM = addComponent(modelM, s, components.get(fileN), components);
            }
        }
        for (String s : e.getRefines()) {
            String fileN = s + ".emch";
            if (modelM.getModel().getComponent(fileN) == null) {
                if (components.get(fileN) == null) {
                    throw new IllegalArgumentException("no component description for machine " + s);
                }
                modelM = addComponent(modelM, s, components.get(fileN), components);
            }
        }
        modelM = addComponent(modelM, ast);
    }
    return modelM;
}
Also used : Start(de.be4.eventbalg.core.parser.node.Start) EventBParser(de.be4.eventbalg.core.parser.EventBParser)

Example 3 with EventBParser

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

Example 4 with EventBParser

use of de.be4.eventbalg.core.parser.EventBParser in project probparsers by bendisposto.

the class AbstractTest method parseInput.

protected Start parseInput(final String input, final boolean debugOutput) throws BException {
    if (debugOutput) {
        System.out.println();
        System.out.println();
    }
    final EventBParser parser = new EventBParser();
    final Start rootNode = parser.parse(input, debugOutput);
    if (debugOutput) {
        rootNode.apply(new ASTPrinter());
    }
    return rootNode;
}
Also used : Start(de.be4.eventbalg.core.parser.node.Start) EventBParser(de.be4.eventbalg.core.parser.EventBParser) ASTPrinter(de.be4.eventbalg.core.parser.analysis.ASTPrinter)

Example 5 with EventBParser

use of de.be4.eventbalg.core.parser.EventBParser 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.eventb.core.parser.node.Start) ASTPrinter(de.be4.eventb.core.parser.analysis.ASTPrinter) ASTDisplay(de.be4.eventb.core.parser.analysis.ASTDisplay) IOException(java.io.IOException) File(java.io.File)

Aggregations

Start (de.be4.eventbalg.core.parser.node.Start)3 Start (de.be4.eventb.core.parser.node.Start)2 EventBParser (de.be4.eventbalg.core.parser.EventBParser)2 ASTPrinter (de.be4.eventbalg.core.parser.analysis.ASTPrinter)2 File (java.io.File)2 IOException (java.io.IOException)2 EventBParser (de.be4.eventb.core.parser.EventBParser)1 ASTDisplay (de.be4.eventb.core.parser.analysis.ASTDisplay)1 ASTPrinter (de.be4.eventb.core.parser.analysis.ASTPrinter)1 ASTDisplay (de.be4.eventbalg.core.parser.analysis.ASTDisplay)1