GithubHelp home page GithubHelp logo

jrp2014 / hforth Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 159 KB

A Forth interpreter in Haskell

License: MIT License

Haskell 87.49% Forth 11.95% Shell 0.28% Roff 0.28%
forth haskell interpreter stackbit

hforth's Introduction

hforth

Overview

A bare bones Forth-like interpreter framework in Haskell based on hsc3-forth from: http://rohandrape.net/t/hsc3-forth

There is a library, HForth that provides a data and control stack as well as a number of basic primitives. The data stack is generic. so you can adapt it to the base type of your choice. (The example apps use HForth with Rationals.) As well as the generic data stack type, Strings can be stored on the data stack. There is no access to raw addresses.

Language features

HForth has

  • some execution control primitives
    • ':' and ';' define words
    • IF ELSE THEN
    • DO LOOP I J
    • EXIT ?EXIT exit (conditionally) the excution of the current word
    • <R R> call and return
    • EMIT KEY TYPE perform IO
    • .S prints the data stack
    • ' pops the top of the stack and prints it
    • FORK KILL KILLALL allow a word to run in parallel, and be terminated
    • PAUSE pauses the current thread
    • S" pushes a string onto the stack.
    • ' puts the next word onto the stack and EXECUTE executes it
    • INCLUDED reads code from a file
    • BYE quits
    • VMSTAT and TRACE provide debugging information
  • local words (enclosed in { } can be defined in a word definition
  • DROP DUP OVER PICK ROT SWAP 2DUP 0< - are stack primitives
  • RECURSIVE allows / forbids recursive name definitions depending on whether the top of the stack is true or false

Tutorial

There is a tutorial file. The fs folder contains some further examples.

Example usage

> cabal run h-forth -- --help
Up to date
H-FORTH

Usage: h-forth [-r|--recursive] [-t|--tracing INT] [FORTH SOURCE FILENAMES...]
  A rudimentary Forth repl written in Haskell

Available options:
  -r,--recursive           Allow recursive word definitions
  -t,--tracing INT         tracing level (-1 to 3) (default: 1)
  -h,--help                Show this help text

rat-forth provides an example of how to define some further basic (arithmetic) primitive words.

To run the tutorial, you need a couple of files defining additional words.

> cabal run rat-forth  --  fs/stdlib.fs  fs/ratlib.fs fs/tutorial.fs

A further example is

> cabal run rat-forth -- fs/preForth-rts.pre fs/preForth-i386-backend.pre fs/preForth.pre

And some examples from buzzard.2

> cabal run buzzard fs/buzzard/third fs/buzzard/demo5.th

hforth's People

Contributors

jrp2014 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.