Greg is a tiny Go-based interpreter for a very small, experimental language. This project is still evolving, so the syntax below reflects the currently working implementation rather than a formal language specification.
- Go 1.27.1 or later
You can execute a source file directly:
go run . path/to/program.hsUse -v to print the source, tokens, and current variable values before the
program runs:
go run . -v path/to/program.hsYou can also build a standalone binary:
go build -o greg .
./greg path/to/program.hsThe parser currently supports:
- typed declarations:
i^,f^, ands^ - numeric expressions with
+,-,*, and/ - comparisons with
>and< ++and--increment/decrement operatorsif/elseblocks with bracesfor (init; condition; update) { ... }loopsprintf("format", args...)output
Declare and print variables:
i^count = 2
f^ratio = 3.5
s^message = "hello"
printf("%v %v %v\n", count, ratio, message)
This prints:
2 3.5 hello
Conditional logic:
i^count = 2
if count > 1 {
printf("large\n")
} else {
printf("small\n")
}
This prints:
large
For loops:
for (i^i = 0; i < 10; i++) {
printf("%v ", i)
}
This prints:
0 1 2 3 4 5 6 7 8 9
This interpreter is intentionally minimal and not fully general-purpose. In the
current implementation, simple reassignment such as count = count + 1 is not
handled by the parser; use declaration syntax plus ++ / -- for updates.
The example programs in the repository are under test/ and are the best
reference for the current syntax and behavior.
Note: this README was drafted with AI because I have a life.