| author | |
| committer | |
| log | 5b663ddbb2152b77ba71b18c7be2b6e379ae632a |
| tree | daa8695f1962c718e5fa8d26208ef35e04b0561d |
| parent | 4236b85c722b36cb31595634bae0ff28d6082761 |
3 files changed, 17 insertions(+), 17 deletions(-)
README.md+9| ... | ... | @@ -4,6 +4,15 @@ An experiment in writing a low-level programming language with the intent to |
| 4 | 4 | replace C. Zig intends to be a small language, yet powerful enough to write |
| 5 | 5 | readable, safe, optimal, and concise code to solve any computing problem. |
| 6 | 6 | |
| 7 | ## Design Principles | |
| 8 | ||
| 9 | * Never compromise power or performance. | |
| 10 | * Keep the language small and easy to understand. C programmers should pretty | |
| 11 | much be able to understand Zig source code without learning anything about | |
| 12 | Zig. | |
| 13 | * Interoperability with C is crucial. Using C libraries should not require | |
| 14 | "Zig bindings". | |
| 15 | ||
| 7 | 16 | ## Goals |
| 8 | 17 | |
| 9 | 18 | * Ability to run arbitrary code at compile time and generate code. |
src/grammar.txt+8-8| ... | ... | @@ -2,12 +2,10 @@ Root<node> : many(FnDecl) token(EOF) { |
| 2 | 2 | $$ = ast_create_root($1); |
| 3 | 3 | }; |
| 4 | 4 | |
| 5 | FnDecl<node> : token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) option(ReturnType) Block { | |
| 6 | $$ = ast_create_fn_decl($2, $4, $6, $7); | |
| 7 | }; | |
| 8 | ||
| 9 | ReturnType<node> : token(Arrow) Type { | |
| 10 | $$ = $2; | |
| 5 | FnDecl<node> : token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) token(Arrow) Type Block { | |
| 6 | $$ = ast_create_fn_decl($2, $4, $7, $8); | |
| 7 | } | token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) Block { | |
| 8 | $$ = ast_create_void_fn_decl($2, $4, $6); | |
| 11 | 9 | }; |
| 12 | 10 | |
| 13 | 11 | ParamDecl<node> : token(Symbol) token(Colon) Type { |
| ... | ... | @@ -26,8 +24,10 @@ PointerType<node> : token(Star) token(Const) Type { |
| 26 | 24 | $$ = ast_create_pointer_type($2, $3); |
| 27 | 25 | }; |
| 28 | 26 | |
| 29 | Block<node> : token(LBrace) many(Statement) option(Expression) token(RBrace) { | |
| 30 | $$ = ast_create_block($2, $3); | |
| 27 | Block<node> : token(LBrace) many(Statement) Expression token(RBrace) { | |
| 28 | $$ = ast_create_expr_block($2, $3); | |
| 29 | } | token(LBrace) many(Statement) token(RBrace) { | |
| 30 | $$ = ast_create_block($2); | |
| 31 | 31 | }; |
| 32 | 32 | |
| 33 | 33 | Statement<node> : ExpressionStatement { |
src/parsergen.cpp-9| ... | ... | @@ -141,10 +141,6 @@ struct RuleMany { |
| 141 | 141 | RuleNode *child; |
| 142 | 142 | }; |
| 143 | 143 | |
| 144 | struct RuleOption { | |
| 145 | RuleNode *child; | |
| 146 | }; | |
| 147 | ||
| 148 | 144 | struct RuleOr { |
| 149 | 145 | Buf name; |
| 150 | 146 | Buf union_field_name; |
| ... | ... | @@ -171,7 +167,6 @@ enum RuleNodeType { |
| 171 | 167 | RuleNodeTypeTuple, |
| 172 | 168 | RuleNodeTypeMany, |
| 173 | 169 | RuleNodeTypeList, |
| 174 | RuleNodeTypeOption, | |
| 175 | 170 | RuleNodeTypeOr, |
| 176 | 171 | RuleNodeTypeToken, |
| 177 | 172 | RuleNodeTypeSubRule, |
| ... | ... | @@ -185,7 +180,6 @@ struct RuleNode { |
| 185 | 180 | RuleTuple tuple; |
| 186 | 181 | RuleMany many; |
| 187 | 182 | RuleList list; |
| 188 | RuleOption option; | |
| 189 | 183 | RuleOr _or; |
| 190 | 184 | RuleToken token; |
| 191 | 185 | RuleSubRule sub_rule; |
| ... | ... | @@ -403,9 +397,6 @@ static void gen(Gen *g, RuleNode *node, Buf *out_field_name, ParserState *cur_st |
| 403 | 397 | case RuleNodeTypeList: |
| 404 | 398 | zig_panic("TODO"); |
| 405 | 399 | break; |
| 406 | case RuleNodeTypeOption: | |
| 407 | zig_panic("TODO"); | |
| 408 | break; | |
| 409 | 400 | case RuleNodeTypeOr: |
| 410 | 401 | { |
| 411 | 402 | buf_init_from_buf(out_field_name, &node->_or.union_field_name); |