this.body = body;
this.existentialVariables = existentialVariables;
}
+
+ public CHRRule(long location, CHRQuery head, CHRQuery body) {
+ this(location, head, body, null);
+ }
public void resolve(TranslationContext context) {
context.pushExistentialFrame();
--- /dev/null
+package org.simantics.scl.compiler.elaboration.chr.ast;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+
+import org.simantics.scl.compiler.common.names.Name;
+import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
+import org.simantics.scl.compiler.elaboration.chr.relations.SpecialCHRRelation;
+import org.simantics.scl.compiler.elaboration.chr.relations.UnresolvedCHRRelation;
+import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
+import org.simantics.scl.compiler.elaboration.expressions.EApply;
+import org.simantics.scl.compiler.elaboration.expressions.EBinary;
+import org.simantics.scl.compiler.elaboration.expressions.EConstant;
+import org.simantics.scl.compiler.elaboration.expressions.ERecord;
+import org.simantics.scl.compiler.elaboration.expressions.EVar;
+import org.simantics.scl.compiler.elaboration.expressions.Expression;
+import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
+import org.simantics.scl.compiler.environment.AmbiguousNameException;
+import org.simantics.scl.compiler.environment.Environments;
+import org.simantics.scl.compiler.errors.Locations;
+import org.simantics.scl.compiler.types.Types;
+
+public class CHRAstAtom extends CHRAstQuery {
+ public Expression expression;
+ public boolean remove;
+
+ public CHRAstAtom(Expression expression, boolean remove) {
+ this.expression = expression;
+ this.remove = remove;
+ }
+
+ @Override
+ public void accept(CHRAstQueryVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ public static CHRAstQuery atom(Expression expression) {
+ boolean remove = false;
+ if(expression instanceof EVar) {
+ EVar var = (EVar)expression;
+ if(var.name.equals("True")) {
+ CHRAstConjunction query = new CHRAstConjunction(Collections.emptyList());
+ query.location = expression.location;
+ return query;
+ }
+ }
+ else if(expression instanceof EBinary) {
+ EBinary binary = (EBinary)expression;
+ if(binary.negation != null && binary.rights.isEmpty()) {
+ remove = true;
+ expression = binary.left;
+ }
+ // If query is marked for removal, it must be an atom
+ }
+ else if(expression instanceof EApply) {
+ EApply apply = (EApply)expression;
+ if(apply.function instanceof EVar && ((EVar)apply.function).name.equals("not")) {
+ Expression subExpression;
+ if(apply.parameters.length == 1)
+ subExpression = apply.parameters[0];
+ else
+ subExpression = new EApply(
+ Locations.combine(apply.parameters[0].location, apply.parameters[apply.parameters.length-1].location),
+ apply.parameters[0],
+ Arrays.copyOfRange(apply.parameters, 1, apply.parameters.length));
+ CHRAstNegation query = new CHRAstNegation(atom(subExpression));
+ query.location = expression.location;
+ return query;
+ }
+ else if(apply.function instanceof EConstant) {
+ Name valueName = ((EConstant)apply.function).getValue().getName();
+ if(valueName.module.equals(Types.BUILTIN) && valueName.name.startsWith("(")) {
+ CHRAstQuery[] conjuncts = new CHRAstQuery[apply.parameters.length];
+ for(int i=0;i<conjuncts.length;++i)
+ conjuncts[i] = atom(apply.parameters[i]);
+ CHRAstQuery query = CHRAstConjunction.conjunction(conjuncts);
+ query.location = expression.location;
+ return query;
+ }
+ }
+ }
+ CHRAstAtom query = new CHRAstAtom(expression, remove);
+ query.location = expression.location;
+ return query;
+ }
+
+ @Override
+ protected void translate(TranslationContext context, boolean isHead, ArrayList<CHRLiteral> literals) {
+ literals.add(
+ isConstraint(context, expression) ?
+ convertConstraint(remove, expression) :
+ convertExpression(isHead, expression));
+ }
+
+ private static boolean isConstraint(TranslationContext context, Expression expression) {
+ if(expression instanceof EApply)
+ expression = ((EApply)expression).function;
+ else if(expression instanceof ERecord)
+ expression = ((ERecord)expression).constructor;
+ if(!(expression instanceof EVar))
+ return false;
+ String name = ((EVar)expression).name;
+ if(TranslationContext.isConstructorName(name))
+ return true;
+ try {
+ return Environments.getRelation(context.getEnvironment(), name) != null;
+ } catch (AmbiguousNameException e) {
+ return true;
+ }
+ }
+
+ private static CHRLiteral convertExpression(boolean isHead, Expression expression) {
+ if(isHead)
+ return new CHRLiteral(expression.location, SpecialCHRRelation.CHECK, new Expression[] {expression}, false, false);
+ else
+ return new CHRLiteral(expression.location, SpecialCHRRelation.EXECUTE, new Expression[] {expression}, false, false);
+ }
+
+ private static CHRLiteral convertConstraint(boolean remove, Expression expression) {
+ long location = expression.location;
+ Expression[] parameters;
+ FieldAssignment[] fields = null;
+ if(expression instanceof EApply) {
+ EApply apply = (EApply)expression;
+ parameters = apply.parameters;
+ expression = apply.function;
+ }
+ else if(expression instanceof ERecord) {
+ ERecord record = (ERecord)expression;
+ parameters = null;
+ fields = record.fields;
+ expression = record.constructor;
+ }
+ else // if(expression instanceof EVar)
+ parameters = Expression.EMPTY_ARRAY;
+ EVar var = (EVar)expression; // this should succeed because of isConstraint test
+ CHRLiteral literal = new CHRLiteral(location, new UnresolvedCHRRelation(var.location, var.name),
+ parameters, remove, false);
+ literal.fields = fields;
+ return literal;
+ }
+}
--- /dev/null
+package org.simantics.scl.compiler.elaboration.chr.ast;
+
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
+import org.simantics.scl.compiler.elaboration.chr.relations.SpecialCHRRelation;
+import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
+import org.simantics.scl.compiler.elaboration.expressions.Expression;
+
+public class CHRAstBinds extends CHRAstQuery {
+ public Expression left;
+ public Expression right;
+
+ public CHRAstBinds(Expression left, Expression right) {
+ this.left = left;
+ this.right = right;
+ }
+
+ @Override
+ public void accept(CHRAstQueryVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ protected void translate(TranslationContext context, boolean isHead, ArrayList<CHRLiteral> literals) {
+ literals.add(new CHRLiteral(location, SpecialCHRRelation.MEMBER,
+ new Expression[] { left, right }, false, false));
+ }
+}
--- /dev/null
+package org.simantics.scl.compiler.elaboration.chr.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
+import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
+
+public class CHRAstConjunction extends CHRAstQuery {
+ public List<CHRAstQuery> conjuncts;
+
+ public CHRAstConjunction(List<CHRAstQuery> conjuncts) {
+ this.conjuncts = conjuncts;
+ }
+
+ @Override
+ public void accept(CHRAstQueryVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ public static CHRAstQuery conjunction(CHRAstQuery[] conjuncts) {
+ ArrayList<CHRAstQuery> result = new ArrayList<CHRAstQuery>(conjuncts.length);
+ for(CHRAstQuery conjunct : conjuncts) {
+ if(conjunct instanceof CHRAstConjunction)
+ result.addAll(((CHRAstConjunction)conjunct).conjuncts);
+ else
+ result.add(conjunct);
+ }
+ if(result.size() == 1)
+ return result.get(0);
+ else
+ return new CHRAstConjunction(result);
+ }
+
+ @Override
+ protected void translate(TranslationContext context, boolean isHead, ArrayList<CHRLiteral> literals) {
+ for(CHRAstQuery conjunct : conjuncts)
+ conjunct.translate(context, isHead, literals);
+ }
+}
--- /dev/null
+package org.simantics.scl.compiler.elaboration.chr.ast;
+
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
+import org.simantics.scl.compiler.elaboration.chr.relations.SpecialCHRRelation;
+import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
+import org.simantics.scl.compiler.elaboration.expressions.Expression;
+
+public class CHRAstEquals extends CHRAstQuery {
+ public Expression left;
+ public Expression right;
+
+ public CHRAstEquals(Expression left, Expression right) {
+ this.left = left;
+ this.right = right;
+ }
+
+ @Override
+ public void accept(CHRAstQueryVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ protected void translate(TranslationContext context, boolean isHead, ArrayList<CHRLiteral> literals) {
+ literals.add(new CHRLiteral(location, SpecialCHRRelation.EQUALS,
+ new Expression[] { left, right }, false, false));
+ }
+}
--- /dev/null
+package org.simantics.scl.compiler.elaboration.chr.ast;
+
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
+import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
+
+public class CHRAstNegation extends CHRAstQuery {
+ public CHRAstQuery subquery;
+
+ public CHRAstNegation(CHRAstQuery subquery) {
+ this.subquery = subquery;
+ }
+
+ @Override
+ public void accept(CHRAstQueryVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ protected void translate(TranslationContext context, boolean isHead, ArrayList<CHRLiteral> literals) {
+ context.getCompilationContext().errorLog.log(location, "CHR negation is not yet supported.");
+ }
+}
--- /dev/null
+package org.simantics.scl.compiler.elaboration.chr.ast;
+
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
+import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
+import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
+import org.simantics.scl.compiler.internal.parsing.Symbol;
+
+public abstract class CHRAstQuery extends Symbol {
+ public CHRQuery translateAsHead(TranslationContext context) {
+ return translate(context, true);
+ }
+
+ public CHRQuery translateAsBody(TranslationContext context) {
+ return translate(context, false);
+ }
+
+ private CHRQuery translate(TranslationContext context, boolean isHead) {
+ ArrayList<CHRLiteral> literals = new ArrayList<CHRLiteral>();
+ translate(context, isHead, literals);
+ return new CHRQuery(literals.toArray(new CHRLiteral[literals.size()]));
+ }
+
+ protected abstract void translate(TranslationContext context, boolean isHead, ArrayList<CHRLiteral> literals);
+
+ public abstract void accept(CHRAstQueryVisitor visitor);
+}
--- /dev/null
+package org.simantics.scl.compiler.elaboration.chr.ast;
+
+public interface CHRAstQueryVisitor {
+ void visit(CHRAstAtom query);
+ void visit(CHRAstBinds query);
+ void visit(CHRAstConjunction query);
+ void visit(CHRAstEquals query);
+ void visit(CHRAstNegation query);
+}
import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
-import org.simantics.scl.compiler.elaboration.chr.CHRRule;
import org.simantics.scl.compiler.elaboration.chr.relations.CHRConstraint;
import org.simantics.scl.compiler.elaboration.chr.relations.SpecialCHRRelation;
import org.simantics.scl.compiler.elaboration.chr.relations.UnresolvedCHRRelation;
import org.simantics.scl.compiler.elaboration.expressions.ERecord;
import org.simantics.scl.compiler.elaboration.expressions.EVar;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
-import org.simantics.scl.compiler.elaboration.expressions.block.CHRStatement;
import org.simantics.scl.compiler.elaboration.expressions.block.ConstraintStatement;
import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment;
import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator;
return new CHRQuery(query.toArray(new CHRLiteral[query.size()]));
}
- public static CHRRule convertCHRStatement(TranslationContext context, CHRStatement statement) {
+ /*public static CHRRule convertCHRStatement(TranslationContext context, CHRStatement statement) {
return new CHRRule(statement.location,
convertCHRQuery(context, true, statement.head),
convertCHRQuery(context, false, statement.body),
null);
- }
+ }*/
public static CHRConstraint convertConstraintStatement(TranslationContext context, ConstraintStatement statement) {
CHRConstraint constraint = new CHRConstraint(statement.location, statement.name.text, TypeAst.toTypes(context, statement.parameterTypes));
import java.util.ArrayList;
import java.util.List;
+import org.simantics.scl.compiler.elaboration.chr.CHRRule;
import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
import org.simantics.scl.compiler.elaboration.chr.translation.CHRTranslation;
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
ruleset.location = Locations.combine(statements.get(begin).location, statements.get(end-1).location);
for(int i=begin;i<end;++i) {
Statement statement = statements.get(i);
- if(statement instanceof CHRStatement)
- ruleset.addRule(CHRTranslation.convertCHRStatement(context, (CHRStatement)statement));
+ if(statement instanceof CHRStatement) {
+ CHRStatement chrStatement = (CHRStatement)statement;
+ ruleset.addRule(new CHRRule(chrStatement.location, chrStatement.head.translateAsHead(context), chrStatement.body.translateAsBody(context)));
+ }
else if(statement instanceof ConstraintStatement)
ruleset.constraints.add(CHRTranslation.convertConstraintStatement(context, (ConstraintStatement)statement));
else if(statement instanceof IncludeStatement)
package org.simantics.scl.compiler.elaboration.expressions;
-import org.simantics.scl.compiler.elaboration.chr.translation.CHRTranslation;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstQuery;
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
-import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier;
public class EPreCHRSelect extends ASTExpression {
- ListQualifier[] query;
+ CHRAstQuery query;
Expression expression;
- public EPreCHRSelect(ListQualifier[] query, Expression expression) {
+ public EPreCHRSelect(CHRAstQuery query, Expression expression) {
this.query = query;
this.expression = expression;
}
@Override
public Expression resolve(TranslationContext context) {
- return new ECHRSelect(expression, CHRTranslation.convertCHRQuery(context, true, query)).resolve(context);
+ return new ECHRSelect(expression, query.translateAsHead(context)).resolve(context);
}
-
-
}
THashSet<Variable> result = new THashSet<Variable>();
collectFreeVariables(result);
return result;
- }
+ }
public static Expression[] concat(Expression[] a, Expression[] b) {
if(a.length == 0)
import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
import org.simantics.scl.compiler.elaboration.chr.CHRRule;
import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstAtom;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstBinds;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstConjunction;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstEquals;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstNegation;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstQuery;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstQueryVisitor;
import org.simantics.scl.compiler.elaboration.equation.EqBasic;
import org.simantics.scl.compiler.elaboration.equation.EqGuard;
import org.simantics.scl.compiler.elaboration.equation.Equation;
public class StandardExpressionTransformer implements
ExpressionTransformer, QueryTransformer, ListQualifierTransformer, StatementVisitor,
-EquationVisitor {
+EquationVisitor, CHRAstQueryVisitor {
@Override
public Expression transform(EAmbiguous expression) {
@Override
public void visit(CHRStatement statement) {
- for(int i=0;i<statement.body.length;++i)
- statement.body[i] = statement.body[i].accept(this);
- for(int i=0;i<statement.head.length;++i)
- statement.head[i] = statement.head[i].accept(this);
+ statement.head.accept(this);
+ statement.body.accept(this);
+ }
+
+ @Override
+ public void visit(CHRAstAtom query) {
+ query.expression = query.expression.accept(this);
+ }
+
+ @Override
+ public void visit(CHRAstBinds query) {
+ query.left = query.left.accept(this);
+ query.right = query.right.accept(this);
+ }
+
+ @Override
+ public void visit(CHRAstConjunction query) {
+ for(CHRAstQuery conjunct : query.conjuncts)
+ conjunct.accept(this);
+ }
+
+ @Override
+ public void visit(CHRAstEquals query) {
+ query.left = query.left.accept(this);
+ query.right = query.right.accept(this);
+ }
+
+ @Override
+ public void visit(CHRAstNegation query) {
+ query.subquery.accept(this);
}
}
import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
import org.simantics.scl.compiler.elaboration.chr.CHRRule;
import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstAtom;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstBinds;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstConjunction;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstEquals;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstNegation;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstQuery;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstQueryVisitor;
import org.simantics.scl.compiler.elaboration.equation.EqBasic;
import org.simantics.scl.compiler.elaboration.equation.EqGuard;
import org.simantics.scl.compiler.elaboration.equation.Equation;
import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment;
import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator;
import org.simantics.scl.compiler.elaboration.expressions.list.ListGuard;
-import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier;
import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifierVisitor;
import org.simantics.scl.compiler.elaboration.expressions.list.ListSeq;
import org.simantics.scl.compiler.elaboration.expressions.list.ListThen;
public class StandardExpressionVisitor implements
ExpressionVisitor, QueryVisitor, FieldAccessorVisitor, ListQualifierVisitor,
-EquationVisitor, StatementVisitor {
+EquationVisitor, StatementVisitor, CHRAstQueryVisitor {
@Override
public void visit(EApply expression) {
@Override
public void visit(CHRStatement statement) {
- for(ListQualifier q : statement.body)
- q.accept(this);
- for(ListQualifier q : statement.head)
- q.accept(this);
+ statement.body.accept(this);
+ statement.head.accept(this);
+ }
+
+ @Override
+ public void visit(CHRAstAtom query) {
+ query.expression.accept(this);
+ }
+
+ @Override
+ public void visit(CHRAstBinds query) {
+ query.left.accept(this);
+ query.right.accept(this);
+ }
+
+ @Override
+ public void visit(CHRAstConjunction query) {
+ for(CHRAstQuery conjunct : query.conjuncts)
+ conjunct.accept(this);
+ }
+
+ @Override
+ public void visit(CHRAstEquals query) {
+ query.left.accept(this);
+ query.right.accept(this);
+ }
+
+ @Override
+ public void visit(CHRAstNegation query) {
+ query.subquery.accept(this);
}
}
package org.simantics.scl.compiler.elaboration.expressions.block;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstQuery;
import org.simantics.scl.compiler.elaboration.contexts.EnvironmentalContext;
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
-import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier;
import org.simantics.scl.compiler.errors.Locations;
public class CHRStatement extends Statement {
- public ListQualifier[] head;
- public ListQualifier[] body;
+ public CHRAstQuery head;
+ public CHRAstQuery body;
- public CHRStatement(ListQualifier[] head, ListQualifier[] body) {
+ public CHRStatement(CHRAstQuery head, CHRAstQuery body) {
this.head = head;
this.body = body;
}
@Override
public void setLocationDeep(long loc) {
- if(location == Locations.NO_LOCATION) {
+ if(location == Locations.NO_LOCATION)
location = loc;
- for(ListQualifier lq : head)
- lq.setLocationDeep(loc);
- for(ListQualifier lq : body)
- lq.setLocationDeep(loc);
- }
}
@Override
| INCLUDE ID aexp # LocalInclude
;
+verboseChrQuery
+ = LBRACE chrQuery (SEMICOLON chrQuery)* RBRACE # VerboseCHRConjunction
+ ;
+
+
chrQuery
- = listQualifier (COMMA listQualifier)* # CHRQuery
+ = chrQueryPart (COMMA chrQueryPart)* # CHRConjunction
;
-verboseChrQuery
- = LBRACE listQualifier (SEMICOLON listQualifier)* RBRACE # VerboseCHRQuery
+chrQueryPart
+ = exp # CHRAtom
+ | exp EQUALS exp # CHREquals
+ | exp BINDS exp # CHRBinds
;
listQualifier
public static final boolean TRACE = false;
private static final int INITIAL_CAPACITY = 16;
- private static final int STATE_COUNT = 357;
+ private static final int STATE_COUNT = 362;
private static final int TERMINAL_COUNT = 85;
- private static final int NONTERMINAL_COUNT = 51;
- private static final int PRODUCT_COUNT = 135;
+ private static final int NONTERMINAL_COUNT = 52;
+ private static final int PRODUCT_COUNT = 138;
private static final int[] ACTION_ROW_ID = new int[STATE_COUNT];
private static final int[] ACTION_COLUMN_ID = new int[TERMINAL_COUNT];
- private static final short[] ACTION_TABLE = new short[6765];
- private static final int[] ERROR_TABLE = new int[949];
+ private static final short[] ACTION_TABLE = new short[6832];
+ private static final int[] ERROR_TABLE = new int[962];
private static final int[] GOTO_ROW_ID = new int[STATE_COUNT];
private static final int[] GOTO_COLUMN_ID = new int[NONTERMINAL_COUNT];
- private static final short[] GOTO_TABLE = new short[1647];
+ private static final short[] GOTO_TABLE = new short[1953];
private static final int[] PRODUCT_LHS = new int[PRODUCT_COUNT];
private static final short STATE_MASK = (short)0x0fff;
"symbolWithoutMinus",
"listQualifier",
"chrQuery",
+ "chrQueryPart",
"caseRhs",
"guardedExpArrow",
"equation",
return parse(0);
}
public Object parseCommands() {
- return parse(341);
+ return parse(346);
}
public Object parseImport() {
- return parse(349);
+ return parse(354);
}
public Object parseType() {
- return parse(351);
+ return parse(356);
}
public Object parseExp() {
- return parse(353);
+ return parse(358);
}
public Object parseEquationBlock() {
- return parse(355);
+ return parse(360);
}
case 106:
return reduceQueryBlock();
case 107:
- return reduceVerboseCHRQuery();
+ return reduceVerboseCHRConjunction();
case 108:
return reduceStringLiteral();
case 109:
case 117:
return reduceThenQualifier();
case 118:
- return reduceCHRQuery();
+ return reduceCHRConjunction();
case 119:
- return reduceSimpleCaseRhs();
+ return reduceCHRAtom();
case 120:
- return reduceGuardedCaseRhs();
+ return reduceCHREquals();
case 121:
- return reduceGuardedExpArrow();
+ return reduceCHRBinds();
case 122:
- return reduceGuardEquation();
+ return reduceSimpleCaseRhs();
case 123:
- return reduceBasicEquation();
+ return reduceGuardedCaseRhs();
case 124:
- return reduceEffect();
+ return reduceGuardedExpArrow();
case 125:
- return reduceJustEtype();
+ return reduceGuardEquation();
case 126:
- return reduceForAll();
+ return reduceBasicEquation();
case 127:
- return reduceApplyType();
+ return reduceEffect();
case 128:
+ return reduceJustEtype();
+ case 129:
+ return reduceForAll();
+ case 130:
+ return reduceApplyType();
+ case 131:
return reduceDummy();
default:
*/
protected abstract Object reduceQueryBlock();
/**
- * verboseChrQuery ::= LBRACE listQualifier (SEMICOLON listQualifier)* RBRACE
+ * verboseChrQuery ::= LBRACE chrQuery (SEMICOLON chrQuery)* RBRACE
*/
- protected abstract Object reduceVerboseCHRQuery();
+ protected abstract Object reduceVerboseCHRConjunction();
/**
* stringLiteral ::= BEGIN_STRING (SUSPEND_STRING exp CONTINUE_STRING)* END_STRING
*/
*/
protected abstract Object reduceThenQualifier();
/**
- * chrQuery ::= (listQualifier COMMA)* listQualifier
+ * chrQuery ::= (chrQueryPart COMMA)* chrQueryPart
+ */
+ protected abstract Object reduceCHRConjunction();
+ /**
+ * chrQueryPart ::= exp
+ */
+ protected abstract Object reduceCHRAtom();
+ /**
+ * chrQueryPart ::= exp EQUALS exp
+ */
+ protected abstract Object reduceCHREquals();
+ /**
+ * chrQueryPart ::= exp BINDS exp
*/
- protected abstract Object reduceCHRQuery();
+ protected abstract Object reduceCHRBinds();
/**
* caseRhs ::= ARROW exp (WHERE statements)?
*/
import org.simantics.scl.compiler.compilation.CompilationContext;
import org.simantics.scl.compiler.constants.CharacterConstant;
import org.simantics.scl.compiler.constants.StringConstant;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstAtom;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstBinds;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstConjunction;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstEquals;
+import org.simantics.scl.compiler.elaboration.chr.ast.CHRAstQuery;
import org.simantics.scl.compiler.elaboration.equation.EqBasic;
import org.simantics.scl.compiler.elaboration.equation.EqGuard;
import org.simantics.scl.compiler.elaboration.equation.Equation;
return new EViewPattern((Expression)get(1), (Expression)get(3));
}
- @Override
- protected Object reduceCHRStatement() {
- return new CHRStatement((ListQualifier[])get(0), (ListQualifier[])get(2));
- }
-
@Override
protected Object reduceConstraintStatement() {
ConstructorAst constructor = (ConstructorAst)get(1);
return new ConstraintStatement(constructor.name, constructor.parameters, constructor.fieldNames, constructor.annotations);
}
- @Override
- protected Object reduceCHRQuery() {
- ListQualifier[] query = new ListQualifier[(length()+1)/2];
- for(int i=0;i<query.length;++i)
- query[i] = (ListQualifier)get(i*2);
- return query;
- }
-
/*
@Override
protected Object reduceWhen() {
new QConjunction((Query[])get(1)),
(Expression)get(3));
}*/
-
- @Override
- protected Object reduceVerboseCHRQuery() {
- ListQualifier[] query = new ListQualifier[(length()-1)/2];
- for(int i=0;i<query.length;++i)
- query[i] = (ListQualifier)get(i*2+1);
- return query;
- }
-
- @Override
- protected Object reduceVerboseCHRStatement() {
- return new CHRStatement((ListQualifier[])get(1), (ListQualifier[])get(3));
- }
@Override
protected Object reduceDummy() {
@Override
protected Object reduceCHRSelect() {
- return new EPreCHRSelect((ListQualifier[])get(3), (Expression)get(1));
+ return new EPreCHRSelect((CHRAstQuery)get(3), (Expression)get(1));
+ }
+
+ @Override
+ protected Object reduceCHRAtom() {
+ return CHRAstAtom.atom((Expression)get(0));
+ }
+
+ @Override
+ protected Object reduceCHREquals() {
+ return new CHRAstEquals((Expression)get(0), (Expression)get(2));
+ }
+
+ @Override
+ protected Object reduceCHRBinds() {
+ return new CHRAstBinds((Expression)get(0), (Expression)get(2));
+ }
+
+ @Override
+ protected Object reduceCHRConjunction() {
+ CHRAstQuery[] conjuncts = new CHRAstQuery[(length()+1)/2];
+ for(int i=0;i<conjuncts.length;++i)
+ conjuncts[i] = (CHRAstQuery)get(i*2);
+ return CHRAstConjunction.conjunction(conjuncts);
+ }
+
+ @Override
+ protected Object reduceVerboseCHRConjunction() {
+ CHRAstQuery[] conjuncts = new CHRAstQuery[(length()-1)/2];
+ for(int i=0;i<conjuncts.length;++i)
+ conjuncts[i] = (CHRAstQuery)get(i*2+1);
+ return CHRAstConjunction.conjunction(conjuncts);
+ }
+
+ @Override
+ protected Object reduceVerboseCHRStatement() {
+ return new CHRStatement((CHRAstQuery)get(1), (CHRAstQuery)get(3));
+ }
+
+ @Override
+ protected Object reduceCHRStatement() {
+ return new CHRStatement((CHRAstQuery)get(0), (CHRAstQuery)get(2));
}
}
}
}
stackOpMap.put(a, stackOp);
- System.out.println(newState + " " + grammar.getName(a) + " " + stackOp);
+ //System.out.println(newState + " " + grammar.getName(a) + " " + stackOp);
if(stackOverflow) {
System.err.println("Stack overflow when following " + grammar.getName(a) + " at");
//builder.visualize();
- builder.printParseTable();
+ //builder.printParseTable();
return builder.getParseTable();
}
A ?x, not A (?x+1) => A (?x-1)
True => A 0
--
-0
-()
\ No newline at end of file
+6:11-6:23: CHR negation is not yet supported.
\ No newline at end of file