Added requirement for having a module header at the beginning of each source file

Updated test cases accordingly
develop_before_lexer_parser_merge_parseName
Tristan B. V. Kildaire 2021-03-21 13:10:18 +02:00
parent 85ab9bde02
commit 8bde36d586
8 changed files with 31 additions and 0 deletions

View File

@ -672,6 +672,18 @@ public final class Parser
/* TODO: Do parsing here */
/* Expect `module` and module name and consume them (and `;`) */
expect(SymbolType.MODULE, getCurrentToken());
nextToken();
expect(SymbolType.IDENTIFIER, getCurrentToken());
nextToken();
expect(SymbolType.SEMICOLON, getCurrentToken());
nextToken();
/* TODO: do `hasTokens()` check */
/* TODO: We should add `hasTokens()` to the `nextToken()` */
/* TODO: And too the `getCurrentTokem()` and throw an error when we have ran out rather */
/* We can have an import or vardef or funcdef */
while (hasTokens())
{

View File

@ -23,6 +23,7 @@ public enum SymbolType
COMMA,
OCURLY,
CCURLY,
MODULE,
IF,
ELSE,
WHILE,
@ -229,6 +230,11 @@ public static SymbolType getSymbolType(Token tokenIn)
{
return SymbolType.DELETE;
}
/* module keyword */
else if(cmp(token, "module") == 0)
{
return SymbolType.MODULE;
}
/* Identifier check (TODO: Track vars) */
else if (isIdentifier(token))
{

View File

@ -1,3 +1,6 @@
module bababoioey;
int x;
ubyte y;

View File

@ -1,3 +1,5 @@
module bababoioey;
int x;
ubyte y;

View File

@ -1,3 +1,5 @@
module bababoioey;
int x;
ubyte y;

View File

@ -1,3 +1,5 @@
module bababoioey;
int x;
ubyte y;

View File

@ -1,3 +1,5 @@
module bababoioey;
int x;
ubyte y;

View File

@ -1,3 +1,5 @@
module bababoioey;
int x;
ubyte y;