Pascal grammar is defined for ANTLR: https://github.com/antlr/grammars-v4/tree/master/pascal and a copy is available in res folder.
This is my pet project to learn haskell and it does not cover 100% of pascal grammar. But it can execute HelloWorld.pas.
- To execute a program: runhaskell Pascal.hs res/examples/helloworld.pas
- To view abstract syntax tree: runhaskell Pascal.hs ast res/examples/helloworld.pas
- To view tokens: runhaskell Pascal.hs lex res/examples/helloworld.pas
Project implements standard modules: lexer, parser and interpreter.
LexerTokens.hs - all tokens defined in grammar.
LexerRules.hs - all rules to read specific tokens from an input stream. This step implemented via regex matching (which is slow).
Lexer.hs - actual code to provide tokens from an input.
AST.hs - abstract syntax tree definitions.
Parser.hs - parser rules.
Interpreter.hs - executes a given abstract syntax tree.
Pascal.hs - command line interface.
Tests use Hspec. To run manually: runhaskell test/NAME_OF_TEST_CASE_FILE