diff options
author | kugwa <kugwa2000@gmail.com> | 2015-11-12 17:20:57 +0800 |
---|---|---|
committer | kugwa <kugwa2000@gmail.com> | 2015-11-12 17:20:57 +0800 |
commit | 26e4dfdf77b9f739d5e5d7407e098a91d87a2939 (patch) | |
tree | f08cf6e50927764b3e6c89bc19b7f37c0b036afb | |
parent | 62d9753dac503b34bb27635faf96a395d465f54d (diff) | |
download | compiler2015-26e4dfdf77b9f739d5e5d7407e098a91d87a2939.tar.gz compiler2015-26e4dfdf77b9f739d5e5d7407e098a91d87a2939.tar.zst compiler2015-26e4dfdf77b9f739d5e5d7407e098a91d87a2939.zip |
Constant tokens fill yylval and return CONST
-rw-r--r-- | src/lexer.l | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/lexer.l b/src/lexer.l index b15668d..eca8cf3 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -79,10 +79,30 @@ ERROR . } return ID; } -{CONST_INT} return CONST; //TODO -{CONST_FLOAT} return CONST; -{CONST_STRING} return CONST; - +{CONST_INT} { + CON_Type *p; + p = (CON_Type *)malloc(sizeof(CON_Type)); + p->const_type = INTEGERC; + p->const_u.intval = atoi(yytext); + yylval.const1 = p; + return CONST; + } +{CONST_FLOAT} { + CON_Type *p; + p = (CON_Type *)malloc(sizeof(CON_Type)); + p->const_type = FLOATC; + p->const_u.fval = atof(yytext); + yylval.const1 = p; + return CONST; + } +{CONST_STRING} { + CON_Type *p; + p = (CON_Type *)malloc(sizeof(CON_Type)); + p->const_type = STRINGC; + p->const_u.sc = strdup(yytext); + yylval.const1 = p; + return CONST; + } {COMMENT} { int i; for (i = 0; yytext[i]; i++) @@ -122,7 +142,6 @@ ERROR . exit(1); } - %% // vim: set sw=4 ts=4 sts=4 et: |