snail: A programming language with no semantics

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

An s-expression parser and abstract syntax tree for a programming language with no semantics. If you wanted to write an interpreter or compiler you convert the AST into your own.


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.1.2.1
Change log None available
Dependencies base (>=4.15 && <5), containers (>=0.6.7 && <0.7), megaparsec (>=9.3.1 && <9.4), mtl (>=2.2.2 && <2.3), QuickCheck (>=2.14.3 && <2.15), text (>=2.0.2 && <2.1), text-display (>=0.0.5 && <0.1) [details]
License MIT
Copyright Barry Moore II
Author Barry Moore II
Maintainer chiroptical@gmail.com
Category Parsing
Home page https://github.com/chiroptical/snail#readme
Bug tracker https://github.com/chiroptical/snail/issues
Source repo head: git clone https://github.com/chiroptical/snail
Uploaded by chiroptical at 2023-08-26T20:41:42Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for snail-0.1.0.0

[back to package description]

Snail

A no-semantics programming language for gastropods.

Why?

My colleagues and I are going to start working through Types and Progamming Languages. In the book you implement languages of varying feature sets. The book implements these languages in OCaml, however I had this Lisp parser essentially ready for awhile. There are a handful of "Write you a Scheme Interpreters"-like tutorials and they all use a parser relatively similar to this one. However, there are some pretty subtle issues with most of the ones I have seen. For example, the two examples below parse as two lexemes in a lot of examples. Even Haskell's parser has this issue!

(1a)
(1 a)

Is this really a programming language?

From the "Programming language" wikipedia page,

A programming language is a system of notation for writing computer programs.

The description of a programming language is usually split into the two components of syntax (form) and semantics (meaning)

Snail is used for writing interpreters or compilers. However, it doesn't define any semantics. So, maybe?

Syntax (form)

Snail describes valid lexemes, text literals, and s-expressions. The valid lexemes are approximately from R5RS Scheme but this may change in the future. We also use Haskell's line and block comments. Here is a valid snail program,

-- Prints `hello "world"` to the console
(print "hello \"world\"")

-- Prints 3 to the console
(print (+ 1 2))

{-
  Defines a function to add two numbers
  Applies the function to generate 3
  Prints 3 to the console
-}
(let
  (f (lambda (x y) (+ x y)))
  (print (f 2 1)))

(quote hello)

(nil)

(print true)

(print false)

-- end comment

Reminder, this program has no semantics. It is your job to take Snail's Abstract Syntax Tree (AST) and define the semantics of an interpreter or compiler.

Getting the AST

You can see some examples in test/Snail/IOSpec.hs, but you can put your snail program into some file, let's say hello.snail. The following Haskell will print the AST or print a failure,

module Main where

import Snail

main :: IO ()
main = do
  eResults <- readSnailFile "./hello.snail"
  case eResults of
    Right ast -> print ast
    Left failureString -> print failureString