The hwhile package

[ Tags: gpl, language, library, program ] [ Propose Tags ]

An implementation of Neil D. Jones' While language. Developed in collaboration with Dr. Bernhard Reus (University of Sussex, UK) for use in the Limits of Computing module.


[Skip to Readme]

Properties

Versions 0.1.1.0, 0.1.1.1, 0.1.1.2
Dependencies array (==0.5.*), base (>=4.8 && <4.11), containers (==0.5.*), filepath, haskeline, hwhile, mtl, repline [details]
License GPL-3
Author Alex Jeffery
Maintainer apjeffery136@gmail.com
Category Language
Source repo head: git clone git@github.com:alexj136/HWhile.git
Uploaded Wed Jan 17 17:03:29 UTC 2018 by alexj136
Distributions NixOS:0.1.1.2
Executables hwhile
Downloads 88 total (25 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-01-17 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for hwhile-0.1.1.2

[back to package description]

HWhile

HWhile is an interpreter for a simple While language originally used by Neil Jones in his book “Computability and Complexity". The While language is a simple imperative programming language with while-loops, assignment and conditionals. It has a single data type: binary trees. The HWhile interpreter is written in Haskell.

This current implementation also includes syntactic sugar such as switch statements, macros, list notation, equality, and natural number literals. It therefore supports (almost fully) the version of While used in Bernhard Reus’ textbook Limits of Computation - From a Programming Perspective and has been developed in co-operation with Bernhard to support students on the corresponding module at Sussex University. This version also allows one to translate while programs into programs as data. For this to work, all the syntax sugar (extensions) of a While program has to be removed again.

More about the syntax and the semantics (and usage) of the While language can be found in Bernhard’s textbook (Chapter 3-5).

Syntax

The grammar below gives exactly the concrete syntax of this implementation:

PROG  ::= ID read ID BLOCK write ID

BLOCK ::= { CMDS }
        | {}

CMDS  ::= CMD ; CMD
        | CMD

CMD   ::= ID := EXP                     // Assignment
        | while EXP BLOCK               // While loops
        | if EXP BLOCK else BLOCK       // If-then-else statements
        | if EXP BLOCK                  // If-then statements
        | ID := <ID> EXP                // Macro calls
        | switch EXP { CASES            // Switch statements

CASES ::= case EXP : CMDS CASES
        | default : CMDS }
        | }

EXP   ::= LIT
        | cons EXP EXP
        | hd EXP
        | tl EXP
        | (EXP)
        | EXP = EXP
        | ID
        | []
        | [ EXP LIST

LIST  ::= , EXP LIST
        | ]
      
LIT   ::= nil
        | true
        | false
        | <LIT.LIT>
        | NAT
        | @asgn
        | @:=
        | @doAsgn
        | @while
        | @doWhile
        | @if
        | @doIf
        | @var
        | @quote
        | @hd
        | @doHd
        | @tl
        | @doTl
        | @cons
        | @doCons
      
NAT   ::= 0|[1-9][0-9]+
      
ID    ::= [a-zA-Z_'][a-zA-Z0-9_']*

Command line input must conform to the following grammar:

INP    ::= nil
        | true
        | false
        | <LIT.LIT>
        | NAT
        | []
        | [ INP INPLST
        | @asgn
        | @:=
        | @doAsgn
        | @while
        | @doWhile
        | @if
        | @doIf
        | @var
        | @quote
        | @hd
        | @doHd
        | @tl
        | @doTl
        | @cons
        | @doCons

INPLST ::= , INP INPLST
        | ]

Instructions

Installing Prerequisites

All the tools required to compile and run HWhile are included in the Haskell Platform.

Note that you may need to add the Haskell Platform's binaries to your system's path variable.

Installing HWhile

Once the Haskell Platform is installed and configured correctly, you can install HWhile by running:

stack install hwhile

This will download HWhile and its depenencies (if necessary) and compile and install them.

Invocation

If installed correctly, HWhile can be run with the command:

hwhile <FLAG> <FILE> <EXPR>        ( Mac & Linux )
hwhile.exe <FLAG> <FILE> <EXPR>    ( Windows     )

For example:

hwhile -i examples/count.while "[1, 2, 3]"         ( Mac & Linux )
hwhile.exe -i examples/count.while "[1, 2, 3]"     ( Windows     )

This example takes a list of numbers as its argument and outputs their sum, so you should see 6 as the output.