hyc

Hydrogen Compiler written in C
git clone git://git.kocotian.pl/hyc.git
Log | Files | Refs | README | LICENSE

commit 92686b60c2f55e8bc6f927c182555a9444b034c6
parent ecd453745f15adc0f9716f47d1438dd944650a6d
Author: kocotian <kocotian@kocotian.pl>
Date:   Mon,  9 Aug 2021 14:52:04 +0000

Fixed globals

Diffstat:
Mast.c | 29++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/ast.c b/ast.c @@ -51,6 +51,7 @@ static ASTStatement tokenstoASTStatementVariableDeclaration(Tokenizer *t, int se static ASTStatement tokenstoASTStatement(Tokenizer *t); static ASTGlobal tokenstoASTGlobalFunction(Tokenizer *t); +static ASTGlobal tokenstoASTGlobal(Tokenizer *t); static Token * prevToken(Tokenizer *t) @@ -406,6 +407,26 @@ tokenstoASTGlobalFunction(Tokenizer *t) return global; } +static ASTGlobal +tokenstoASTGlobal(Tokenizer *t) +{ + ASTGlobal global; + Token *tok; + + tok = enextToken(t); + global.Any.any.inittoken = tok; + + if (0) { + } else if (tok->type == TokenIdentifier && !Strccmp(tok->str, "function")) { + prevToken(t); + global = tokenstoASTGlobalFunction(t); + } else { + error(tok, "unexpected token"); + } + + return global; +} + ASTModule tokenstoASTModule(Token *tdata, size_t tlen) { @@ -415,11 +436,9 @@ tokenstoASTModule(Token *tdata, size_t tlen) newVector(module); - while ((tok = nextTokenType(&t, TokenIdentifier)) != NULL) { - if (!Strccmp(tok->str, "function")) { - prevToken(&t); - pushVector(module, tokenstoASTGlobalFunction(&t)); - } + while ((tok = nextToken(&t)) != NULL) { + prevToken(&t); + pushVector(module, tokenstoASTGlobal(&t)); } return module;