Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

lexer working

  • Loading branch information...
commit 74ffe9565d45fb711a35cb99fa364a41aab5d8ed 1 parent cc5c785
Tom authored
View
BIN  Language/.SMTLIB.hs.swp
Binary file not shown
View
11 Language/SMTLIB.hs
@@ -42,11 +42,15 @@ module Language.SMTLIB
, Gv_response
, T_valuation_pair
, Gta_response
+ -- * Parsing
+ , parseSMTLIB
) where
import Data.List hiding (group)
import Text.Printf
+import qualified Language.SMTLIB.Lexer as L
+
type Numeral = Integer
type Symbol = String
type Keyword = String
@@ -429,3 +433,10 @@ group a = "( " ++ intercalate " " a ++ " )"
showBool :: Bool -> String
showBool a = if a then "true" else "false"
+parseSMTLIB :: String -> IO Script
+parseSMTLIB a = do
+ mapM_ print tokens
+ return $ Script [] --XXX
+ where
+ tokens = L.lexSMTLIB a
+
View
55 Language/SMTLIB/Lexer.x
@@ -0,0 +1,55 @@
+{
+module Language.SMTLIB.Lexer
+ ( lexSMTLIB
+ , alexScanTokens
+ , alexAndPred
+ , alexPrevCharIs
+ , alexPrevCharIsOneOf
+ , alexRightContext
+ , iUnbox
+ , alexInputPrevChar
+ ) where
+}
+
+%wrapper "basic"
+
+$digit = 0-9 -- digits
+$alpha = [a-zA-Z] -- alphabetic characters
+$other = [\+\-\/\*\=\%\?\!\.\$\_\~\&\^\<\>\@]
+$sym = [$digit$alpha$other]
+$hex = [a-fA-F$digit]
+$bin = 0-1
+
+tokens :-
+
+ $white+ ;
+ \;.* ;
+ [$sym # $digit]$sym* { Symbol }
+ \|[$printable # \|]*\| { Symbol }
+ \:$sym+ { Keyword }
+ $digit+\.$digit+ { Decimal . read }
+ $digit { Numeral . read }
+ \( { const LeftParen }
+ \) { const RightParen }
+ \"(([$printable#\\]|\\.)*)\" { String . read }
+ "#x"$hex+ { Hex . drop 2 }
+ "#b"$bin+ { Bin . drop 2 }
+ . { \ s -> error $ "unexpected character: '" ++ s ++ "'" }
+
+{
+data Token
+ = Numeral Integer
+ | Decimal Double
+ | Hex String
+ | Bin String
+ | String String
+ | Symbol String
+ | Keyword String
+ | LeftParen
+ | RightParen
+ | EOF
+ deriving (Eq,Show)
+
+lexSMTLIB :: String -> [Token]
+lexSMTLIB a = alexScanTokens a ++ [EOF]
+}
View
8 smt-lib.cabal
@@ -23,16 +23,14 @@ cabal-version: >= 1.6
library
build-depends:
base >= 4.0 && < 5.0,
+ array >= 0.3 && < 0.4,
polyparse >= 1.4
exposed-modules:
Language.SMTLIB
+ Language.SMTLIB.Lexer
--- extensions:
-
- if impl(ghc > 6.8)
- ghc-options: -fwarn-tabs
- ghc-options: -W
+ ghc-options: -W
source-repository head
type: git
Please sign in to comment.
Something went wrong with that request. Please try again.