Advertisement
knkd

test.l

Jun 22nd, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.05 KB | None | 0 0
  1. %{
  2. #include <stdio.h>
  3. #include "y.tab.h"
  4.  
  5. #define BFSIZE 1024
  6. char string_buf[BFSIZE];
  7. char *string_buf_ptr;
  8.  
  9. /* FLOATVAL [+-]?(([0-9]*\.[0-9]+|[0-9]+\.[0-9]*)([Ee][+-]?[0-9]+)?|[0-9]+[Ee][+-]?[0-9]+) */
  10.  
  11. %}
  12.  
  13. dig                        [0-9]
  14. num1                       [-+]?{dig}+\.?([eE][-+]?{dig}+)?
  15. num2                       [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
  16. FLOATVAL                   {num1}|{num2}
  17. INTVAL                     {dig}+
  18. ID                         [\_a-zA-Z][\_a-zA-Z0-9]*
  19.  
  20. ESCSTR                     '(\\.|''|[^'\n])*' | \"(\\.|\"\"|[^"\n])*\"
  21.  
  22. %x str
  23.  
  24. %%
  25.  
  26. \{                          {return OBRACKET;}
  27. \}                          {return CBRACKET;}
  28.  
  29. [\=]                        {return ASSIGMENT;}
  30. [\;]                        {return EOL;}
  31. {ID}                        {
  32.                                yylval._string = malloc(strlen(yytext) + 1);
  33.                                strcpy(yylval._string, yytext);
  34.                                return IDENT;
  35.                            }
  36.  
  37. {INTVAL}                    {
  38.                                yylval._int = atoi(yytext);
  39.                                return INTEGER;
  40.                            }
  41.  
  42. {FLOATVAL}                  {
  43.                                yylval._double = atof(yytext);
  44.                                return FLOAT;
  45.                            }
  46.  
  47. \"                          {
  48.                                string_buf_ptr = string_buf;
  49.                                BEGIN(str);
  50.                            }
  51. <str>[^\"]                  {
  52.                                *string_buf_ptr++ = yytext[0];
  53.                            }
  54. <str>\"                     {
  55.                                BEGIN(INITIAL);
  56.                                *string_buf_ptr = '\0';
  57.                                yylval._string = malloc(strlen(string_buf) + 1);
  58.                                strcpy(yylval._string, string_buf);
  59.                                return STRING;
  60.                            }
  61.  
  62. [\s\t\n]                    {;}
  63.  
  64. %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement