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...@@ -4,6 +4,15 @@ An experiment in writing a low-level programming language with the intent to
4replace C. Zig intends to be a small language, yet powerful enough to write4replace C. Zig intends to be a small language, yet powerful enough to write
5readable, safe, optimal, and concise code to solve any computing problem.5readable, 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
7## Goals16## Goals
817
9 * Ability to run arbitrary code at compile time and generate code.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,12 +2,10 @@ Root<node> : many(FnDecl) token(EOF) {
2 $$ = ast_create_root($1);2 $$ = ast_create_root($1);
3};3};
44
5FnDecl<node> : token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) option(ReturnType) Block {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, $6, $7);6 $$ = ast_create_fn_decl($2, $4, $7, $8);
7};7} | token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) Block {
88 $$ = ast_create_void_fn_decl($2, $4, $6);
9ReturnType<node> : token(Arrow) Type {
10 $$ = $2;
11};9};
1210
13ParamDecl<node> : token(Symbol) token(Colon) Type {11ParamDecl<node> : token(Symbol) token(Colon) Type {
...@@ -26,8 +24,10 @@ PointerType<node> : token(Star) token(Const) Type {...@@ -26,8 +24,10 @@ PointerType<node> : token(Star) token(Const) Type {
26 $$ = ast_create_pointer_type($2, $3);24 $$ = ast_create_pointer_type($2, $3);
27};25};
2826
29Block<node> : token(LBrace) many(Statement) option(Expression) token(RBrace) {27Block<node> : token(LBrace) many(Statement) Expression token(RBrace) {
30 $$ = ast_create_block($2, $3);28 $$ = ast_create_expr_block($2, $3);
29} | token(LBrace) many(Statement) token(RBrace) {
30 $$ = ast_create_block($2);
31};31};
3232
33Statement<node> : ExpressionStatement {33Statement<node> : ExpressionStatement {
src/parsergen.cpp-9
...@@ -141,10 +141,6 @@ struct RuleMany {...@@ -141,10 +141,6 @@ struct RuleMany {
141 RuleNode *child;141 RuleNode *child;
142};142};
143143
144struct RuleOption {
145 RuleNode *child;
146};
147
148struct RuleOr {144struct RuleOr {
149 Buf name;145 Buf name;
150 Buf union_field_name;146 Buf union_field_name;
...@@ -171,7 +167,6 @@ enum RuleNodeType {...@@ -171,7 +167,6 @@ enum RuleNodeType {
171 RuleNodeTypeTuple,167 RuleNodeTypeTuple,
172 RuleNodeTypeMany,168 RuleNodeTypeMany,
173 RuleNodeTypeList,169 RuleNodeTypeList,
174 RuleNodeTypeOption,
175 RuleNodeTypeOr,170 RuleNodeTypeOr,
176 RuleNodeTypeToken,171 RuleNodeTypeToken,
177 RuleNodeTypeSubRule,172 RuleNodeTypeSubRule,
...@@ -185,7 +180,6 @@ struct RuleNode {...@@ -185,7 +180,6 @@ struct RuleNode {
185 RuleTuple tuple;180 RuleTuple tuple;
186 RuleMany many;181 RuleMany many;
187 RuleList list;182 RuleList list;
188 RuleOption option;
189 RuleOr _or;183 RuleOr _or;
190 RuleToken token;184 RuleToken token;
191 RuleSubRule sub_rule;185 RuleSubRule sub_rule;
...@@ -403,9 +397,6 @@ static void gen(Gen *g, RuleNode *node, Buf *out_field_name, ParserState *cur_st...@@ -403,9 +397,6 @@ static void gen(Gen *g, RuleNode *node, Buf *out_field_name, ParserState *cur_st
403 case RuleNodeTypeList:397 case RuleNodeTypeList:
404 zig_panic("TODO");398 zig_panic("TODO");
405 break;399 break;
406 case RuleNodeTypeOption:
407 zig_panic("TODO");
408 break;
409 case RuleNodeTypeOr:400 case RuleNodeTypeOr:
410 {401 {
411 buf_init_from_buf(out_field_name, &node->_or.union_field_name);402 buf_init_from_buf(out_field_name, &node->_or.union_field_name);