Search in sources :

Example 81 with Parser

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

the class BParser method eparse.

public Start eparse(String input, IDefinitions context) throws BCompoundException, LexerException, IOException {
    final Reader reader = new StringReader(input);
    Start ast = null;
    List<String> ids = new ArrayList<>();
    final DefinitionTypes defTypes = new DefinitionTypes();
    defTypes.addAll(context.getTypes());
    BLexer bLexer = new BLexer(new PushbackReader(reader, BLexer.PUSHBACK_BUFFER_SIZE), defTypes);
    bLexer.setParseOptions(parseOptions);
    Token t;
    do {
        t = bLexer.next();
        if (t instanceof TIdentifierLiteral) {
            if (!ids.contains(t.getText())) {
                ids.add(t.getText());
            }
        }
    } while (!(t instanceof EOF));
    Parser p = new Parser(new EBLexer(input, BigInteger.ZERO, ids, defTypes));
    boolean ok;
    try {
        ast = p.parse();
        ok = true;
    } catch (Exception e) {
        handleException(e);
        ok = false;
    }
    BigInteger b = new BigInteger("2");
    b = b.pow(ids.size());
    b = b.subtract(BigInteger.ONE);
    while (!ok && b.compareTo(BigInteger.ZERO) > 0) {
        p = new Parser(new EBLexer(input, b, ids, defTypes));
        try {
            ast = p.parse();
            ok = true;
        } catch (ParserException e) {
            b = b.subtract(BigInteger.ONE);
            handleException(e);
        }
    }
    return ast;
}
Also used : ParserException(de.be4.classicalb.core.parser.parser.ParserException) Start(de.be4.classicalb.core.parser.node.Start) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) PushbackReader(java.io.PushbackReader) Token(de.be4.classicalb.core.parser.node.Token) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) LexerException(de.be4.classicalb.core.parser.lexer.LexerException) IOException(java.io.IOException) ParserException(de.be4.classicalb.core.parser.parser.ParserException) PushbackReader(java.io.PushbackReader) Parser(de.be4.classicalb.core.parser.parser.Parser) StringReader(java.io.StringReader) BigInteger(java.math.BigInteger) EOF(de.be4.classicalb.core.parser.node.EOF)

Aggregations

Start (de.be4.classicalb.core.parser.node.Start)51 BParser (de.be4.classicalb.core.parser.BParser)41 Test (org.junit.Test)31 Ast2String (util.Ast2String)20 File (java.io.File)15 IOException (java.io.IOException)13 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)10 StringReader (java.io.StringReader)9 PushbackReader (java.io.PushbackReader)8 AbstractParseMachineTest (util.AbstractParseMachineTest)7 PrintStream (java.io.PrintStream)6 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)5 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)4 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)4 Reader (java.io.Reader)4 ArrayList (java.util.ArrayList)4 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)3 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)3 Start (de.be4.eventbalg.core.parser.node.Start)3 LtlParseException (de.be4.ltl.core.parser.LtlParseException)3