diff --git a/analyzers/test/test.l b/analyzers/test/test.l index 23a9b66..1411236 100644 --- a/analyzers/test/test.l +++ b/analyzers/test/test.l @@ -32,6 +32,8 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] "int32" { return INT32; } "int64" { return INT64; } +"package" { return PACKAGE; } +"import" { return IMPORT; } "var" { return VAR; } "func" { return FUNC; } "return" { return RETURN; } diff --git a/analyzers/test/test.y b/analyzers/test/test.y index e2f01ed..c5ab582 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -22,7 +22,7 @@ void free_node(char *str) { } %token SHORT_DECLARATION LBRACE RBRACE SEMICOLON ASSIGN LPAREN RPAREN COMMA -%token VAR FUNC RETURN STRING_LITERAL FLOAT_LITERAL NUMBER +%token VAR FUNC RETURN STRING_LITERAL FLOAT_LITERAL NUMBER PACKAGE IMPORT %token PLUS MINUS MULT DIV MOD %token STRING %token UINT UINT8 UINT16 UINT32 UINT64 @@ -37,6 +37,7 @@ void free_node(char *str) { %% program: + package_declaration import_declaration | program statement ; @@ -104,6 +105,27 @@ literal: | NUMBER { } ; +// Package & import blocks +package_declaration: + PACKAGE IDENTIFIER SEMICOLON + { printf("\033[1;34mPACKAGE IDENTIFIER: %s\n\033[0m", $2); } + ; + +import_declaration: + IMPORT { printf("\033[1;36mHELLO, IMPORT BLOCK\n\033[0m"); } import { printf("\033[1;36mBY, IMPORT BLOCK\n\n\033[0m"); } + | IMPORT { printf("\033[1;36mHELLO, IMPORT BLOCK\n\033[0m"); } LPAREN import_list RPAREN { printf("\033[1;36mBY, IMPORT BLOCK\n\n\033[0m"); } + ; + +import: + STRING_LITERAL { printf("\033[1;36mIMPORTED PACKAGE\n\033[0m"); } SEMICOLON + ; + +import_list: + import + | import_list import + ; +// + arg_declaration: IDENTIFIER type { printf("\033[1;35mARG: %s\n\033[0m", $1); } diff --git a/tests/test_math.txt b/tests/test.txt similarity index 80% rename from tests/test_math.txt rename to tests/test.txt index 68253f1..9566e6e 100644 --- a/tests/test_math.txt +++ b/tests/test.txt @@ -1,4 +1,9 @@ +package main; +import ( + "fmt"; + "log"; +) func test() { return "123";