authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-11-23 19:19:38-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-11-23 19:19:38-07:00
log5b663ddbb2152b77ba71b18c7be2b6e379ae632a
treedaa8695f1962c718e5fa8d26208ef35e04b0561d
parent4236b85c722b36cb31595634bae0ff28d6082761

grammar doesn't need the option() construct


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
44replace C. Zig intends to be a small language, yet powerful enough to write
55readable, safe, optimal, and concise code to solve any computing problem.
66
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
716## Goals
817
918 * 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) {
22 $$ = ast_create_root($1);
33};
44
5FnDecl<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
9ReturnType<node> : token(Arrow) Type {
10 $$ = $2;
5FnDecl<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);
119};
1210
1311ParamDecl<node> : token(Symbol) token(Colon) Type {
......@@ -26,8 +24,10 @@ PointerType<node> : token(Star) token(Const) Type {
2624 $$ = ast_create_pointer_type($2, $3);
2725};
2826
29Block<node> : token(LBrace) many(Statement) option(Expression) token(RBrace) {
30 $$ = ast_create_block($2, $3);
27Block<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);
3131};
3232
3333Statement<node> : ExpressionStatement {
src/parsergen.cpp-9
......@@ -141,10 +141,6 @@ struct RuleMany {
141141 RuleNode *child;
142142};
143143
144struct RuleOption {
145 RuleNode *child;
146};
147
148144struct RuleOr {
149145 Buf name;
150146 Buf union_field_name;
......@@ -171,7 +167,6 @@ enum RuleNodeType {
171167 RuleNodeTypeTuple,
172168 RuleNodeTypeMany,
173169 RuleNodeTypeList,
174 RuleNodeTypeOption,
175170 RuleNodeTypeOr,
176171 RuleNodeTypeToken,
177172 RuleNodeTypeSubRule,
......@@ -185,7 +180,6 @@ struct RuleNode {
185180 RuleTuple tuple;
186181 RuleMany many;
187182 RuleList list;
188 RuleOption option;
189183 RuleOr _or;
190184 RuleToken token;
191185 RuleSubRule sub_rule;
......@@ -403,9 +397,6 @@ static void gen(Gen *g, RuleNode *node, Buf *out_field_name, ParserState *cur_st
403397 case RuleNodeTypeList:
404398 zig_panic("TODO");
405399 break;
406 case RuleNodeTypeOption:
407 zig_panic("TODO");
408 break;
409400 case RuleNodeTypeOr:
410401 {
411402 buf_init_from_buf(out_field_name, &node->_or.union_field_name);