-
Notifications
You must be signed in to change notification settings - Fork 0
/
C++Front2.hs
38 lines (32 loc) · 1.16 KB
/
C++Front2.hs
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
{-# LANGUAGE QuasiQuotes #-}
module Main where
import LamParser
import Transformer
import StringQQ
----------------------------------------------------------------------
-- data LamDeBruijn = UnboundSym String
-- | BoundSym Int
-- | LamDB LamDeBruijn -- 1 parameter functions, we no
-- -- longer need to specify the dummy
-- -- parameter.
-- | AppDB LamDeBruijn LamDeBruijn
analyze :: LamDeBruijn -> String
analyze (UnboundSym s) = "symbol(\"" ++ s ++ "\")"
analyze (BoundSym n) = "variable(" ++ show n ++ ")"
analyze (LamDB v) = "lambda(" ++ analyze v ++ ")"
analyze (AppDB a b) = "apply(" ++ analyze a ++ "," ++ analyze b ++ ")"
----------------------------------------------------------------------
headerStr :: String
headerStr = [stringQQ|
#include <iostream>
#include "lam_int.h"
|]
addMain :: String -> String
addMain s = "int main() {std::cout << show(NULL,"
++ s
++ ") << std::endl;return 0; }\n"
main :: IO ()
main =
do val <- getContents
putStrLn headerStr
putStrLn $ addMain $ analyze $ toDeBruijn $ readExpr val