aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/hello.halk28
-rw-r--r--src/include/parser.h10
-rw-r--r--src/include/tree.h29
3 files changed, 29 insertions, 38 deletions
diff --git a/examples/hello.halk b/examples/hello.halk
index 6e5f7bf..d046d19 100644
--- a/examples/hello.halk
+++ b/examples/hello.halk
@@ -9,28 +9,10 @@
argument 'target', also of type 'str' `
` some more functions `
-:void:add1. :int:n = n = +. n, 1;
-:int:fac.:int:n=if.(==.n,0),1,*.n,fac.-.n,1;
+:void:add1.:int:n+=. n, 1;
+:int:fac.:int:n=?.(=.n,0),1,*.n,fac.-.n,1;
-:int:fib. :int:n = if. (<=. n, 1), ` multiple lines can be used for clarity `
- n,
- +. fib.(-. n, 1), fib. -. n, 2);
+:int:fib. :int:n = ?. (<=. n, 1), ` multiple lines can be used for clarity `
+ n,
+ +. fib.(-. n, 1), fib. -. n, 2);
-
-:void:print_greet.:str:target = stdio/pln.greet.target; ` namespaces `
-
-:namespace:people = { ` create namespace `
- struct.person, :int:age, :str:name; ` create a struct -- syntax not finalized `
-
- :str:person_report. :struct:person = {
- :str:age = int->str.person.age;
- :str:name = person.name;
-
- strcat. "NAME:\t", name, "\nAGE:\t", age;
- }
-
- :void:person_birthday. :struct:person = {
- stdio/pln. "Happy birthday, ", person.name;
- person.age = +.person.age, 1;
- }
-}
diff --git a/src/include/parser.h b/src/include/parser.h
index deb6c7c..7541303 100644
--- a/src/include/parser.h
+++ b/src/include/parser.h
@@ -9,13 +9,19 @@
typedef struct PARSER_STRUC {
lexer_t* lexer; // lexer used by the parser
token_t* token; // current token
+
+ enum {
+ DEF,
+ CAL
+ } state;
+
} parser_t;
parser_t* parser_init(lexer_t* lexer);
void parser_destroy(parser_t* parser);
-// expect token(s), or die
-void parser_token_expect(parser_t* parser, int token, ...);
+// expect tokens, or die
+void parser_token_expect(parser_t* parser, int token_type, ...);
// do the parse
tree_t* parser_parse(parser_t* parser);
diff --git a/src/include/tree.h b/src/include/tree.h
index 88287a4..a240a18 100644
--- a/src/include/tree.h
+++ b/src/include/tree.h
@@ -3,27 +3,30 @@
#include <stdlib.h>
-typedef struct TREE_STRUC {
+typedef enum {
+ LEAF_TYPE_INT,
+ LEAF_TYPE_STR,
+} leaf_t;
+
+typedef struct ARG_T_STRUCT {
+ leaf_t type;
+ char* id;
+ struct ARG_T_STRUCT* nxt;
+} arg_t;
+
+typedef struct TREE_T_STRUCT {
enum TREE_TYPE {
- TREE_TYPE_INT,
- TREE_TYPE_STR,
TREE_TYPE_DEF,
TREE_TYPE_CAL,
- TREE_TYPE_COND,
} type;
union {
struct {
- int val;
- } tree_int_t;
-
- struct {
- char* val;
- } tree_str_t;
-
- struct {
+ leaf_t type;
char* id;
- } tree_def_t;
+ arg_t* arg;
+ struct TREE_T_STRUCT* val;
+ } tree_def;
} data;
} tree_t;