summaryrefslogtreecommitdiff
path: root/DSL/StdLib.hs
blob: 09c53384664030218e8a992caf08391c70ee3c7d (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
38
39
40
module DSL.StdLib (stdlib) where

import Data.Map.Strict (fromList)

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

stdlib :: ProcTable
stdlib = procs
  where
    p = tokenizer `chain` mult procP
    m = "Failed to parse standard library:\n"
    procs = case parse p (unlines sources) of
      Right (_, ps) -> fromList ps
      Left e        -> error $ m ++ nicePrintParserError e

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"