package & import blocks

ilya
serr 2025-05-13 18:41:51 +03:00
parent 84efc813ad
commit 79ca611557
3 changed files with 30 additions and 1 deletions

View File

@ -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; }

View File

@ -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); }

View File

@ -1,4 +1,9 @@
package main;
import (
"fmt";
"log";
)
func test() {
return "123";