From 92fd61074874351f134d3b75af779522bf641be0 Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Wed, 12 Sep 2012 09:41:38 +0100 Subject: [PATCH] Initial work on experimental Haskell implementation. --- .gitignore | 1 + Setup.hs | 2 + build.xml | 57 ---------------- ofc | 2 +- ofc.cabal | 12 ++++ {src => old}/ofc/OFC.scala | 0 .../ofc/codegen/AllocateStatement.scala | 0 .../ofc/codegen/AssignStatement.scala | 0 {src => old}/ofc/codegen/Comment.scala | 0 .../ofc/codegen/ConditionalValue.scala | 0 .../ofc/codegen/DeallocateStatement.scala | 0 {src => old}/ofc/codegen/Expression.scala | 0 {src => old}/ofc/codegen/ForLoop.scala | 0 .../ofc/codegen/FortranGenerator.scala | 0 .../ofc/codegen/FortranProperty.scala | 0 {src => old}/ofc/codegen/Function.scala | 0 {src => old}/ofc/codegen/FunctionCall.scala | 0 .../ofc/codegen/FunctionCallStatement.scala | 0 .../ofc/codegen/FunctionSignature.scala | 0 {src => old}/ofc/codegen/IfStatement.scala | 0 {src => old}/ofc/codegen/Intrinsic.scala | 0 .../ofc/codegen/IterationContext.scala | 0 .../ofc/codegen/NumericOperator.scala | 0 {src => old}/ofc/codegen/ScopeStatement.scala | 0 {src => old}/ofc/codegen/Statement.scala | 0 {src => old}/ofc/codegen/Symbol.scala | 0 {src => old}/ofc/codegen/Type.scala | 0 {src => old}/ofc/expression/Assignment.scala | 0 {src => old}/ofc/expression/Dictionary.scala | 0 {src => old}/ofc/expression/Expression.scala | 0 {src => old}/ofc/expression/TreeBuilder.scala | 0 {src => old}/ofc/generators/Generator.scala | 0 {src => old}/ofc/generators/Onetep.scala | 0 .../ofc/generators/onetep/Assignment.scala | 0 .../ofc/generators/onetep/CodeGenerator.scala | 0 .../onetep/DensePsincToReciprocal.scala | 0 .../ofc/generators/onetep/Dictionary.scala | 0 .../ofc/generators/onetep/Field.scala | 0 .../ofc/generators/onetep/FieldFragment.scala | 0 .../ofc/generators/onetep/Fragment.scala | 0 .../generators/onetep/GenerationContext.scala | 0 .../ofc/generators/onetep/InnerProduct.scala | 0 .../ofc/generators/onetep/Laplacian.scala | 0 .../ofc/generators/onetep/NamedIndex.scala | 0 .../generators/onetep/OnetepFunctions.scala | 0 .../ofc/generators/onetep/OnetepTypes.scala | 0 .../generators/onetep/OnetepVariables.scala | 0 .../ofc/generators/onetep/Operand.scala | 0 .../generators/onetep/PPDFunctionSet.scala | 0 .../generators/onetep/ReciprocalToPsinc.scala | 0 .../ofc/generators/onetep/SPAM3.scala | 0 .../ofc/generators/onetep/Scalar.scala | 0 .../generators/onetep/ScalarFragment.scala | 0 .../ofc/generators/onetep/ScalarLiteral.scala | 0 .../ofc/generators/onetep/ScaledField.scala | 0 {src => old}/ofc/parser/Parser.scala | 0 {src => old}/ofc/parser/Statement.scala | 0 {src => old}/ofc/util/DirectedGraph.scala | 0 {src => old}/ofc/util/Graph.scala | 0 {src => old}/ofc/util/GraphBase.scala | 0 {src => old}/ofc/util/Ordering.scala | 0 {src => old}/ofc/util/Queue.scala | 0 {src => old}/ofc/util/UndirectedGraph.scala | 0 src/Main.hs | 17 +++++ src/Parsing.hs | 66 +++++++++++++++++++ 65 files changed, 99 insertions(+), 58 deletions(-) create mode 100644 Setup.hs delete mode 100644 build.xml create mode 100644 ofc.cabal rename {src => old}/ofc/OFC.scala (100%) rename {src => old}/ofc/codegen/AllocateStatement.scala (100%) rename {src => old}/ofc/codegen/AssignStatement.scala (100%) rename {src => old}/ofc/codegen/Comment.scala (100%) rename {src => old}/ofc/codegen/ConditionalValue.scala (100%) rename {src => old}/ofc/codegen/DeallocateStatement.scala (100%) rename {src => old}/ofc/codegen/Expression.scala (100%) rename {src => old}/ofc/codegen/ForLoop.scala (100%) rename {src => old}/ofc/codegen/FortranGenerator.scala (100%) rename {src => old}/ofc/codegen/FortranProperty.scala (100%) rename {src => old}/ofc/codegen/Function.scala (100%) rename {src => old}/ofc/codegen/FunctionCall.scala (100%) rename {src => old}/ofc/codegen/FunctionCallStatement.scala (100%) rename {src => old}/ofc/codegen/FunctionSignature.scala (100%) rename {src => old}/ofc/codegen/IfStatement.scala (100%) rename {src => old}/ofc/codegen/Intrinsic.scala (100%) rename {src => old}/ofc/codegen/IterationContext.scala (100%) rename {src => old}/ofc/codegen/NumericOperator.scala (100%) rename {src => old}/ofc/codegen/ScopeStatement.scala (100%) rename {src => old}/ofc/codegen/Statement.scala (100%) rename {src => old}/ofc/codegen/Symbol.scala (100%) rename {src => old}/ofc/codegen/Type.scala (100%) rename {src => old}/ofc/expression/Assignment.scala (100%) rename {src => old}/ofc/expression/Dictionary.scala (100%) rename {src => old}/ofc/expression/Expression.scala (100%) rename {src => old}/ofc/expression/TreeBuilder.scala (100%) rename {src => old}/ofc/generators/Generator.scala (100%) rename {src => old}/ofc/generators/Onetep.scala (100%) rename {src => old}/ofc/generators/onetep/Assignment.scala (100%) rename {src => old}/ofc/generators/onetep/CodeGenerator.scala (100%) rename {src => old}/ofc/generators/onetep/DensePsincToReciprocal.scala (100%) rename {src => old}/ofc/generators/onetep/Dictionary.scala (100%) rename {src => old}/ofc/generators/onetep/Field.scala (100%) rename {src => old}/ofc/generators/onetep/FieldFragment.scala (100%) rename {src => old}/ofc/generators/onetep/Fragment.scala (100%) rename {src => old}/ofc/generators/onetep/GenerationContext.scala (100%) rename {src => old}/ofc/generators/onetep/InnerProduct.scala (100%) rename {src => old}/ofc/generators/onetep/Laplacian.scala (100%) rename {src => old}/ofc/generators/onetep/NamedIndex.scala (100%) rename {src => old}/ofc/generators/onetep/OnetepFunctions.scala (100%) rename {src => old}/ofc/generators/onetep/OnetepTypes.scala (100%) rename {src => old}/ofc/generators/onetep/OnetepVariables.scala (100%) rename {src => old}/ofc/generators/onetep/Operand.scala (100%) rename {src => old}/ofc/generators/onetep/PPDFunctionSet.scala (100%) rename {src => old}/ofc/generators/onetep/ReciprocalToPsinc.scala (100%) rename {src => old}/ofc/generators/onetep/SPAM3.scala (100%) rename {src => old}/ofc/generators/onetep/Scalar.scala (100%) rename {src => old}/ofc/generators/onetep/ScalarFragment.scala (100%) rename {src => old}/ofc/generators/onetep/ScalarLiteral.scala (100%) rename {src => old}/ofc/generators/onetep/ScaledField.scala (100%) rename {src => old}/ofc/parser/Parser.scala (100%) rename {src => old}/ofc/parser/Statement.scala (100%) rename {src => old}/ofc/util/DirectedGraph.scala (100%) rename {src => old}/ofc/util/Graph.scala (100%) rename {src => old}/ofc/util/GraphBase.scala (100%) rename {src => old}/ofc/util/Ordering.scala (100%) rename {src => old}/ofc/util/Queue.scala (100%) rename {src => old}/ofc/util/UndirectedGraph.scala (100%) create mode 100644 src/Main.hs create mode 100644 src/Parsing.hs diff --git a/.gitignore b/.gitignore index 779e54e..7d33312 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /build/ +/dist/ ofc.jar .*.swp diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/build.xml b/build.xml deleted file mode 100644 index 1da0b34..0000000 --- a/build.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ofc b/ofc index 7e8fe60..575df54 100755 --- a/ofc +++ b/ofc @@ -1,3 +1,3 @@ #!/bin/sh -scala -cp build ofc.OFC "$@" +dist/build/ofc/ofc "$@" diff --git a/ofc.cabal b/ofc.cabal new file mode 100644 index 0000000..aae9fec --- /dev/null +++ b/ofc.cabal @@ -0,0 +1,12 @@ +Name: ofc +Version: 0.1 +Description: ONTEP Form Compiler +Author: Francis Russell +Maintainer: fpr02@doc.ic.ac.uk +Build-Type: Simple +Cabal-Version: >=1.2 + +Executable ofc + Main-is: Main.hs + Hs-Source-Dirs: src + Build-Depends: base, parsec >= 3 diff --git a/src/ofc/OFC.scala b/old/ofc/OFC.scala similarity index 100% rename from src/ofc/OFC.scala rename to old/ofc/OFC.scala diff --git a/src/ofc/codegen/AllocateStatement.scala b/old/ofc/codegen/AllocateStatement.scala similarity index 100% rename from src/ofc/codegen/AllocateStatement.scala rename to old/ofc/codegen/AllocateStatement.scala diff --git a/src/ofc/codegen/AssignStatement.scala b/old/ofc/codegen/AssignStatement.scala similarity index 100% rename from src/ofc/codegen/AssignStatement.scala rename to old/ofc/codegen/AssignStatement.scala diff --git a/src/ofc/codegen/Comment.scala b/old/ofc/codegen/Comment.scala similarity index 100% rename from src/ofc/codegen/Comment.scala rename to old/ofc/codegen/Comment.scala diff --git a/src/ofc/codegen/ConditionalValue.scala b/old/ofc/codegen/ConditionalValue.scala similarity index 100% rename from src/ofc/codegen/ConditionalValue.scala rename to old/ofc/codegen/ConditionalValue.scala diff --git a/src/ofc/codegen/DeallocateStatement.scala b/old/ofc/codegen/DeallocateStatement.scala similarity index 100% rename from src/ofc/codegen/DeallocateStatement.scala rename to old/ofc/codegen/DeallocateStatement.scala diff --git a/src/ofc/codegen/Expression.scala b/old/ofc/codegen/Expression.scala similarity index 100% rename from src/ofc/codegen/Expression.scala rename to old/ofc/codegen/Expression.scala diff --git a/src/ofc/codegen/ForLoop.scala b/old/ofc/codegen/ForLoop.scala similarity index 100% rename from src/ofc/codegen/ForLoop.scala rename to old/ofc/codegen/ForLoop.scala diff --git a/src/ofc/codegen/FortranGenerator.scala b/old/ofc/codegen/FortranGenerator.scala similarity index 100% rename from src/ofc/codegen/FortranGenerator.scala rename to old/ofc/codegen/FortranGenerator.scala diff --git a/src/ofc/codegen/FortranProperty.scala b/old/ofc/codegen/FortranProperty.scala similarity index 100% rename from src/ofc/codegen/FortranProperty.scala rename to old/ofc/codegen/FortranProperty.scala diff --git a/src/ofc/codegen/Function.scala b/old/ofc/codegen/Function.scala similarity index 100% rename from src/ofc/codegen/Function.scala rename to old/ofc/codegen/Function.scala diff --git a/src/ofc/codegen/FunctionCall.scala b/old/ofc/codegen/FunctionCall.scala similarity index 100% rename from src/ofc/codegen/FunctionCall.scala rename to old/ofc/codegen/FunctionCall.scala diff --git a/src/ofc/codegen/FunctionCallStatement.scala b/old/ofc/codegen/FunctionCallStatement.scala similarity index 100% rename from src/ofc/codegen/FunctionCallStatement.scala rename to old/ofc/codegen/FunctionCallStatement.scala diff --git a/src/ofc/codegen/FunctionSignature.scala b/old/ofc/codegen/FunctionSignature.scala similarity index 100% rename from src/ofc/codegen/FunctionSignature.scala rename to old/ofc/codegen/FunctionSignature.scala diff --git a/src/ofc/codegen/IfStatement.scala b/old/ofc/codegen/IfStatement.scala similarity index 100% rename from src/ofc/codegen/IfStatement.scala rename to old/ofc/codegen/IfStatement.scala diff --git a/src/ofc/codegen/Intrinsic.scala b/old/ofc/codegen/Intrinsic.scala similarity index 100% rename from src/ofc/codegen/Intrinsic.scala rename to old/ofc/codegen/Intrinsic.scala diff --git a/src/ofc/codegen/IterationContext.scala b/old/ofc/codegen/IterationContext.scala similarity index 100% rename from src/ofc/codegen/IterationContext.scala rename to old/ofc/codegen/IterationContext.scala diff --git a/src/ofc/codegen/NumericOperator.scala b/old/ofc/codegen/NumericOperator.scala similarity index 100% rename from src/ofc/codegen/NumericOperator.scala rename to old/ofc/codegen/NumericOperator.scala diff --git a/src/ofc/codegen/ScopeStatement.scala b/old/ofc/codegen/ScopeStatement.scala similarity index 100% rename from src/ofc/codegen/ScopeStatement.scala rename to old/ofc/codegen/ScopeStatement.scala diff --git a/src/ofc/codegen/Statement.scala b/old/ofc/codegen/Statement.scala similarity index 100% rename from src/ofc/codegen/Statement.scala rename to old/ofc/codegen/Statement.scala diff --git a/src/ofc/codegen/Symbol.scala b/old/ofc/codegen/Symbol.scala similarity index 100% rename from src/ofc/codegen/Symbol.scala rename to old/ofc/codegen/Symbol.scala diff --git a/src/ofc/codegen/Type.scala b/old/ofc/codegen/Type.scala similarity index 100% rename from src/ofc/codegen/Type.scala rename to old/ofc/codegen/Type.scala diff --git a/src/ofc/expression/Assignment.scala b/old/ofc/expression/Assignment.scala similarity index 100% rename from src/ofc/expression/Assignment.scala rename to old/ofc/expression/Assignment.scala diff --git a/src/ofc/expression/Dictionary.scala b/old/ofc/expression/Dictionary.scala similarity index 100% rename from src/ofc/expression/Dictionary.scala rename to old/ofc/expression/Dictionary.scala diff --git a/src/ofc/expression/Expression.scala b/old/ofc/expression/Expression.scala similarity index 100% rename from src/ofc/expression/Expression.scala rename to old/ofc/expression/Expression.scala diff --git a/src/ofc/expression/TreeBuilder.scala b/old/ofc/expression/TreeBuilder.scala similarity index 100% rename from src/ofc/expression/TreeBuilder.scala rename to old/ofc/expression/TreeBuilder.scala diff --git a/src/ofc/generators/Generator.scala b/old/ofc/generators/Generator.scala similarity index 100% rename from src/ofc/generators/Generator.scala rename to old/ofc/generators/Generator.scala diff --git a/src/ofc/generators/Onetep.scala b/old/ofc/generators/Onetep.scala similarity index 100% rename from src/ofc/generators/Onetep.scala rename to old/ofc/generators/Onetep.scala diff --git a/src/ofc/generators/onetep/Assignment.scala b/old/ofc/generators/onetep/Assignment.scala similarity index 100% rename from src/ofc/generators/onetep/Assignment.scala rename to old/ofc/generators/onetep/Assignment.scala diff --git a/src/ofc/generators/onetep/CodeGenerator.scala b/old/ofc/generators/onetep/CodeGenerator.scala similarity index 100% rename from src/ofc/generators/onetep/CodeGenerator.scala rename to old/ofc/generators/onetep/CodeGenerator.scala diff --git a/src/ofc/generators/onetep/DensePsincToReciprocal.scala b/old/ofc/generators/onetep/DensePsincToReciprocal.scala similarity index 100% rename from src/ofc/generators/onetep/DensePsincToReciprocal.scala rename to old/ofc/generators/onetep/DensePsincToReciprocal.scala diff --git a/src/ofc/generators/onetep/Dictionary.scala b/old/ofc/generators/onetep/Dictionary.scala similarity index 100% rename from src/ofc/generators/onetep/Dictionary.scala rename to old/ofc/generators/onetep/Dictionary.scala diff --git a/src/ofc/generators/onetep/Field.scala b/old/ofc/generators/onetep/Field.scala similarity index 100% rename from src/ofc/generators/onetep/Field.scala rename to old/ofc/generators/onetep/Field.scala diff --git a/src/ofc/generators/onetep/FieldFragment.scala b/old/ofc/generators/onetep/FieldFragment.scala similarity index 100% rename from src/ofc/generators/onetep/FieldFragment.scala rename to old/ofc/generators/onetep/FieldFragment.scala diff --git a/src/ofc/generators/onetep/Fragment.scala b/old/ofc/generators/onetep/Fragment.scala similarity index 100% rename from src/ofc/generators/onetep/Fragment.scala rename to old/ofc/generators/onetep/Fragment.scala diff --git a/src/ofc/generators/onetep/GenerationContext.scala b/old/ofc/generators/onetep/GenerationContext.scala similarity index 100% rename from src/ofc/generators/onetep/GenerationContext.scala rename to old/ofc/generators/onetep/GenerationContext.scala diff --git a/src/ofc/generators/onetep/InnerProduct.scala b/old/ofc/generators/onetep/InnerProduct.scala similarity index 100% rename from src/ofc/generators/onetep/InnerProduct.scala rename to old/ofc/generators/onetep/InnerProduct.scala diff --git a/src/ofc/generators/onetep/Laplacian.scala b/old/ofc/generators/onetep/Laplacian.scala similarity index 100% rename from src/ofc/generators/onetep/Laplacian.scala rename to old/ofc/generators/onetep/Laplacian.scala diff --git a/src/ofc/generators/onetep/NamedIndex.scala b/old/ofc/generators/onetep/NamedIndex.scala similarity index 100% rename from src/ofc/generators/onetep/NamedIndex.scala rename to old/ofc/generators/onetep/NamedIndex.scala diff --git a/src/ofc/generators/onetep/OnetepFunctions.scala b/old/ofc/generators/onetep/OnetepFunctions.scala similarity index 100% rename from src/ofc/generators/onetep/OnetepFunctions.scala rename to old/ofc/generators/onetep/OnetepFunctions.scala diff --git a/src/ofc/generators/onetep/OnetepTypes.scala b/old/ofc/generators/onetep/OnetepTypes.scala similarity index 100% rename from src/ofc/generators/onetep/OnetepTypes.scala rename to old/ofc/generators/onetep/OnetepTypes.scala diff --git a/src/ofc/generators/onetep/OnetepVariables.scala b/old/ofc/generators/onetep/OnetepVariables.scala similarity index 100% rename from src/ofc/generators/onetep/OnetepVariables.scala rename to old/ofc/generators/onetep/OnetepVariables.scala diff --git a/src/ofc/generators/onetep/Operand.scala b/old/ofc/generators/onetep/Operand.scala similarity index 100% rename from src/ofc/generators/onetep/Operand.scala rename to old/ofc/generators/onetep/Operand.scala diff --git a/src/ofc/generators/onetep/PPDFunctionSet.scala b/old/ofc/generators/onetep/PPDFunctionSet.scala similarity index 100% rename from src/ofc/generators/onetep/PPDFunctionSet.scala rename to old/ofc/generators/onetep/PPDFunctionSet.scala diff --git a/src/ofc/generators/onetep/ReciprocalToPsinc.scala b/old/ofc/generators/onetep/ReciprocalToPsinc.scala similarity index 100% rename from src/ofc/generators/onetep/ReciprocalToPsinc.scala rename to old/ofc/generators/onetep/ReciprocalToPsinc.scala diff --git a/src/ofc/generators/onetep/SPAM3.scala b/old/ofc/generators/onetep/SPAM3.scala similarity index 100% rename from src/ofc/generators/onetep/SPAM3.scala rename to old/ofc/generators/onetep/SPAM3.scala diff --git a/src/ofc/generators/onetep/Scalar.scala b/old/ofc/generators/onetep/Scalar.scala similarity index 100% rename from src/ofc/generators/onetep/Scalar.scala rename to old/ofc/generators/onetep/Scalar.scala diff --git a/src/ofc/generators/onetep/ScalarFragment.scala b/old/ofc/generators/onetep/ScalarFragment.scala similarity index 100% rename from src/ofc/generators/onetep/ScalarFragment.scala rename to old/ofc/generators/onetep/ScalarFragment.scala diff --git a/src/ofc/generators/onetep/ScalarLiteral.scala b/old/ofc/generators/onetep/ScalarLiteral.scala similarity index 100% rename from src/ofc/generators/onetep/ScalarLiteral.scala rename to old/ofc/generators/onetep/ScalarLiteral.scala diff --git a/src/ofc/generators/onetep/ScaledField.scala b/old/ofc/generators/onetep/ScaledField.scala similarity index 100% rename from src/ofc/generators/onetep/ScaledField.scala rename to old/ofc/generators/onetep/ScaledField.scala diff --git a/src/ofc/parser/Parser.scala b/old/ofc/parser/Parser.scala similarity index 100% rename from src/ofc/parser/Parser.scala rename to old/ofc/parser/Parser.scala diff --git a/src/ofc/parser/Statement.scala b/old/ofc/parser/Statement.scala similarity index 100% rename from src/ofc/parser/Statement.scala rename to old/ofc/parser/Statement.scala diff --git a/src/ofc/util/DirectedGraph.scala b/old/ofc/util/DirectedGraph.scala similarity index 100% rename from src/ofc/util/DirectedGraph.scala rename to old/ofc/util/DirectedGraph.scala diff --git a/src/ofc/util/Graph.scala b/old/ofc/util/Graph.scala similarity index 100% rename from src/ofc/util/Graph.scala rename to old/ofc/util/Graph.scala diff --git a/src/ofc/util/GraphBase.scala b/old/ofc/util/GraphBase.scala similarity index 100% rename from src/ofc/util/GraphBase.scala rename to old/ofc/util/GraphBase.scala diff --git a/src/ofc/util/Ordering.scala b/old/ofc/util/Ordering.scala similarity index 100% rename from src/ofc/util/Ordering.scala rename to old/ofc/util/Ordering.scala diff --git a/src/ofc/util/Queue.scala b/old/ofc/util/Queue.scala similarity index 100% rename from src/ofc/util/Queue.scala rename to old/ofc/util/Queue.scala diff --git a/src/ofc/util/UndirectedGraph.scala b/old/ofc/util/UndirectedGraph.scala similarity index 100% rename from src/ofc/util/UndirectedGraph.scala rename to old/ofc/util/UndirectedGraph.scala diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..6f11f2d --- /dev/null +++ b/src/Main.hs @@ -0,0 +1,17 @@ +module Main where +import System.IO (readFile) +import System.Environment (getArgs) +import Parsing + +main :: IO() +main = do + args <- getArgs + contents <- readFile $ getFileName args + processOFL contents + +getFileName :: [String] -> String +getFileName [filename] = filename +getFileName _ = error "Usage: ofc input_file" + +processOFL :: String -> IO() +processOFL input = putStrLn $ show $ parseOFL input diff --git a/src/Parsing.hs b/src/Parsing.hs new file mode 100644 index 0000000..80c313e --- /dev/null +++ b/src/Parsing.hs @@ -0,0 +1,66 @@ +module Parsing where +import Text.Parsec +import Text.Parsec.Prim +import Text.Parsec.Token +import Text.Parsec.Language +import Text.Parsec.Combinator + +data OFL = OFL [OFLDeclaration] deriving Show +data OFLType = Real | Function | Integer deriving Show +data OFLIndex = FunctionIndex | SpinIndex | SpatialIndex deriving Show +data OFLDeclaration = Declaration OFLType [OFLIndex] [String] deriving Show +data OFLAssignment = Assign OFLExpression OFLExpression deriving Show +data OFLExpression = Identifier String | IndexedIdentifier String [String] deriving Show + +oflIndexTypes = ["FunctionIndex", "SpinIndex", "SpatialIndex"] +oflOperandTypes = ["Real", "Function", "Integer"] +oflKeywords = oflIndexTypes ++ oflOperandTypes + + +oflDef = emptyDef{ commentStart = "" + , commentEnd = "" + , commentLine = "#" + , nestedComments = False + , identStart = letter + , identLetter = alphaNum <|> oneOf "_" + , caseSensitive = True + , reservedNames = oflKeywords + } + +TokenParser { reserved = oflReserved + , whiteSpace = oflWhiteSpace + , identifier = oflIdentifier + , commaSep = oflCommaSep + , brackets = oflBrackets + , symbol = oflSymbol +} = makeTokenParser oflDef + + +parseType = foldl1 (<|>) [do { oflReserved $ show t; return t} | t <- [Real, Function, Integer]] +parseIndex = foldl1 (<|>) [do { oflReserved $ show t; return t} | t <- [FunctionIndex, SpinIndex, SpatialIndex]] +parseDeclaration = do { valueType <- parseType; + indices <- oflBrackets $ oflCommaSep parseIndex; + names <- oflCommaSep parseIdentifier; + return $ Declaration valueType indices names + } + +parseIdentifier = do {identifier <- oflIdentifier; return identifier } + +parseAssignment = do { lhs <- parseExpression; + oflSymbol "="; + rhs <- parseExpression; + return $ Assign lhs rhs + } + +parseExpression = parseIndexedIdentifier <|> parseUnindexedIdentifier + + +parseUnindexedIdentifier = do { identifier <- parseIdentifier; + return $ Identifier identifier + } + +parseIndexedIdentifier = do { identifier <- parseIdentifier; + indices <- oflBrackets $ oflCommaSep parseIdentifier; + return $ IndexedIdentifier identifier indices + } +parseOFL string = parse (oflWhiteSpace >> many1 parseDeclaration >> many1 parseAssignment) "(unknown)" string -- 2.47.3