Skip to content

Commit

Permalink
support for parsing of statements. Calculation of stack size, or scop…
Browse files Browse the repository at this point in the history
…e structure is not yet implemented.
  • Loading branch information
august95 committed Sep 12, 2024
1 parent d0b7b2b commit 877ca84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 17 additions & 13 deletions compiler_lib/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ std::shared_ptr < node > parser::makeExpressionNode(filePosition file_position,
return expression_node;
}

/*

template <class nodeType>
std::shared_ptr<nodeType> parser::cast_node(std::shared_ptr<node> node_)
{
Expand All @@ -59,7 +59,7 @@ std::shared_ptr<nodeType> parser::cast_node(std::shared_ptr<node> node_)
std::shared_ptr<nodeType> cast_node_ = std::static_pointer_cast<nodeType>(node_);
return cast_node_;
}
*/


void parser::parseTokens()
{
Expand Down Expand Up @@ -278,7 +278,6 @@ void parser::parseBody()
cerror("expected symbol '}' at ending of body");
}


pushNode(body_node);
//end scopes

Expand All @@ -287,18 +286,23 @@ void parser::parseBody()

void parser::parseStatement()
{
nextToken();
//pop token

//parse keyword
//parse expression
//parse symbol ('{' new scope or ':' label)
//no other token types is expected as the first token in the statement
std::shared_ptr<token> token = peekToken();
if (token->isTokenTypeKeyword())
{
parseKeyword();
return;
}

// case token type number, token type identifier, if, else, switch, return, goto, for, while....
parseExpression();

//pop ';'
pushNode(std::make_shared<node>());
//parse symbol ('{' new scope or ':' label)
//no other token types is expected as the first token in the statement

token = nextToken();
if ((!token->isTokenTypeSymbol()) || token->getCharValue() != ';')
{
cerror("expected ';' at ending of statement");
}
}

void parser::parseSymbol()
Expand Down
2 changes: 1 addition & 1 deletion unit_test/test_files/test_parser_function.c
Original file line number Diff line number Diff line change
@@ -1 +1 @@
int main(){ int var_val;}
int main(){ int var_val; var_val + 50;}

0 comments on commit 877ca84

Please sign in to comment.