Skip to content
Snippets Groups Projects
Commit 46e2b399 authored by kwsa1g20's avatar kwsa1g20
Browse files

Lexer first draft

parent 139988ab
No related branches found
No related tags found
No related merge requests found
Tokens.hs 0 → 100644
This diff is collapsed.
......@@ -11,7 +11,7 @@ tokens :-
$white+ ;
"--".* ;
$digit+ { tok (\p s -> TokenInt p (read s) )}
$digit+ { tok (\p s -> TokenDigit p (read s) )}
\- { tok (\p s -> TokenMinus p )}
\* { tok (\p s -> TokenMult p )}
\/ { tok (\p s -> TokenDiv p )}
......@@ -52,7 +52,7 @@ tokens :-
Bool { tok (\p s -> TokenBool p )}
true { tok (\p s -> TokenBTrue p )}
false { tok (\p s -> TokenBFalse p )}
'[' $alpha [$alpha $digit \_ \']* ']' {tok (\p s -> TokenGroup p)}
\[ $alpha [$alpha $digit \_ \']* \] {tok (\p s -> TokenGroup p )}
$alpha [$alpha $digit \_ \']* { tok (\p s -> TokenVar p s)}
{
......@@ -62,10 +62,96 @@ tok f p s = f p s
-- The token type:
data TokenType =
Var AlexPosn String |
Int AlexPosn Int
TokenDigit AlexPosn Int |
TokenMinus AlexPosn |
TokenMult AlexPosn |
TokenDiv AlexPosn |
TokenOpBracket AlexPosn |
TokenClBracket AlexPosn |
TokenEq AlexPosn |
TokenPlus AlexPosn |
TokenDot AlexPosn |
TokenLess AlexPosn |
TokenComma AlexPosn |
TokenOSBracket AlexPosn |
TokenClSBracket AlexPosn |
TokenClCurBracket AlexPosn |
TokenOCurBracket AlexPosn |
TokenIf AlexPosn |
TokenThen AlexPosn |
TokenElse AlexPosn |
TokenFor AlexPosn |
TokenEmpty AlexPosn |
TokenCreate AlexPosn |
TokenBlank AlexPosn |
TokenFlipX AlexPosn |
TokenFlipY AlexPosn |
TokenRotate AlexPosn |
TokenSubtile AlexPosn |
TokenConj AlexPosn |
TokenNeg AlexPosn |
TokenSupersize AlexPosn |
TokenStack AlexPosn |
TokenJoin AlexPosn |
TokenShape AlexPosn |
TokenAND AlexPosn |
TokenOR AlexPosn |
TokenNOT AlexPosn |
TokenInt AlexPosn |
TokenTile AlexPosn |
TokenTileG AlexPosn |
TokenBool AlexPosn |
TokenBTrue AlexPosn |
TokenBFalse AlexPosn |
TokenGroup AlexPosn |
TokenVar AlexPosn String
deriving (Eq,Show)
token_posn (Var p _) = p
token_posn (Int p _) = p
token_posn (TokenDigit (AlexPn a l c)_) = show(l) ++ ":" ++ show(c)
token_posn (TokenMinus (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenMult (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenDiv (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenOpBracket (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenClBracket (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenEq (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenPlus (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenDot (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenLess (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenComma (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenOSBracket (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenClSBracket (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenClCurBracket (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenOCurBracket (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenIf (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenThen (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenElse (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenFor (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenCreate (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenBlank (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenFlipX (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenFlipY (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenRotate (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenSubtile (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenConj (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenNeg (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenSupersize (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenStack (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenJoin (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenShape (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenAND (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenOR (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenNOT (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenInt (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenTile (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenTileG (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenBool (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenBTrue (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenBFalse (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenGroup (AlexPn a l c) ) = show(l) ++ ":" ++ show(c)
token_posn (TokenVar (AlexPn a l c) _) = show(l) ++ ":" ++ show(c)
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment