added signs to integer

removed linebrakes
added floats as "real"
changed Keyword for single symbol Operators
This commit is contained in:
Felix Müller 2024-04-16 19:54:09 +02:00
parent 0740dcc237
commit 74befb4edd
2 changed files with 18 additions and 37 deletions

View File

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

View File

@ -9,34 +9,31 @@
%union {
char *string;
int num;
float real;
}
%token KeyInt
%token KeyFloat
%token KeyAs
%token <num> ValInt
%token <string> Ident
%token <real> ValFloat
%token <string> ValStr
%token <string> 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: ;