+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<project name="OFC" default="build">
- <property name="project.dir" value="."/>
- <property name="main.class" value="ofc.OFC"/>
-
- <target name="init">
- <!-- derived path names -->
- <property name="source.dir" value="${project.dir}/src"/>
- <property name="build.dir" value="${project.dir}/build"/>
- <property name="scala-library.jar" location="/usr/share/java/scala-library.jar"/>
- <property name="scala-compiler.jar" location="/usr/share/java/scala-compiler.jar"/>
-
- <path id="build.classpath">
- <pathelement location="${scala-library.jar}"/>
- <pathelement location="${build.dir}"/>
- </path>
-
- <path id="scala.classpath">
- <pathelement location="${scala-compiler.jar}"/>
- <pathelement location="${scala-library.jar}"/>
- </path>
-
- <!-- definition for the "scalac" and "scaladoc" ant tasks -->
- <taskdef resource="scala/tools/ant/antlib.xml" classpathref="scala.classpath">
- </taskdef>
- </target>
-
- <target name="clean" depends="init" description="clean">
- <delete dir="${build.dir}"/>
- <delete file="ofc.jar"/>
- </target>
-
- <target name="build" depends="init" description="build">
- <mkdir dir="${build.dir}"/>
- <scalac
- classpathref="build.classpath"
- srcdir="${source.dir}"
- destdir="${build.dir}"
- force="false"
- deprecation="yes"
- unchecked="yes"
- >
- <include name="**/*.scala"/>
- </scalac>
- </target>
-
- <target name="jar" depends="build">
- <jar jarfile="ofc.jar">
- <fileset dir="${build.dir}"/>
- <zipfileset includes="**/*.class" src="${scala-library.jar}"/>
- <manifest>
- <attribute name="Main-Class" value="${main.class}"/>
- </manifest>
- </jar>
- </target>
-</project>
--- /dev/null
+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
--- /dev/null
+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