小编Jus*_*n B的帖子

编写用于计算命令式编程语言的指称语义的haskell程序

我正在尝试在Haskell中编写一个程序来计算具有整数变量,一维(整数)数组和函数的命令式语言程序的指称语义.我开始的功能是这样的类型:

    progsem :: Prog -> State -> State
Run Code Online (Sandbox Code Playgroud)

国家如下:

    type State (Name -> Int, Name -> Int -> Int)
Run Code Online (Sandbox Code Playgroud)

第一部分是整数变量的值,而第二部分是特定索引处的数组变量的值.

该计划将具有以下品质:

  • progsem将在程序执行后返回结果状态

  • 函数有两个参数列表,一个用于整数变量,另一个用于数组变量.

  • 函数是按值调用的结果

以下是命令式语言的抽象语法:

     -- names (variables) are just strings.
     type Name = String

     -- a program is a series (list) of function definitions, followed by a
     -- series of statements.
     type Prog = ([FunDefn],[Stmt])

     -- a statement is either...
     data Stmt =
         Assign Name Exp              -- ...assignment (<name> := <exp>;)
       | If BExp [Stmt] [Stmt]        -- ...if-then-else (if …
Run Code Online (Sandbox Code Playgroud)

haskell imperative denotational-semantics semantics

4
推荐指数
1
解决办法
696
查看次数

为用命令式编程语言编写的类型检查程序编写 Haskell 程序

我正在尝试用 Haskell 编写一个程序来键入用命令式编程语言编写的检查程序。

这是抽象语法:


    type Name = String
Run Code Online (Sandbox Code Playgroud)

-- 程序是一系列(列表)变量声明和一系列(列表)语句。

    type Prog = ([TypeEnv],[Stmt])
Run Code Online (Sandbox Code Playgroud)

-- 变量声明是一个类型和一个变量名

    type TypeEnv = (Type,Name)
Run Code Online (Sandbox Code Playgroud)

-- 类型是“int”或“bool”,或“int[]..[]”或“bool[]..[]”

   data Type = BaseType BT | ArrayType BT Int deriving Show
   data BT = TyInt | TyBool deriving Show
Run Code Online (Sandbox Code Playgroud)

——声明要么是...

   data Stmt =
   Assign Name Exp                -- ...assignment (<name> := <exp>;)
   | If Exp [Stmt] [Stmt]           -- ...if-then-else (if <bexp> { <stmt>* } else { <stmt>* })
   | While Exp [Stmt]               -- ...a while-loop (while <bexp> { <stmt>*> …
Run Code Online (Sandbox Code Playgroud)

haskell types imperative imp

2
推荐指数
1
解决办法
860
查看次数