package & import blocks
parent
84efc813ad
commit
79ca611557
|
@ -32,6 +32,8 @@ LETTER_OR_DIGIT [a-zA-Z0-9_]
|
||||||
"int32" { return INT32; }
|
"int32" { return INT32; }
|
||||||
"int64" { return INT64; }
|
"int64" { return INT64; }
|
||||||
|
|
||||||
|
"package" { return PACKAGE; }
|
||||||
|
"import" { return IMPORT; }
|
||||||
"var" { return VAR; }
|
"var" { return VAR; }
|
||||||
"func" { return FUNC; }
|
"func" { return FUNC; }
|
||||||
"return" { return RETURN; }
|
"return" { return RETURN; }
|
||||||
|
|
|
@ -22,7 +22,7 @@ void free_node(char *str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
%token SHORT_DECLARATION LBRACE RBRACE SEMICOLON ASSIGN LPAREN RPAREN COMMA
|
%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 PLUS MINUS MULT DIV MOD
|
||||||
%token STRING
|
%token STRING
|
||||||
%token UINT UINT8 UINT16 UINT32 UINT64
|
%token UINT UINT8 UINT16 UINT32 UINT64
|
||||||
|
@ -37,6 +37,7 @@ void free_node(char *str) {
|
||||||
%%
|
%%
|
||||||
|
|
||||||
program:
|
program:
|
||||||
|
package_declaration import_declaration
|
||||||
| program statement
|
| program statement
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -104,6 +105,27 @@ literal:
|
||||||
| NUMBER { }
|
| 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:
|
arg_declaration:
|
||||||
IDENTIFIER type
|
IDENTIFIER type
|
||||||
{ printf("\033[1;35mARG: %s\n\033[0m", $1); }
|
{ printf("\033[1;35mARG: %s\n\033[0m", $1); }
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
|
package main;
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt";
|
||||||
|
"log";
|
||||||
|
)
|
||||||
|
|
||||||
func test() {
|
func test() {
|
||||||
return "123";
|
return "123";
|
Loading…
Reference in New Issue