First version of Pinn, in ANTLR and Go. Archived, but works as is.
Pinn is a statically typed, imperative language for computers.
- Syntax taken mostly from Go.
- Carefully chosen ideas from Swift.
Most lexical elements are borrowed from Go. Later elements include support for _ in numeric literals and binary floating point.
int. Always a signed 64-bit.bool. Standard,trueorfalse.string. Immutable.big. Big integer.float. Big float. See Go.char. Character. Implemented as UTF-32.
- Scalar is a single element.
map. Key is always a string. Like Go, a missing string returns the zero value.slice. Pointer to a region of an array or slice. Shares memory in Go and copies in Swift.array. Arrays are passed by value.
- Almost all taken from Go, so much like c/Java. Conditional expression was put back in.
( <function> | <statement>)+ EOF
"{" { <statement> } "}"
while <expr> <block>- Evaluate
expr. If true, executeblockand repeat this line. If false, go on.
- Evaluate
repeat <block> while <expr>- Execute
block. Evaluateexpr. If true, repeat this line.
- Execute
return [<expr>] ;- Return from function. The
exprmust match the return type, or empty if there is none. If global, there is no return type.
- Return from function. The
if <expr> <statement> [else <statement>]- Evaluate
expr. If true, exectue firststatement. If false, either move on or execute secondstatement.
- Evaluate
guard <expr> else <block>- Evaluate
expr. If false, executeblock. The block must relinquish control, with areturn,break, orcontinue.
- Evaluate
<id> <kind> [ = <expr_list> ]- Declare
idofkindtype. Optionally initialize it.
- Declare
id := <expr>- Short declaration.
The grammar is clean of implementation language and is written in ANTLR. It has implementations in Go and Swift. The Swift implementation is more recent and at https://github.com/keppel2/pinnSwift.
Get ANTLR from https://www.antlr.org/download.html.
Save the following to hello.pinn:
func main ( ) { print ("Hello, world."); }
Then run the ANTLR code and run go run . -f hello.pinn. You should see:
Hello, world.
java -jar <path_to_antlr_jar> -Dlanguage=Go -o pparser Pinn.g4
| alternation
() grouping
[] option (0 or 1 times)
{} repetition (0 to n times)
literal type as specified
<production> rule specified elsewhere
"{" "[" ... notation elements as literals