diff options
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | doc/grammar.txt | 28 |
2 files changed, 24 insertions, 14 deletions
@@ -1,7 +1,10 @@ .POSIX: BINOUT = .bin -OBJ = src/main.o +HDR = include/lex.h +OBJ = \ + src/lex.o \ + src/main.o $(BINOUT)/cerc: $(OBJ) @mkdir -p -- $(BINOUT) @@ -17,6 +20,11 @@ src/main.o: $(HDR) @printf 'CC\t%s\n' '$@' @$(CC) -c $(CFLAGS) -o $@ $< +$(BINOUT)/cerc: $(OBJ) + @mkdir -p -- $(BINOUT) + @printf 'CCLD\t%s\n' '$@' + @$(CC) $(LDFLAGS) -o $@ $(OBJ) + clean: @rm -rf -- $(BINOUT) $(OBJ) diff --git a/doc/grammar.txt b/doc/grammar.txt index 77f5763..c78e2a6 100644 --- a/doc/grammar.txt +++ b/doc/grammar.txt @@ -1,12 +1,14 @@ root := toplevel* -toplevel := externfunc | function | constant +toplevel := import* ( externfunc | function | constant ) -function := [ "export" ] "func" IDENT "(" ( param ), ")" IDENT block -param := IDENT type +import := "import" IDENT [ NAME ] ";" -externfunc := "extern" "func" IDENT "(" ( type ), ")" IDENT ";" +function := [ "pub" ] [ "export" ] "func" NAME "(" ( param ), ")" type block +param := NAME type -constant := "const" IDENT "=" ( type | bool | INTEGER | FLOAT | STRING* ) ";" +externfunc := "extern" "func" NAME "(" ( type ), ")" type ";" + +constant := [ "pub" ] "const" NAME "=" ( type | bool | INTEGER | FLOAT | STRING* ) ";" block := "{" body* "}" @@ -26,19 +28,19 @@ if := "if" expression block elseif* else* elseif := "else" "if" expression block else := "else" block -for := [ ":" IDENT ] [ assignment ";" ] expression [ ";" assignment ] block +for := [ ":" NAME ] [ assignment ";" ] expression [ ";" assignment ] block return := "return" expression -break := "break" ":" IDENT -continue := "continue" ":" IDENT +break := "break" ":" NAME +continue := "continue" ":" NAME -declaration := "let" [ "mut" ] IDENT "=" expression ";" +declaration := "let" [ "mut" ] NAME "=" expression ";" assignment := location "=" expression ";" -location := IDENT ( index | field )* [ "*" ] +location := NAME ( index | field )* [ "*" ] index := "[" INTEGER "]" -field := "." IDENT +field := "." NAME call := IDENT "(" ( expression ), ")" @@ -55,9 +57,9 @@ float := "f32" | "f64" array := "[" INTEGER "]" type slice := "[]" type struct := "struct" "{" fields "}" -enum := "enum" [ expression ] "{" ( IDENT ), "}" +enum := "enum" [ expression ] "{" ( NAME ), "}" union := "union" [ type ] "{" fields "}" -fields := ( IDENT type ), +fields := ( NAME type ), expression := equality | comparison equality := comparison ( "==" | "!=" ) comparison |