Commit 5b663ddbb2
Changed files (3)
src/grammar.txt
@@ -2,12 +2,10 @@ Root<node> : many(FnDecl) token(EOF) {
$$ = ast_create_root($1);
};
-FnDecl<node> : token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) option(ReturnType) Block {
- $$ = ast_create_fn_decl($2, $4, $6, $7);
-};
-
-ReturnType<node> : token(Arrow) Type {
- $$ = $2;
+FnDecl<node> : token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) token(Arrow) Type Block {
+ $$ = ast_create_fn_decl($2, $4, $7, $8);
+} | token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) Block {
+ $$ = ast_create_void_fn_decl($2, $4, $6);
};
ParamDecl<node> : token(Symbol) token(Colon) Type {
@@ -26,8 +24,10 @@ PointerType<node> : token(Star) token(Const) Type {
$$ = ast_create_pointer_type($2, $3);
};
-Block<node> : token(LBrace) many(Statement) option(Expression) token(RBrace) {
- $$ = ast_create_block($2, $3);
+Block<node> : token(LBrace) many(Statement) Expression token(RBrace) {
+ $$ = ast_create_expr_block($2, $3);
+} | token(LBrace) many(Statement) token(RBrace) {
+ $$ = ast_create_block($2);
};
Statement<node> : ExpressionStatement {
src/parsergen.cpp
@@ -141,10 +141,6 @@ struct RuleMany {
RuleNode *child;
};
-struct RuleOption {
- RuleNode *child;
-};
-
struct RuleOr {
Buf name;
Buf union_field_name;
@@ -171,7 +167,6 @@ enum RuleNodeType {
RuleNodeTypeTuple,
RuleNodeTypeMany,
RuleNodeTypeList,
- RuleNodeTypeOption,
RuleNodeTypeOr,
RuleNodeTypeToken,
RuleNodeTypeSubRule,
@@ -185,7 +180,6 @@ struct RuleNode {
RuleTuple tuple;
RuleMany many;
RuleList list;
- RuleOption option;
RuleOr _or;
RuleToken token;
RuleSubRule sub_rule;
@@ -403,9 +397,6 @@ static void gen(Gen *g, RuleNode *node, Buf *out_field_name, ParserState *cur_st
case RuleNodeTypeList:
zig_panic("TODO");
break;
- case RuleNodeTypeOption:
- zig_panic("TODO");
- break;
case RuleNodeTypeOr:
{
buf_init_from_buf(out_field_name, &node->_or.union_field_name);
README.md
@@ -4,6 +4,15 @@ An experiment in writing a low-level programming language with the intent to
replace C. Zig intends to be a small language, yet powerful enough to write
readable, safe, optimal, and concise code to solve any computing problem.
+## Design Principles
+
+ * Never compromise power or performance.
+ * Keep the language small and easy to understand. C programmers should pretty
+ much be able to understand Zig source code without learning anything about
+ Zig.
+ * Interoperability with C is crucial. Using C libraries should not require
+ "Zig bindings".
+
## Goals
* Ability to run arbitrary code at compile time and generate code.