From 1fc3eda881031916dd6134bc49aa1c73de17982a Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Thu, 23 Aug 2012 17:32:04 +0100 Subject: [PATCH] Update parser to handle new syntax. --- examples/integrals_kinetic.ofl | 13 ++++++------- src/ofc/parser/Parser.scala | 10 +++++----- src/ofc/parser/Statement.scala | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/examples/integrals_kinetic.ofl b/examples/integrals_kinetic.ofl index 4d55296..eb14a8c 100644 --- a/examples/integrals_kinetic.ofl +++ b/examples/integrals_kinetic.ofl @@ -8,12 +8,11 @@ kinet[alpha, beta] = inner(bra[alpha], laplacian(ket[beta])*-0.5) # Implementation specific target ONETEP -Variable kinet = FortranVariable("kinet", spam3) -Variable bra_basis = FortranVariable("bra_basis", func_basis) -Variable bras_on_grid = FortranVariable("bras_on_grid", double(:)) -Variable ket_basis = FortranVariable("ket_basis", func_basis) -Variable kets_on_grid = FortranVariable("kets_on_grid", double(:)) +Variable kinet = FortranVariable("kinet", "spam3") +Variable bra_basis = FortranVariable("bra_basis", "func_basis") +Variable bras_on_grid = FortranVariable("bras_on_grid", "double(:)") +Variable ket_basis = FortranVariable("ket_basis", "func_basis") +Variable kets_on_grid = FortranVariable("kets_on_grid", "double(:)") Variable bra = PPDFunctionSet(bras_on_grid, bra_basis) Variable ket = PPDFunctionSet(kets_on_grid, ket_basis) - -FortranFunction("integrals_kinetic", kinet, bras_on_grid, bra_basis, kets_on_grid, ket_basis) +Variable output = FortranFunction("integrals_kinetic", kinet, bras_on_grid, bra_basis, kets_on_grid, ket_basis) diff --git a/src/ofc/parser/Parser.scala b/src/ofc/parser/Parser.scala index 8e9cf7b..5bd373f 100644 --- a/src/ofc/parser/Parser.scala +++ b/src/ofc/parser/Parser.scala @@ -17,10 +17,10 @@ class Parser extends JavaTokenParsers { def comment : Parser[Comment] = "#"~!".*".r ^^ (v => new Comment(v._2)) def identifier : Parser[Identifier] = ident ^^ (v => new Identifier(v)) - def oflType : Parser[OFLType] = matrixType | functionSetType | indexType - def matrixType : Parser[Matrix] = "Matrix" ^^ (_ => new Matrix) + def oflType : Parser[OFLType] = arrayType | functionSetType | indexType + def arrayType : Parser[Matrix] = "Array["~>repsep(indexType, ",")<~"]" ^^ (x => new Matrix(x)) def functionSetType : Parser[FunctionSet] = "FunctionSet" ^^ (_ => new FunctionSet) - def indexType : Parser[Index] = "Index" ^^ (_ => new Index) + def indexType : Parser[Index] = "FunctionIndex" ^^ (_ => new Index) def declarations: Parser[DeclarationList] = oflType~!repsep(identifier, ",") ^^ (d => new DeclarationList(d._1, d._2)) @@ -49,11 +49,11 @@ class Parser extends JavaTokenParsers { def operator : Parser[Operator] = identifier~("("~>repsep(expr, ",")<~")") ^^ (x => new Operator(x._1, x._2)) def target : Parser[Target] = "target"~!identifier ^^ (x => new Target(x._2)) - def specifics : Parser[TargetAssignment] = identifier~("is"~>functionCall) ^^ (x => new TargetAssignment(x._1, x._2)) + def specifics : Parser[TargetAssignment] = "Variable"~>identifier~("="~>functionCall) ^^ (x => new TargetAssignment(x._1, x._2)) def functionCall : Parser[FunctionCall] = identifier~("("~>repsep(functionParameter, ",")<~")") ^^ (x => new FunctionCall(x._1, new ParameterList(x._2 : _*))) - def functionParameter : Parser[Parameter] = stringParameter | numericParameter | parameterList + def functionParameter : Parser[Parameter] = stringParameter | numericParameter | identifier | parameterList def stringParameter : Parser[StringParameter] = stringLiteral ^^ (x => new StringParameter(x.slice(1, x.length-1))) def numericParameter : Parser[NumericParameter] = floatingPointNumber ^^ (x => new NumericParameter(x.toDouble)) def parameterList : Parser[ParameterList] = "["~>repsep(functionParameter, ",")<~"]" ^^ (x => new ParameterList(x : _*)) diff --git a/src/ofc/parser/Statement.scala b/src/ofc/parser/Statement.scala index 6c6414f..3c6ddce 100644 --- a/src/ofc/parser/Statement.scala +++ b/src/ofc/parser/Statement.scala @@ -1,6 +1,6 @@ package ofc.parser -case class Identifier(name: String) { +case class Identifier(name: String) extends Parameter { override def toString : String = "id(\""+name+"\")" def getName = name } @@ -23,7 +23,7 @@ case class TargetAssignment(id: Identifier, value: FunctionCall) extends Stateme } sealed abstract class OFLType -case class Matrix() extends OFLType { +case class Matrix(indices: List[Index]) extends OFLType { override def toString : String = "Matrix" } case class FunctionSet() extends OFLType { -- 2.47.3