use of de.be4.classicalb.core.parser.node.EOF in project prob2 by bendisposto.
the class DomBuilder method createPredicateAST.
private Start createPredicateAST(final PPredicate pPredicate) {
Start start = new Start();
APredicateParseUnit node2 = new APredicateParseUnit();
start.setPParseUnit(node2);
start.setEOF(EOF);
node2.setPredicate((PPredicate) pPredicate.clone());
node2.getPredicate().apply(new RenameIdentifiers());
return start;
}
use of de.be4.classicalb.core.parser.node.EOF 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.node.EOF 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));
}
use of de.be4.classicalb.core.parser.node.EOF in project probparsers by bendisposto.
the class PreParser method determineDependencies.
private Map<String, Set<String>> determineDependencies(Set<String> definitionNames, Map<Token, Token> definitions) throws PreParseException {
HashMap<String, Set<String>> dependencies = new HashMap<>();
for (Entry<Token, Token> entry : definitions.entrySet()) {
Token nameToken = entry.getKey();
Token rhsToken = entry.getValue();
// The FORMULA_PREFIX is needed to switch the lexer state from
// section to normal. Note, that we do not parse the right hand side
// of the definition here. Hence FORMULA_PREFIX has no further
// meaning and substitutions can also be handled by the lexer.
final Reader reader = new StringReader(BParser.FORMULA_PREFIX + "\n" + rhsToken.getText());
final BLexer lexer = new BLexer(new PushbackReader(reader, BLexer.PUSHBACK_BUFFER_SIZE), new DefinitionTypes());
lexer.setParseOptions(parseOptions);
Set<String> set = new HashSet<>();
de.be4.classicalb.core.parser.node.Token next = null;
try {
next = lexer.next();
while (!(next instanceof EOF)) {
if (next instanceof TIdentifierLiteral) {
TIdentifierLiteral id = (TIdentifierLiteral) next;
String name = id.getText();
if (definitionNames.contains(name)) {
set.add(name);
}
}
next = lexer.next();
}
} catch (IOException e) {
} catch (BLexerException e) {
de.be4.classicalb.core.parser.node.Token errorToken = e.getLastToken();
final String newMessage = determineNewErrorMessageWithCorrectedPositionInformations(nameToken, rhsToken, errorToken, e.getMessage());
throw new PreParseException(newMessage);
} catch (de.be4.classicalb.core.parser.lexer.LexerException e) {
final String newMessage = determineNewErrorMessageWithCorrectedPositionInformationsWithoutToken(nameToken, rhsToken, e.getMessage());
throw new PreParseException(newMessage);
}
dependencies.put(nameToken.getText(), set);
}
return dependencies;
}
use of de.be4.classicalb.core.parser.node.EOF 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;
}
Aggregations