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: ;