aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-02-24 15:48:42 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commitf11c4b63ff74bffb1d42d95167b3384a2f7765ea (patch)
tree5ca7332f91a1297caa215b1dacaef09be53a05f3 /src
parent11dc4b81935e3dfee997c421d8d6fa166edd7a05 (diff)
Add grammar above parser functions
Diffstat (limited to 'src')
-rw-r--r--src/parser.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c
index ddf4a18..f68bbf0 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -19,6 +19,9 @@ void parser_deinit(Parser *self) {
buffer_deinit(&self->ast_objects);
}
+/*
+LHS = 'const'|'var' IDENTIFIER
+*/
static WARN_UNUSED_RESULT int parser_parse_lhs(Parser *self, LhsExpr **result) {
bool isConst;
BufferView var_name;
@@ -40,6 +43,9 @@ static WARN_UNUSED_RESULT int parser_parse_lhs(Parser *self, LhsExpr **result) {
return PARSER_OK;
}
+/*
+FUNC_DECL = '(' PARAM* ')' '{' BODY* '}'
+*/
static WARN_UNUSED_RESULT int parser_parse_function_decl(Parser *self, FunctionDecl **func_decl) {
bool result;
*func_decl = NULL;
@@ -76,6 +82,9 @@ static WARN_UNUSED_RESULT int parser_parse_function_decl(Parser *self, FunctionD
return PARSER_ERR;
}
+/*
+FUNC_CALL = IDENTIFIER '(' ARGS* ')'
+*/
static WARN_UNUSED_RESULT int parser_parse_function_call(Parser *self, FunctionCall **func_call) {
bool result;
BufferView func_name;
@@ -95,6 +104,9 @@ static WARN_UNUSED_RESULT int parser_parse_function_call(Parser *self, FunctionC
return PARSER_OK;
}
+/*
+RHS = FUNC_DECL | FUNC_CALL
+*/
static WARN_UNUSED_RESULT int parser_parse_rhs(Parser *self, Ast *rhs_expr) {
FunctionDecl *func_decl;
FunctionCall *func_call;
@@ -133,6 +145,10 @@ static WARN_UNUSED_RESULT int parser_parse_rhs(Parser *self, Ast *rhs_expr) {
return PARSER_ERR;
}
+/*
+BODY = (LHS '=' RHS) |
+ RHS
+*/
int parser_parse_body(Parser *self, Ast *ast) {
LhsExpr *lhs_expr;
Ast rhs_expr;
@@ -159,6 +175,9 @@ int parser_parse_body(Parser *self, Ast *ast) {
return PARSER_ERR;
}
+/*
+ROOT = BODY*
+*/
int parser_parse_buffer(Parser *self, BufferView code_buffer) {
Ast ast;
ast = ast_none();