diff options
Diffstat (limited to 'lisp.l')
| -rw-r--r-- | lisp.l | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -7,6 +7,11 @@ int tcnt = 0; %} %% +[[:space:]]+ { printf("%d: WHITESPACE\n", ++tcnt); return WHITESPACE; } +"(" { printf("%d: LPAREN\n", ++tcnt); return LPAREN; } +")" { printf("%d: RPAREN\n", ++tcnt); return RPAREN; } +"\." { printf("%d: DOT\n", ++tcnt); return DOT; } + [+-]?([0-9]+|([0-9]*\.[0-9]+))([eE][-+]?[0-9]+)? { yylval.dval = atof(yytext); printf("%d: NUMBER: %f\n", ++tcnt, yylval.dval); @@ -17,7 +22,7 @@ int tcnt = 0; // 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); } + if (!str) { fprintf(stderr, "out of memory!\n"); exit(1); } strncpy(str, yytext + 1, len); str[len] = '\0'; @@ -26,13 +31,10 @@ int tcnt = 0; 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; } -"\." { printf("%d: DOT\n", ++tcnt); return DOT; } -"+" { printf("%d: PLUS\n", ++tcnt); return PLUS; } -"-" { printf("%d: MINUS\n", ++tcnt); return MINUS; } -"*" { printf("%d: MULT\n", ++tcnt); return MULT; } -"/" { printf("%d: DIV\n", ++tcnt); return DIV; } +[^[:space:]\"()]+ { + yylval.strval = strdup(yytext); + printf("%d: SYMBOL: %s\n", ++tcnt, yylval.strval); + return SYMBOL; + } . ; // do nothing %% |
