diff options
| author | Felix Perktold <Felix.Perktold@student.uibk.ac.at> | 2025-12-20 22:43:27 +0100 |
|---|---|---|
| committer | Felix Perktold <Felix.Perktold@student.uibk.ac.at> | 2025-12-20 22:43:27 +0100 |
| commit | dc0074b1accf92ce2e1fa126dccf702722f11611 (patch) | |
| tree | a667b62a283362d6ade7555eabbe47b19be5c5f3 /lisp.l | |
| parent | a75b2c6fe57edec9b1bf876a5e8ad98762c7d0ba (diff) | |
fix string lexing
Diffstat (limited to 'lisp.l')
| -rw-r--r-- | lisp.l | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -11,7 +11,21 @@ int tcnt = 0; yylval.dval = atof(yytext); printf("%d: NUMBER: %f\n", ++tcnt, yylval.dval); return NUMBER; - } + } + +\"(\\.|[^"\\])*\" { + // remove starting and ending quotes + int len = yyleng - 2; + char *str = (char*)malloc(len + 1); + if (!str) { fprintf(stderr, "Out of memory\n"); exit(1); } + strncpy(str, yytext + 1, len); + str[len] = '\0'; + + yylval.strval = str; + printf("%d: STRING: \"%s\"\n", ++tcnt, yylval.strval); + return STRING; + } + [ \t\n]+ { printf("%d: WHITESPACE\n", tcnt); return WHITESPACE; } "(" { printf("%d: LPAREN\n", ++tcnt); return LPAREN; } ")" { printf("%d: RPAREN\n", ++tcnt); return RPAREN; } @@ -20,6 +34,5 @@ int tcnt = 0; "-" { printf("%d: MINUS\n", ++tcnt); return MINUS; } "*" { printf("%d: MULT\n", ++tcnt); return MULT; } "/" { printf("%d: DIV\n", ++tcnt); return DIV; } -\".*\" { printf("%d: STRING\n", ++tcnt); return STRING; } . ; // do nothing %% |
