Merge pull request #24 from Servostar/21-add-debug-print-into-tokenizer

21 add debug print into tokenizer
This commit is contained in:
Filleo 2024-04-22 12:29:43 +02:00 committed by GitHub
commit c38abad400
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 63 additions and 64 deletions

View File

@ -1,84 +1,83 @@
%option noyywrap
%{
#include <yacc/parser.tab.h>
#include <sys/log.h>
int yyLineNumber = 1;
int yylex();
%}
/* disable the following functions */
/* to avoid failing code check */
%option nounput
%option noinput
%%
"\n" yyLineNumber++;
":" return(':');
"=" return('=');
"+" return('+');
"-" return('-');
"*" return('*');
"/" return('/');
"," return(',');
";" return(';');
"." return('.');
"#" return('#');
":" {DEBUG("\"%s\" tokenized with \':\'", yytext); return(':');};
"=" {DEBUG("\"%s\" tokenized with \'=\'", yytext); return('=');};
"+" {DEBUG("\"%s\" tokenized with \'+\'", yytext); return('+');};
"-" {DEBUG("\"%s\" tokenized with \'-\'", yytext); return('-');};
"*" {DEBUG("\"%s\" tokenized with \'*\'", yytext); return('*');};
"/" {DEBUG("\"%s\" tokenized with \'/\'", yytext); return('/');};
"," {DEBUG("\"%s\" tokenized with \',\'", yytext); return(',');};
";" {DEBUG("\"%s\" tokenized with \';\'", yytext); return(';');};
"." {DEBUG("\"%s\" tokenized with \'.\'", yytext); return('.');};
"#" {DEBUG("\"%s\" tokenized with \'#\'", yytext); return('#');};
"(" return('(');
")" return(')');
"[" return('[');
"]" return(']');
"{" return('{');
"}" return('}');
">" return('>');
"<" return('<');
"(" {DEBUG("\"%s\" tokenized with \'(\'", yytext); return('(');};
")" {DEBUG("\"%s\" tokenized with \')\'", yytext); return(')');};
"[" {DEBUG("\"%s\" tokenized with \'[\'", yytext); return('[');};
"]" {DEBUG("\"%s\" tokenized with \']\'", yytext); return(']');};
"{" {DEBUG("\"%s\" tokenized with \'{\'", yytext); return('{');};
"}" {DEBUG("\"%s\" tokenized with \'}\'", yytext); return('}');};
">" {DEBUG("\"%s\" tokenized with \'>\'", yytext); return('>');};
"<" {DEBUG("\"%s\" tokenized with \'<\'", yytext); 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(OpEquals);
"&&" return(OpAnd);
"||" return(OpOr);
"!!" return(OpNot);
"^^" return(OpXor);
"&" return(OpBitand);
"|" return(OpBitor);
"!" return(OpBitnot);
"^" return(OpBitxor);
"import" return(KeyImport);
"silent" return(KeySilent);
"box" return(KeyBox);
"typeof" return(FunTypeof);
"sizeof" return(FunSizeof);
"filename" return(FunFilename);
"funname" return(FunFunname);
"lineno" return(FunLineno);
"extsupport" return(FunExtsupport);
"int" {DEBUG("\"%s\" tokenized with \'<KeyInt'", yytext); return(KeyInt);};
"float" {DEBUG("\"%s\" tokenized with \'KeyFloat\'", yytext); return(KeyFloat);};
"as" {DEBUG("\"%s\" tokenized with \'<KeyAs'", yytext); return (KeyAs);};
"short" {DEBUG("\"%s\" tokenized with \'KeyShort\'", yytext); return(KeyShort);};
"long" {DEBUG("\"%s\" tokenized with \'KeyLong\'", yytext); return(KeyLong);};
"half" {DEBUG("\"%s\" tokenized with \'KeyHalf\'", yytext); return(KeyHalf);};
"double" {DEBUG("\"%s\" tokenized with \'KeyDouble\'", yytext); return(KeyDouble);};
"signed" {DEBUG("\"%s\" tokenized with \'KeySigned\'", yytext); return(KeySigned);};
"unsigned" {DEBUG("\"%s\" tokenized with \'KeyUnsigned\'", yytext); return(KeyUnsigned);};
"ref" {DEBUG("\"%s\" tokenized with \'KeyRef\'", yytext); return(KeyRef);};
"type" {DEBUG("\"%s\" tokenized with \'KeyType\'", yytext); return(KeyType);};
"local" {DEBUG("\"%s\" tokenized with \'KeyLocal\'", yytext); return(KeyLocal);};
"global" {DEBUG("\"%s\" tokenized with \'KeyGlobal\'", yytext); return(KeyGlobal);};
"static" {DEBUG("\"%s\" tokenized with \'KeyStatic\'", yytext); return(KeyStatic);};
"if" {DEBUG("\"%s\" tokenized with \'KeyIf\'", yytext); return(KeyIf);};
"else" {DEBUG("\"%s\" tokenized with \'KeyElse\'", yytext); return(KeyElse);};
"while" {DEBUG("\"%s\" tokenized with \'KeyWhile\'", yytext); return(KeyWhile);};
"in" {DEBUG("\"%s\" tokenized with \'KeyIn\'", yytext); return(KeyIn);};
"out" {DEBUG("\"%s\" tokenized with \'KeyOut\'", yytext); return(KeyOut);};
"fun" {DEBUG("\"%s\" tokenized with \'KeyFun\'", yytext); return(KeyFun);};
"==" {DEBUG("\"%s\" tokenized with \'OpEquals\'", yytext); return(OpEquals);};
"&&" {DEBUG("\"%s\" tokenized with \'OpAnd\'", yytext); return(OpAnd);};
"||" {DEBUG("\"%s\" tokenized with \'OpOr\'", yytext); return(OpOr);};
"!!" {DEBUG("\"%s\" tokenized with \'OpNot\'", yytext); return(OpNot);};
"^^" {DEBUG("\"%s\" tokenized with \'OpXor\'", yytext); return(OpXor);};
"&" {DEBUG("\"%s\" tokenized with \'OpBitand\'", yytext); return(OpBitand);};
"|" {DEBUG("\"%s\" tokenized with \'OpBitor\'", yytext); return(OpBitor);};
"!" {DEBUG("\"%s\" tokenized with \'OpBitnot\'", yytext); return(OpBitnot);};
"^" {DEBUG("\"%s\" tokenized with \'OpBitxor\'", yytext); return(OpBitxor);};
"import" {DEBUG("\"%s\" tokenized with \'KeyImport\'", yytext); return(KeyImport);};
"silent" {DEBUG("\"%s\" tokenized with \'KeySilent\'", yytext); return(KeySilent);};
"box" {DEBUG("\"%s\" tokenized with \'KeyBox\'", yytext); return(KeyBox);};
"typeof" {DEBUG("\"%s\" tokenized with \'FunTypeof\'", yytext); return(FunTypeof);};
"sizeof" {DEBUG("\"%s\" tokenized with \'FunSizeof\'", yytext); return(FunSizeof);};
"filename" {DEBUG("\"%s\" tokenized with \'FunFilename\'", yytext); return(FunFilename);};
"funname" {DEBUG("\"%s\" tokenized with \'FunFunname\'", yytext); return(FunFunname);};
"lineno" {DEBUG("\"%s\" tokenized with \'FunLineno\'", yytext); return(FunLineno);};
"extsupport" {DEBUG("\"%s\" tokenized with \'FunExtsupport\'", yytext); return(FunExtsupport);};
[a-zA-Z_]+ { yylval.string = strdup(yytext); return(Ident); };
[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.string = strdup(yytext); return(ValFloat);};
[0-9]+ {DEBUG("\"%s\" tokenized with \'ValInt\'", yytext); yylval.string = strdup(yytext); return(ValInt); };
[0-9]*\.[0-9]+ {DEBUG("\"%s\" tokenized with \'ValFloat\'", yytext); yylval.string = strdup(yytext); return(ValFloat);};
[a-zA-Z_0-9]+ {DEBUG("\"%s\" tokenized with \'Ident\'", yytext); yylval.string = strdup(yytext); return(Ident); };
\"([^\"\n])*\" {DEBUG("\"%s\" tokenized with \'ValStr\'", yytext); yylval.string = strdup(yytext); return(ValStr);};
\"\"\"([^\"\n]|\\\n)*\"\"\" {DEBUG("\"%s\" tokenized with \'ValMultistr\'", yytext); yylval.string = strdup(yytext); return(ValMultistr);};
.;
%%

View File

@ -24,7 +24,7 @@
%token KeyHalf
%token KeyDouble
%token KeySigned
%token Keyunsigned
%token KeyUnsigned
%token KeyRef
%token KeyType
%token KeyLocal