File: Tokens.x

package info (click to toggle)
alex 3.1.7-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 916 kB
  • sloc: haskell: 4,244; xml: 1,479; yacc: 246; makefile: 99; ansic: 4
file content (38 lines) | stat: -rw-r--r-- 621 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
module Main where
}

%wrapper "basic"

$digit = 0-9			-- digits
$alpha = [a-zA-Z]		-- alphabetic characters

tokens :-

  $white+				{ \s -> White }
  "--".*				{ \s -> Comment }
  let					{ \s -> Let }
  in					{ \s -> In }
  $digit+				{ \s -> Int (read s) }
  [\=\+\-\*\/\(\)]			{ \s -> Sym (head s) }
  $alpha [$alpha $digit \_ \']*		{ \s -> Var s }

{
-- Each right-hand side has type :: String -> Token

-- The token type:
data Token =
        White		|
        Comment		|
	Let 		|
	In  		|
	Sym Char	|
	Var String	|
	Int Int		|
	Err 
	deriving (Eq,Show)

main = do
  s <- getContents
  print (alexScanTokens s)
}