Skip to content

Commit

Permalink
feat(compiler,type_checker,ast,parser): struct literals and allow omi…
Browse files Browse the repository at this point in the history
…tting data type for let
  • Loading branch information
JaDogg committed Jun 25, 2023
1 parent 91b0394 commit 7509dbf
Show file tree
Hide file tree
Showing 41 changed files with 2,265 additions and 1,369 deletions.
15 changes: 14 additions & 1 deletion compiler/scripts/update_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# expression type name is followed by content of the class
EXPRS = sorted([
# Assign to a variable
("assign", (("token*", "name"), ("token*", "opr"), ("expr*", "right"))),
# We can promote an assignment to a let statement, if so promoted is set to true
("assign", (("token*", "name"), ("token*", "opr"), ("expr*", "right"), ("bool", "promoted"))),
# Assign to a member
("assign_member", (("expr*", "set_oper"), ("token*", "opr"), ("expr*", "right"))),
# Assign to array object
Expand All @@ -34,6 +35,10 @@
# Can be abc(), abc(1), abc(1, 2, 3), etc
# name->`abc` args->`1, 2, 3` paren_token->`)`
("fncall", (("expr*", "name"), ("token*", "paren_token"), ("std::vector<expr*>", "args"))),
# Struct literal
("struct_literal", (("token*", "colon"),
("ykdatatype*", "data_type"), ("token*", "curly_open"), ("std::vector<name_val>", "values"),
("token*", "curly_close"))),
# Can be a[1], a[b[1]], etc
("square_bracket_access", (("expr*", "name"), ("token*", "sqb_token"), ("expr*", "index_expr"))),
("square_bracket_set", (("expr*", "name"), ("token*", "sqb_token"), ("expr*", "index_expr"))),
Expand Down Expand Up @@ -190,6 +195,7 @@
struct expr;
struct stmt;
struct parameter;
struct name_val;
$FORWARD_DECLS$
// Types of expressions and statements
$AST_TYPES$
Expand Down Expand Up @@ -222,6 +228,13 @@
token* name_;
ykdatatype* data_type_;
};
/**
* Name + value item
*/
struct name_val {
token* name_;
expr* value_;
};
} // namespace yaksha
#endif
""".strip()
Expand Down
Loading

0 comments on commit 7509dbf

Please sign in to comment.