From f11c4b63ff74bffb1d42d95167b3384a2f7765ea Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 24 Feb 2019 15:48:42 +0100 Subject: Add grammar above parser functions --- src/parser.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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(); -- cgit v1.2.3