Permalink
Browse files

lexer working

  • Loading branch information...
1 parent cc5c785 commit 74ffe9565d45fb711a35cb99fa364a41aab5d8ed Tom committed Jul 7, 2010
Showing with 69 additions and 5 deletions.
  1. BIN Language/.SMTLIB.hs.swp
  2. +11 −0 Language/SMTLIB.hs
  3. +55 −0 Language/SMTLIB/Lexer.x
  4. +3 −5 smt-lib.cabal
View
Binary file not shown.
View
@@ -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
@@ -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
@@ -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

0 comments on commit 74ffe95

Please sign in to comment.