https://github.com/lukakerr/sea
A simple lexer, parser and evaluator for a C like language
https://github.com/lukakerr/sea
evaluator lexer parser recursive-descent-parser
Last synced: 10 months ago
JSON representation
A simple lexer, parser and evaluator for a C like language
- Host: GitHub
- URL: https://github.com/lukakerr/sea
- Owner: lukakerr
- Created: 2018-11-17T22:33:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-01T09:00:16.000Z (over 7 years ago)
- Last Synced: 2025-08-14T01:06:37.217Z (10 months ago)
- Topics: evaluator, lexer, parser, recursive-descent-parser
- Language: Haskell
- Homepage:
- Size: 65.4 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sea
A simple evaluator for a C like language, currently a work in progress.
Built to learn Haskell and the process of writing a lexer, parser and evaluator.
A recursive descent parser is used for parsing.
Currently in the very early stages of development.
### Running
First build `sea`
```bash
$ stack build
```
You can write a `.sea` program and evaluate, lex or parse it:
```bash
# Run the evaluator
$ stack run sea tests/evaluator/2.sea
# Run the lexer
$ stack run sea tests/evaluator/2.sea --lexer
# Run the parser
$ stack run sea tests/evaluator/2.sea --parser
```
Or you can run the interactive REPL:
```bash
$ stack run sea repl
# Sea> 1 + 2
# 3
# Sea> str n = "Hello Sea" n
# Hello Sea
# Sea> :q
```
### Testing
```bash
$ ./test.sh
```
### Examples
Below is an example `.sea` program to demonstrate the syntax.
This will be updated as the parser and evaluator progress.
```assembly
;; sea only supports a single main {} function currently
fn main {} (
num n = 3 * 4
str s = "Hello world"
str ss = s + " again"
if {n > 10} (
ret ss
) else (
ret s
)
)
```