From 46de25f8cefb7521144ece10c875c24c616e7dcb Mon Sep 17 00:00:00 2001 From: Filleo Date: Mon, 15 Apr 2024 20:36:13 +0200 Subject: [PATCH 1/7] first batch of keywords and symbols --- src/lex/lexer.l | 59 ++++++++++++++++++++++++++++++- src/main.c | 7 ++++ src/yacc/parser.y | 88 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 152 insertions(+), 2 deletions(-) diff --git a/src/lex/lexer.l b/src/lex/lexer.l index a17888b..c09798d 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -6,6 +6,63 @@ int yylex(); %} +/*543fgrsdffsd*/ + %% +"\n" yyLineNumber++; + + +":" return(':'); +"=" return('='); +"|" return('|'); +"!" return('!'); +"+" return('+'); +"-" return('-'); +"*" return('*'); +"/" return('/'); + + +"(" return('('); +")" return(')'); +"[" return('['); +"]" return(']'); +"{" return('{'); +"}" return('}'); +">" return('>'); +"<" return('<'); + + +"int" return(KeyInt); +"float" return(KeyFloat); + +"as" return (KeyAs); + + +"short" return(KeyShort); +"long" return(KeyLong); +"half" return(KeyHalf); +"double" return(KeyDouble); +"signed" return(KeySigned); +"unsigned" return(Keyunsigned); + +"ref" return(KeyRef); +"type" return(KeyType); +"local" return(KeyLocal); +"global" return(KeyGlobal); +"static" return(KeyStatic); + +"if" return(KeyIf); +"else" return(KeyElse); + +"while" return(KeyWhile); + + + + + + + +[a-zA-Z_]+ { yylval.string = strdup(yytext); return(Ident); }; +[0-9]+ { yylval.num = atoi(yytext); return(ValInt); }; .; -%% \ No newline at end of file +%% diff --git a/src/main.c b/src/main.c index 6b48e00..27df7ed 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,13 @@ #include +#include + +extern FILE* yyin; int main() { + FILE* input = fopen("program.gem", "r"); + + yyin = input; + yyparse(); return 0; } \ No newline at end of file diff --git a/src/yacc/parser.y b/src/yacc/parser.y index fbe3d5a..4552fbd 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -1,15 +1,101 @@ %{ + #include extern int yylineno; int yyerror(char*); extern int yylex(); + + int array[256]; %} +%union { + char *string; + int num; +} + + +%token KeyInt +%token KeyFloat + +%token KeyAs +%token ValInt +%token Ident + +%token KeyShort +%token KeyLong +%token KeyHalf +%token KeyDouble +%token KeySigned +%token Keyunsigned + +%token KeyRef +%token KeyType +%token KeyLocal +%token KeyGlobal +%token KeyStatic + +%token KeyIf +%token KeyElse + +%token KeyWhile + + + + %% -program: ; +program: decllist; + +decllist: decl + | decllist decl; + +decl: '=' {printf("=\n"); }; + | ':' {printf(":\n"); }; + | '|' {printf("|\n"); }; + | '(' {printf("(\n"); }; + | ')' {printf(")\n"); }; + | '[' {printf("[\n"); }; + | ']' {printf("]\n"); }; + | '{' {printf("{\n"); }; + | '}' {printf("}\n"); }; + | '!' {printf("!\n"); }; + + | '+' {printf("+\n"); }; + | '-' {printf("-\n"); }; + | '*' {printf("*\n"); }; + | '/' {printf("/\n"); }; + + + + + | Ident {printf("Ident\n"); }; + | ValInt {printf("ValInt\n"); }; + | KeyInt {printf("KeyInt\n"); }; + | KeyFloat {printf("KeyFloat\n"); }; + | KeyAs {printf("KeyAs\n"); }; + + | KeyShort {printf("KeyShort\n"); }; + | KeyLong {printf("KeyLong\n"); }; + | KeyHalf {printf("KeyHalf\n"); }; + | KeyDouble {printf("KeyDouble\n"); }; + | KeySigned {printf("KeySigned\n"); }; + | Keyunsigned {printf("Keyunsigned\n"); }; + + | KeyRef {printf("KeyRef\n"); }; + | KeyType {printf("KeyType\n"); }; + | KeyLocal {printf("KeyLocal\n"); }; + | KeyGlobal {printf("KeyGlobal\n"); }; + | KeyStatic {printf("KeyStatic\n"); }; + + | KeyIf {printf("KeyIf\n"); }; + | KeyElse {printf("KeyElse\n"); }; + + | KeyWhile {printf("KeyWhile\n"); }; + %% + + int yyerror(char *s) { return 0; } \ No newline at end of file From 59da185baf0042a47632f6be055029b85c167d7c Mon Sep 17 00:00:00 2001 From: Filleo Date: Mon, 15 Apr 2024 21:12:17 +0200 Subject: [PATCH 2/7] all Keywords from primitives til modules --- src/lex/lexer.l | 15 +++++++++++++-- src/yacc/parser.y | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/lex/lexer.l b/src/lex/lexer.l index c09798d..f69347b 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -56,8 +56,19 @@ "while" return(KeyWhile); - - +"in" return(KeyIn); +"out" return(KeyOut); +"fun" return(KeyFun); +"," return(','); +";" return(';'); +"==" return(OpEquals); +"&&" return(OpAnd); +"||" return(OpOr); +"!!" return(OpNot); +"^^" return(OpXor); +"&" return('&'); +"^" return('^'); +"." return('.'); diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 4552fbd..ac5608e 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -40,6 +40,15 @@ %token KeyWhile +%token KeyIn +%token KeyOut +%token KeyFun +%token OpEquals +%token OpAnd +%token OpOr +%token OpNot +%token OpXor + @@ -65,6 +74,11 @@ decl: '=' {printf("=\n"); }; | '*' {printf("*\n"); }; | '/' {printf("/\n"); }; + | '&' {printf("&\n"); }; + | '^' {printf("^\n"); }; + | '.' {printf(".\n"); }; + | ',' {printf(",\n"); }; + | ';' {printf(";\n"); }; @@ -91,6 +105,18 @@ decl: '=' {printf("=\n"); }; | KeyElse {printf("KeyElse\n"); }; | KeyWhile {printf("KeyWhile\n"); }; + + | KeyIn {printf("KeyIn\n"); }; + | KeyOut {printf("KeyOut\n"); }; + | KeyFun {printf("KeyFun\n"); }; + | OpEquals {printf("OpEquals\n"); }; + | OpAnd {printf("OpAnd\n"); }; + | OpOr {printf("OpOr\n"); }; + | OpNot {printf("OpNot\n"); }; + | OpXor {printf("OpXor\n"); }; + + + %% From d9f959f40015565694bc7bbcbec76b2904d765d5 Mon Sep 17 00:00:00 2001 From: Filleo Date: Mon, 15 Apr 2024 22:02:53 +0200 Subject: [PATCH 3/7] completed all keywords and symbols in base language. created keywords for strings and multiline strings. --- program.gem | 75 +++++++++++++++++++++++++++++++++++++++++++++++ src/yacc/parser.y | 25 +++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 program.gem diff --git a/program.gem b/program.gem new file mode 100644 index 0000000..a05ba92 --- /dev/null +++ b/program.gem @@ -0,0 +1,75 @@ += +: +| +! + ++ +- +* +/ + + +( +) +[ +] +{ +} + +dsafsdgvvgxc +543564765 +int +float +as + +short +long +half +double +signed +unsigned + +ref +type +local +global +static + +if +else + +while + +in +out +fun + +, +; +== +&& +|| +!! +^^ +& +| +^ +! +. + +import +silent +box +# +typeof +sizeof +filename +funname +lineno +extsupport + +"fdsdfsdfsdfsdf" +"test" +"""gsdffgsdfgdf \ +dasad""" +"""""" diff --git a/src/yacc/parser.y b/src/yacc/parser.y index ac5608e..92a193e 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -50,6 +50,17 @@ %token OpXor +%token KeyImport +%token KeySilent +%token KeyBox +%token FunTypeof +%token FunSizeof +%token FunFilename +%token FunFunname +%token FunLineno +%token FunExtsupport +%token ValStr +%token ValMultistr %% @@ -79,6 +90,7 @@ decl: '=' {printf("=\n"); }; | '.' {printf(".\n"); }; | ',' {printf(",\n"); }; | ';' {printf(";\n"); }; + | '#' {printf("#\n"); }; @@ -115,9 +127,20 @@ decl: '=' {printf("=\n"); }; | OpNot {printf("OpNot\n"); }; | OpXor {printf("OpXor\n"); }; + | KeyImport {printf("KeyImport\n"); }; + | KeySilent {printf("KeySilent\n"); }; + | KeyBox {printf("KeyBox\n"); }; + | FunTypeof {printf("FunTypeof\n"); }; + | FunSizeof {printf("FunSizeof\n"); }; + | FunFilename {printf("FunFilename\n"); }; + | FunLineno {printf("FunLineno\n"); }; + | FunExtsupport {printf("FunExtsupport\n"); }; + | FunFunname {printf("FunFunname\n"); }; + + | ValStr {printf("ValStr\n"); }; + | ValMultistr {printf("ValMultistr\n"); }; - %% From 866d3d03c16c7edd1930945c95fa13688171a7e7 Mon Sep 17 00:00:00 2001 From: Filleo Date: Mon, 15 Apr 2024 22:04:21 +0200 Subject: [PATCH 4/7] forgor one file --- src/lex/lexer.l | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lex/lexer.l b/src/lex/lexer.l index f69347b..05ec44c 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -4,9 +4,10 @@ int yyLineNumber = 1; int yylex(); + + %} -/*543fgrsdffsd*/ %% "\n" yyLineNumber++; @@ -71,9 +72,22 @@ "." return('.'); +"import" return(KeyImport); +"silent" return(KeySilent); +"box" return(KeyBox); +"#" return('#'); +"typeof" return(FunTypeof); +"sizeof" return(FunSizeof); +"filename" return(FunFilename); +"funname" return(FunFunname); +"lineno" return(FunLineno); +"extsupport" return(FunExtsupport); + [a-zA-Z_]+ { yylval.string = strdup(yytext); return(Ident); }; [0-9]+ { yylval.num = atoi(yytext); return(ValInt); }; +\"([^\"\n])*\" {yylval.string = strdup(yytext); return(ValStr);}; +\"\"\"([^\"\n]|\\\n)*\"\"\" {yylval.string = strdup(yytext); return(ValMultistr);}; .; %% From 0740dcc237631f5bca8c03a1ac1ab6045906b830 Mon Sep 17 00:00:00 2001 From: Filleo Date: Mon, 15 Apr 2024 22:11:20 +0200 Subject: [PATCH 5/7] deleted test code and files --- program.gem | 75 ------------------------------------------ src/main.c | 7 ---- src/yacc/parser.y | 83 +---------------------------------------------- 3 files changed, 1 insertion(+), 164 deletions(-) delete mode 100644 program.gem diff --git a/program.gem b/program.gem deleted file mode 100644 index a05ba92..0000000 --- a/program.gem +++ /dev/null @@ -1,75 +0,0 @@ -= -: -| -! - -+ -- -* -/ - - -( -) -[ -] -{ -} - -dsafsdgvvgxc -543564765 -int -float -as - -short -long -half -double -signed -unsigned - -ref -type -local -global -static - -if -else - -while - -in -out -fun - -, -; -== -&& -|| -!! -^^ -& -| -^ -! -. - -import -silent -box -# -typeof -sizeof -filename -funname -lineno -extsupport - -"fdsdfsdfsdfsdf" -"test" -"""gsdffgsdfgdf \ -dasad""" -"""""" diff --git a/src/main.c b/src/main.c index 27df7ed..6b48e00 100644 --- a/src/main.c +++ b/src/main.c @@ -1,13 +1,6 @@ #include -#include - -extern FILE* yyin; int main() { - FILE* input = fopen("program.gem", "r"); - - yyin = input; - yyparse(); return 0; } \ No newline at end of file diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 92a193e..7decf27 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -1,12 +1,9 @@ %{ - #include extern int yylineno; int yyerror(char*); extern int yylex(); - - int array[256]; %} %union { @@ -64,87 +61,9 @@ %% -program: decllist; - -decllist: decl - | decllist decl; - -decl: '=' {printf("=\n"); }; - | ':' {printf(":\n"); }; - | '|' {printf("|\n"); }; - | '(' {printf("(\n"); }; - | ')' {printf(")\n"); }; - | '[' {printf("[\n"); }; - | ']' {printf("]\n"); }; - | '{' {printf("{\n"); }; - | '}' {printf("}\n"); }; - | '!' {printf("!\n"); }; - - | '+' {printf("+\n"); }; - | '-' {printf("-\n"); }; - | '*' {printf("*\n"); }; - | '/' {printf("/\n"); }; - - | '&' {printf("&\n"); }; - | '^' {printf("^\n"); }; - | '.' {printf(".\n"); }; - | ',' {printf(",\n"); }; - | ';' {printf(";\n"); }; - | '#' {printf("#\n"); }; - - - - | Ident {printf("Ident\n"); }; - | ValInt {printf("ValInt\n"); }; - | KeyInt {printf("KeyInt\n"); }; - | KeyFloat {printf("KeyFloat\n"); }; - | KeyAs {printf("KeyAs\n"); }; - - | KeyShort {printf("KeyShort\n"); }; - | KeyLong {printf("KeyLong\n"); }; - | KeyHalf {printf("KeyHalf\n"); }; - | KeyDouble {printf("KeyDouble\n"); }; - | KeySigned {printf("KeySigned\n"); }; - | Keyunsigned {printf("Keyunsigned\n"); }; - - | KeyRef {printf("KeyRef\n"); }; - | KeyType {printf("KeyType\n"); }; - | KeyLocal {printf("KeyLocal\n"); }; - | KeyGlobal {printf("KeyGlobal\n"); }; - | KeyStatic {printf("KeyStatic\n"); }; - - | KeyIf {printf("KeyIf\n"); }; - | KeyElse {printf("KeyElse\n"); }; - - | KeyWhile {printf("KeyWhile\n"); }; - - | KeyIn {printf("KeyIn\n"); }; - | KeyOut {printf("KeyOut\n"); }; - | KeyFun {printf("KeyFun\n"); }; - | OpEquals {printf("OpEquals\n"); }; - | OpAnd {printf("OpAnd\n"); }; - | OpOr {printf("OpOr\n"); }; - | OpNot {printf("OpNot\n"); }; - | OpXor {printf("OpXor\n"); }; - - | KeyImport {printf("KeyImport\n"); }; - | KeySilent {printf("KeySilent\n"); }; - | KeyBox {printf("KeyBox\n"); }; - | FunTypeof {printf("FunTypeof\n"); }; - | FunSizeof {printf("FunSizeof\n"); }; - | FunFilename {printf("FunFilename\n"); }; - | FunLineno {printf("FunLineno\n"); }; - | FunExtsupport {printf("FunExtsupport\n"); }; - | FunFunname {printf("FunFunname\n"); }; - - | ValStr {printf("ValStr\n"); }; - | ValMultistr {printf("ValMultistr\n"); }; - - +program: ; %% - - int yyerror(char *s) { return 0; } \ No newline at end of file From 74befb4eddf649bde1956b58d047528c1f7fc6d6 Mon Sep 17 00:00:00 2001 From: Filleo Date: Tue, 16 Apr 2024 19:54:09 +0200 Subject: [PATCH 6/7] added signs to integer removed linebrakes added floats as "real" changed Keyword for single symbol Operators --- src/lex/lexer.l | 35 ++++++++++------------------------- src/yacc/parser.y | 20 ++++++++------------ 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/lex/lexer.l b/src/lex/lexer.l index 05ec44c..a9279cb 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -4,24 +4,22 @@ int yyLineNumber = 1; int yylex(); - - %} %% "\n" yyLineNumber++; - ":" return(':'); "=" return('='); -"|" return('|'); -"!" return('!'); "+" return('+'); "-" return('-'); "*" return('*'); "/" return('/'); - +"," return(','); +";" return(';'); +"." return('.'); +"#" return('#'); "(" return('('); ")" return(')'); @@ -32,50 +30,38 @@ ">" return('>'); "<" return('<'); - "int" return(KeyInt); "float" return(KeyFloat); - "as" return (KeyAs); - - "short" return(KeyShort); "long" return(KeyLong); "half" return(KeyHalf); "double" return(KeyDouble); "signed" return(KeySigned); "unsigned" return(Keyunsigned); - "ref" return(KeyRef); "type" return(KeyType); "local" return(KeyLocal); "global" return(KeyGlobal); "static" return(KeyStatic); - "if" return(KeyIf); "else" return(KeyElse); - "while" return(KeyWhile); - "in" return(KeyIn); "out" return(KeyOut); "fun" return(KeyFun); -"," return(','); -";" return(';'); "==" return(OpEquals); "&&" return(OpAnd); "||" return(OpOr); "!!" return(OpNot); "^^" return(OpXor); -"&" return('&'); -"^" return('^'); -"." return('.'); - - +"&" return(OpBitand); +"|" return(OpBitor); +"!" return(OpBitnot); +"^" return(OpBitxor); "import" return(KeyImport); "silent" return(KeySilent); "box" return(KeyBox); -"#" return('#'); "typeof" return(FunTypeof); "sizeof" return(FunSizeof); "filename" return(FunFilename); @@ -83,11 +69,10 @@ "lineno" return(FunLineno); "extsupport" return(FunExtsupport); - - [a-zA-Z_]+ { yylval.string = strdup(yytext); return(Ident); }; -[0-9]+ { yylval.num = atoi(yytext); return(ValInt); }; +[-+]?[0-9]+ { yylval.num = atoi(yytext); return(ValInt); }; \"([^\"\n])*\" {yylval.string = strdup(yytext); return(ValStr);}; \"\"\"([^\"\n]|\\\n)*\"\"\" {yylval.string = strdup(yytext); return(ValMultistr);}; +[-+]?[0-9]*\.[0-9]+ {yylval.real = atof(yytext); return(ValFloat);}; .; %% diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 7decf27..cc795b6 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -9,34 +9,31 @@ %union { char *string; int num; + float real; } - %token KeyInt %token KeyFloat - %token KeyAs %token ValInt %token Ident - +%token ValFloat +%token ValStr +%token ValMultistr %token KeyShort %token KeyLong %token KeyHalf %token KeyDouble %token KeySigned %token Keyunsigned - %token KeyRef %token KeyType %token KeyLocal %token KeyGlobal %token KeyStatic - %token KeyIf %token KeyElse - %token KeyWhile - %token KeyIn %token KeyOut %token KeyFun @@ -45,8 +42,10 @@ %token OpOr %token OpNot %token OpXor - - +%token OpBitand +%token OpBitor +%token OpBitnot +%token OpBitxor %token KeyImport %token KeySilent %token KeyBox @@ -56,9 +55,6 @@ %token FunFunname %token FunLineno %token FunExtsupport -%token ValStr -%token ValMultistr - %% program: ; From e8bfc348bed33437513be85ecbf7fad465be4b2d Mon Sep 17 00:00:00 2001 From: Filleo Date: Wed, 17 Apr 2024 09:12:29 +0200 Subject: [PATCH 7/7] removed sign in number tokenizer pass floats and integer as strings --- src/lex/lexer.l | 4 ++-- src/yacc/parser.y | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lex/lexer.l b/src/lex/lexer.l index 921ae09..a932b11 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -76,9 +76,9 @@ "extsupport" return(FunExtsupport); [a-zA-Z_]+ { yylval.string = strdup(yytext); return(Ident); }; -[-+]?[0-9]+ { yylval.num = atoi(yytext); return(ValInt); }; +[0-9]+ { yylval.string = strdup(yytext); return(ValInt); }; \"([^\"\n])*\" {yylval.string = strdup(yytext); return(ValStr);}; \"\"\"([^\"\n]|\\\n)*\"\"\" {yylval.string = strdup(yytext); return(ValMultistr);}; -[-+]?[0-9]*\.[0-9]+ {yylval.real = atof(yytext); return(ValFloat);}; +[0-9]*\.[0-9]+ {yylval.string = strdup(yytext); return(ValFloat);}; .; %% diff --git a/src/yacc/parser.y b/src/yacc/parser.y index cc795b6..8aff8a0 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -8,16 +8,14 @@ %union { char *string; - int num; - float real; } %token KeyInt %token KeyFloat %token KeyAs -%token ValInt +%token ValInt %token Ident -%token ValFloat +%token ValFloat %token ValStr %token ValMultistr %token KeyShort