aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorc+12023-05-15 17:50:11 -0400
committerc+12023-05-15 17:50:11 -0400
commit6ada416e01aa358527b243236eae560399b7d84b (patch)
tree7f2f4fd814f24ef10aa46dacbc41baf77987b950 /src
parentb2aa09bf1958952836e4c2664af122458d246a8b (diff)
augh
Diffstat (limited to 'src')
-rw-r--r--src/main.c3
-rw-r--r--src/parser.c27
2 files changed, 25 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 33be891..5d5b69c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -12,7 +12,7 @@ int main(int argc, char* argv[]) {
long fsource_size;
char *source;
- fsource = fopen ("examples/hello.halk", "rb");
+ fsource = fopen ("examples/simple.halk", "rb");
if (!fsource) {
log_err("Source file not found");
exit(1);
@@ -49,6 +49,7 @@ int main(int argc, char* argv[]) {
log_inf("Tree root created");
printf("TYPE: [%d]\n", tree->type);
+ printf("SIZE: [%d]\n", tree->data.subtree.size);
fclose(fsource);
diff --git a/src/parser.c b/src/parser.c
index 01b252c..0e6a015 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -34,7 +34,7 @@ tree_t* parser_parse(parser_t* parser) {
}
tree_t* parser_parse_token_id(parser_t* parser) {
- if (strcmp(parser->token->value, "var")) {
+ if (strcmp(parser->token->value, "let")) {
return parser_parse_var(parser);
} else { // if id not recognized, check for variables under that name
return parser_parse_var_def(parser);
@@ -49,7 +49,7 @@ tree_t* parser_parse_chunk(parser_t* parser) {
break;
}
default: {
- log_dbg("Skiping non-keyword token");
+ log_dbg("Skipping non-keyword token");
lexer_next(parser->lexer);
break;
}
@@ -80,7 +80,18 @@ tree_t* parser_parse_chunks(parser_t* parser) {
return subtree;
}
-tree_t* parser_parse_expr(parser_t* parser) {};
+tree_t* parser_parse_expr(parser_t* parser) {
+ switch (parser->token->type) {
+ case TOKEN_STR:
+ parser_parse_str(parser);
+ break;
+
+ default:
+ log_war("Skipping unknown token");
+ lexer_next(parser->lexer);
+
+ }
+};
tree_t* parser_parse_fac(parser_t* parser) {};
@@ -129,7 +140,15 @@ tree_t* parser_parse_var_def(parser_t* parser) {
return var_def;
};
-tree_t* parser_parse_str(parser_t* parser) {};
+tree_t* parser_parse_str(parser_t* parser) {
+ log_dbg("Entered str");
+ tree_t* str = tree_init(TREE_STR);
+ str->data.str.val = parser->token->value;
+
+ parser_check_expect(parser, TOKEN_STR);
+
+ return str;
+};
tree_t* parser_parse_keyword(parser_t* parser) {
if (strcmp(parser->token->value, "let")) {