%%
#include <ctype.h>
+#include <stdlib.h>
#define BUFSIZE 4096
yylex(void)
{
- int c, last;
- char temp[BUFSIZE];
- char* p=temp;
+ int i, c, last;
while ((c = getchar ()) == ' ' || c == '\t');
if (c == '"'){
last = '"';
+ i = 0;
+ if (!(yylval.str = malloc(BUFSIZE))){
+ puts("Low memory");
+ exit(0);
+ }
while ((c = getchar()) != '"' || last == '\\'){
- *p = c;
+ yylval.str[i] = c;
last = c;
- p++;
- if (p-temp >= BUFSIZE-1)
+ i++;
+ if (i >= BUFSIZE-1)
break;
}
- *p = '\0';
+ yylval.str[i] = '\0';
- strcpy(&yylval,temp);
return CONST;
}