use of de.be4.eventb.core.parser.node.TIdentifierLiteral 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;
}
use of de.be4.eventb.core.parser.node.TIdentifierLiteral in project prob2 by bendisposto.
the class ContextTranslator method translateContext.
public Node translateContext() {
AEventBContextParseUnit ast = new AEventBContextParseUnit();
ast.setName(new TIdentifierLiteral(context.getName()));
List<PContextClause> clauses = new ArrayList<>();
clauses.add(processExtends());
clauses.addAll(processConstants());
clauses.addAll(processAxiomsAndTheorems());
clauses.add(processSets());
ast.setContextClauses(clauses);
return ast;
}
use of de.be4.eventb.core.parser.node.TIdentifierLiteral in project prob2 by bendisposto.
the class EventBMachineTranslator method processEvents.
private AEventsModelClause processEvents() {
List<PEvent> events = new ArrayList<>();
for (Event e : machine.getEvents()) {
AEvent event = new AEvent();
event.setEventName(new TIdentifierLiteral(e.getName()));
event.setStatus(extractEventStatus(e));
nodeInfos.put(event, new Tuple2<>(machine.getName(), e.getName()));
List<TIdentifierLiteral> refined = new ArrayList<>();
for (Event ref : e.getRefines()) {
refined.add(new TIdentifierLiteral(ref.getName()));
}
event.setRefines(refined);
List<PExpression> params = new ArrayList<>();
for (EventParameter eventParameter : e.getParameters()) {
PExpression pExpression = (PExpression) eventParameter.getExpression().getAst();
nodeInfos.put(pExpression, new Tuple2<>(machine.getName(), eventParameter.getName()));
params.add(pExpression);
}
event.setVariables(params);
List<PPredicate> guards = new ArrayList<>();
List<PPredicate> thms = new ArrayList<>();
for (EventBGuard eventBGuard : e.getGuards()) {
PPredicate ppred = (PPredicate) ((EventB) eventBGuard.getPredicate()).getAst();
nodeInfos.put(ppred, new Tuple2<>(machine.getName(), eventBGuard.getName()));
if (eventBGuard.isTheorem()) {
thms.add(ppred);
} else {
guards.add(ppred);
}
}
event.setGuards(guards);
event.setTheorems(thms);
List<PWitness> witnesses = new ArrayList<>();
for (Witness witness : e.getWitnesses()) {
PPredicate ppred = (PPredicate) witness.getPredicate().getAst();
nodeInfos.put(ppred, new Tuple2<>(machine.getName(), witness.getName()));
witnesses.add(new AWitness(new TIdentifierLiteral(witness.getName()), ppred));
}
event.setWitness(witnesses);
List<PSubstitution> actions = new ArrayList<>();
for (EventBAction eventBAction : e.getActions()) {
PSubstitution psub = (PSubstitution) ((EventB) eventBAction.getCode()).getAst();
nodeInfos.put(psub, new Tuple2<>(machine.getName(), eventBAction.getName()));
actions.add(psub);
}
event.setAssignments(actions);
events.add(event);
}
return new AEventsModelClause(events);
}
use of de.be4.eventb.core.parser.node.TIdentifierLiteral in project prob2 by bendisposto.
the class EventBMachineTranslator method processContexts.
private ASeesModelClause processContexts() {
List<Context> sees = machine.getSees();
List<TIdentifierLiteral> contextNames = new ArrayList<>();
for (Context context : sees) {
contextNames.add(new TIdentifierLiteral(context.getName()));
}
return new ASeesModelClause(contextNames);
}
Aggregations