Skip to content

HaskellTreeDSL is a BASIC-like DSL written in Haskell, the demo code currently renders an ASCII art festive tree, extensively developed with the aid of generative AI.

License

Notifications You must be signed in to change notification settings

mark1010/HaskellTreeDSL

Repository files navigation

HaskellTreeDSL

A minimal BASIC-like Domain Specific Language (DSL), implemented in Haskell 🧐.

This project is a demo, with 'minimum viable' BASIC language features largely implemented through AI code generation.

Festive tree

The BASIC code, for the tree outline (without decorations), looks like this:

10 FOR i = 1 TO 12
20 LET spaces = 12 - i
30 LET tree = i * 2 - 1
40 FOR j = 1 TO spaces
45 COLOR "Green"
50 PRINT " ";
60 NEXT j
70 FOR k = 1 TO tree
80 PRINT "/";
90 NEXT k
100 PRINT
110 NEXT i
125 COLOR "Brown"
120 PRINT "         ||||"
125 COLOR "Red"
130 PRINT "       ________"

Background

ChatGPT generated the BASIC outline for the tree, without decorations, and the fundamentals of the Haskell parser.

To improve the accuracy of the generated code, a custom GPT was used, Haskell Parser Helper GPT, with key help files from Megaparsec loaded as knowledge. This did seem to improve the generated code accuracy to a degree, but further refinement is needed. The parser is not entirely AI generated, it needed a little tweaking to fix a couple of end of line / keyword handling issues that crept in.

devcontainer

This project 'should' launch in a devcontainer: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers

run

build and run as a binary:

stack run

to debug / develop

run in ghci:

stack ghci

ghci> SamplePrograms.main

SamplePrograms.hs contains other programs to run, with a little tweaking.

test cases

run the test cases:

stack ghci --test

(option 2)

ghci> Main.main

Additional notes:

Testing

List the tests:

stack test --test-arguments "--dry-run"

Run a specific test:

stack test --test-arguments "-m \"parses valid LET statement"\"

stack test --test-arguments "-m \"parses valid LET statement with arithmetic"\"

stack test --test-arguments "-m \"FOR NEXT program tests/parses valid FOR statement in program, with PRINT"\"

stack test --test-arguments "-m \"FOR NEXT tests"\"

traceShow

Add traceShow within parsers to log the parser state:

  -- Debugging prints
  let debugInfo = (ln, varName, startExpr, endExpr)
  traceShow debugInfo $ return ()

About

HaskellTreeDSL is a BASIC-like DSL written in Haskell, the demo code currently renders an ASCII art festive tree, extensively developed with the aid of generative AI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published