]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Update parser to handle new syntax.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 23 Aug 2012 16:32:04 +0000 (17:32 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 23 Aug 2012 16:32:04 +0000 (17:32 +0100)
examples/integrals_kinetic.ofl
src/ofc/parser/Parser.scala
src/ofc/parser/Statement.scala

index 4d55296f3be2111d95ad66c6cea9e901c6e765db..eb14a8cffe4fd23edf7eff56b4dce25550971bb5 100644 (file)
@@ -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)
index 8e9cf7bd7e86f536e8ee132edac1d18704e031d5..5bd373fd56141588fb912f63b79eb427511c5635 100644 (file)
@@ -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 : _*))
index 6c6414f14e0ccc128e8be95f79a6ba27b8a3ace5..3c6ddce5df3f49dd044ae32e12b9a119bd939023 100644 (file)
@@ -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 {