From: Francis Russell Date: Thu, 26 Apr 2012 22:38:34 +0000 (+0100) Subject: Start work on pattern matching. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=0cc673cabad3c7f430905d29ca74d13708229eea;p=francis%2Fofc.git Start work on pattern matching. --- diff --git a/src/ofc/expression/TreeBuilder.scala b/src/ofc/expression/TreeBuilder.scala index 6d17772..357c075 100644 --- a/src/ofc/expression/TreeBuilder.scala +++ b/src/ofc/expression/TreeBuilder.scala @@ -11,8 +11,10 @@ class TreeBuilder(dictionary : Dictionary) { if (!lhsTree.isAssignable) throw new InvalidInputException("Non-assignable expression on LHS of assignment.") - else - new Assignment(lhsTree, rhsTree) + else (lhsTree, rhsTree) match { + case (lhs: ScalarExpression, rhs: ScalarExpression) => new Assignment(lhs, rhs) + case _ => throw new InvalidInputException("Assignment must be of scalar type.") + } } private def buildIndexedOperand(term: parser.IndexedIdentifier) : Expression = { diff --git a/src/ofc/generators/Generator.scala b/src/ofc/generators/Generator.scala index f5ee970..e4b5639 100644 --- a/src/ofc/generators/Generator.scala +++ b/src/ofc/generators/Generator.scala @@ -3,5 +3,5 @@ import ofc.parser.TargetAssignment import ofc.expression.{Dictionary,Assignment} trait Generator { - def acceptInput(dictionary: Dictionary, expression: Assignment, targetSpecific : Seq[TargetAssignment]) : Unit + def acceptInput(dictionary: Dictionary, expression: Assignment, targetSpecific : Seq[TargetAssignment]) } diff --git a/src/ofc/generators/Onetep.scala b/src/ofc/generators/Onetep.scala index dc33598..c2502b6 100644 --- a/src/ofc/generators/Onetep.scala +++ b/src/ofc/generators/Onetep.scala @@ -2,12 +2,24 @@ package ofc.generators import ofc.generators.onetep._ import ofc.parser -import ofc.expression.{Assignment,Dictionary} +import ofc.expression.{Assignment,Expression,Dictionary} class Onetep extends Generator { - def acceptInput(dictionary: Dictionary, assignment: Assignment, targetSpecific : Seq[parser.TargetAssignment]) = { + def acceptInput(dictionary: Dictionary, assignment: Assignment, targetSpecific : Seq[parser.TargetAssignment]) { println(assignment) + if (matchLHS(assignment.lhs)) + println("ha!") } + + private def matchLHS(expression: Expression) : Boolean = { + import ofc.expression._ + + expression match { + case ScalarIndexingOperation(_: Matrix, List(bra, ket)) => true + case _ => false + } + } + /* def buildMatrix(id: parser.Identifier, call : Option[parser.FunctionCall]) {