summaryrefslogtreecommitdiff
path: root/DSL/StdLib.hs
blob: 6483433676e3c0ea3ff2e775277eb0d2f2b07330 (plain)
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
module DSL.StdLib (stdlib) where

import DSL.Types
import DSL.BaseParsers (parse, mult, chain)
import DSL.Parsing (tokenizer, procP)

stdlib :: [ProcSpec]
stdlib = procs
  where
    p = tokenizer `chain` mult procP
    procs = case parse p (unlines sources) of
      Nothing      -> error "Failed to parse standard library"
      Just (_, ps) -> ps

sources :: [String]
sources = [ div'
          , mod'
          , lteq
          , gteq
          , neq
          ]

div' :: String
div' = "PROC / /% DROP END"

mod' :: String
mod' = "PROC % /% SWAP DROP END"

lteq :: String
lteq = "PROC <= OVER OVER == ROT < || END"

gteq :: String
gteq = "PROC >= OVER OVER == ROT > || END"

neq :: String
neq = "PROC != == ! END"