14 files changed, 83 insertions(+), 0 deletions(-)
R codegen/{add_one.ssa => gen/add_one.ssa}
R codegen/{array.ssa => gen/array.ssa}
R codegen/{hello.ssa => gen/hello.ssa}
R codegen/{literal_string.ssa => gen/literal_string.ssa}
R codegen/{new.ssa => gen/new.ssa}
R codegen/{optional.ssa => gen/optional.ssa}
R syntax/{declarations.snow => tax/declarations.snow}
R syntax/{modules.snow => tax/modules.snow}
R syntax/{overview.snow => tax/overview.snow}
R syntax/{pointers.snow => tax/pointers.snow}
A go.mod
A go.sum
A pkg/grammar/grammar.ebnf
A pkg/grammar/grammar_test.go
R codegen/add_one.ssa => exp/codegen/add_one.ssa +0 -0
R codegen/array.ssa => exp/codegen/array.ssa +0 -0
R codegen/hello.ssa => exp/codegen/hello.ssa +0 -0
R codegen/literal_string.ssa => exp/codegen/literal_string.ssa +0 -0
R codegen/new.ssa => exp/codegen/new.ssa +0 -0
R codegen/optional.ssa => exp/codegen/optional.ssa +0 -0
R syntax/declarations.snow => exp/syntax/declarations.snow +0 -0
R syntax/modules.snow => exp/syntax/modules.snow +0 -0
R syntax/overview.snow => exp/syntax/overview.snow +0 -0
R syntax/pointers.snow => exp/syntax/pointers.snow +0 -0
A go.mod => go.mod +5 -0
@@ 0,0 1,5 @@
+module git.sr.ht/~mna/snow
+
+go 1.13
+
+require golang.org/x/exp v0.0.0-20191129062945-2f5052295587
A go.sum => go.sum +21 -0
@@ 0,0 1,21 @@
+dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
+github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
+github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
+golang.org/x/exp v0.0.0-20191129062945-2f5052295587 h1:5Uz0rkjCFu9BC9gCRN7EkwVvhNyQgGWb8KNJrPwBoHY=
+golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
+golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
+golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
+golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
+golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
A pkg/grammar/grammar.ebnf => pkg/grammar/grammar.ebnf +32 -0
@@ 0,0 1,32 @@
+SourceFile = { TopLevelStmt } .
+TopLevelStmt = VarDef | FuncDef .
+
+// TODO(VarDef): eventually support groups of var/let definitions.
+// TODO(ArgsList): eventually support grouping multiple argument names of same type
+// TODO: type is not just an identifier, more complex (e.g. func type, tuple type, generics, etc.)
+// TODO(Stmt): for now, limit to variable definitions and return expressions.
+
+VarDef = LetVarDef | VarVarDef .
+LetVarDef = "let" ident ( TypedVarDef | InferredVarDef ) .
+VarVarDef = "var" ident ( TypedVarDef | InferredVarDef ) .
+TypedVarDef = ":" ident [ InferredVarDef ] .
+InferredVarDef = "=" Expr .
+
+FuncDef = "fn" ident ArgsList [ FuncTrailer ] Block .
+ArgsList = "(" ArgDef { "," ArgDef } ")" .
+ArgDef = ident ":" ident .
+FuncTrailer = "->" ident .
+Block = "{" { Stmt } "}" .
+
+Stmt = VarDef | ReturnStmt .
+ReturnStmt = "return" [ Expr ] .
+
+Expr = Term { ( "+" | "-" ) Term } .
+Term = Factor { ( "*" | "/" | "%" ) Factor } .
+Factor = ( "+" | "-" ) Factor | Atom .
+Atom = "(" Expr ")" | ident | number | string .
+
+// NOTE: not actual definitions, tokenizer is the source of truth.
+ident = "a" … "z" { ( "a" … "z" | "0" … "9" | "A" … "Z" | "_" ) } [ "!" | "?" ] .
+number = "0" … "9" { "0" … "9" } .
+string = "\"" { " " … "~" } "\"" .
A pkg/grammar/grammar_test.go => pkg/grammar/grammar_test.go +25 -0
@@ 0,0 1,25 @@
+package grammar
+
+import (
+ "os"
+ "testing"
+
+ "golang.org/x/exp/ebnf"
+)
+
+func TestEBNF(t *testing.T) {
+ const filename = "grammar.ebnf"
+ f, err := os.Open(filename)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+
+ g, err := ebnf.Parse(filename, f)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := ebnf.Verify(g, "SourceFile"); err != nil {
+ t.Fatal(err)
+ }
+}