Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include <stdio.h>
- #include "y.tab.h"
- #define BFSIZE 1024
- char string_buf[BFSIZE];
- char *string_buf_ptr;
- /* FLOATVAL [+-]?(([0-9]*\.[0-9]+|[0-9]+\.[0-9]*)([Ee][+-]?[0-9]+)?|[0-9]+[Ee][+-]?[0-9]+) */
- %}
- dig [0-9]
- num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)?
- num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
- FLOATVAL {num1}|{num2}
- INTVAL {dig}+
- ID [\_a-zA-Z][\_a-zA-Z0-9]*
- ESCSTR '(\\.|''|[^'\n])*' | \"(\\.|\"\"|[^"\n])*\"
- %x str
- %%
- \{ {return OBRACKET;}
- \} {return CBRACKET;}
- [\=] {return ASSIGMENT;}
- [\;] {return EOL;}
- {ID} {
- yylval._string = malloc(strlen(yytext) + 1);
- strcpy(yylval._string, yytext);
- return IDENT;
- }
- {INTVAL} {
- yylval._int = atoi(yytext);
- return INTEGER;
- }
- {FLOATVAL} {
- yylval._double = atof(yytext);
- return FLOAT;
- }
- \" {
- string_buf_ptr = string_buf;
- BEGIN(str);
- }
- <str>[^\"] {
- *string_buf_ptr++ = yytext[0];
- }
- <str>\" {
- BEGIN(INITIAL);
- *string_buf_ptr = '\0';
- yylval._string = malloc(strlen(string_buf) + 1);
- strcpy(yylval._string, string_buf);
- return STRING;
- }
- [\s\t\n] {;}
- %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement