| |
%{ |
| /* front-end scanner for vmgen example |
/* front-end scanner for vmgen example |
| |
|
| Copyright (C) 2001 Free Software Foundation, Inc. |
Copyright (C) 2001,2003 Free Software Foundation, Inc. |
| |
|
| This file is part of Gforth. |
This file is part of Gforth. |
| |
|
| |
|
| /* %option yylineno (flex option, implied by flex -l) */ |
/* %option yylineno (flex option, implied by flex -l) */ |
| |
|
| %{ |
#include <stdlib.h> |
| #ifndef __GNUC__ |
|
| #include <string.h> |
#include <string.h> |
| char *strdup(const char *s); |
char *mystrdup(const char *s) |
| #endif |
{ |
| |
char *t=malloc(strlen(s)+1); |
| |
return strcpy(t,s); |
| |
} |
| %} |
%} |
| |
|
| %% |
%% |
| do return DO; |
do return DO; |
| print return PRINT; |
print return PRINT; |
| [0-9]+ { yylval.num=strtol(yytext,NULL,10); return NUM; } |
[0-9]+ { yylval.num=strtol(yytext,NULL,10); return NUM; } |
| [a-zA-Z\_][a-zA-Z0-9\_]* { yylval.string=strdup(yytext); return IDENT; } |
[a-zA-Z\_][a-zA-Z0-9\_]* { yylval.string=mystrdup(yytext); return IDENT; } |
| [ \t\n] ; |
[ \t\n] ; |
| [/][/].* ; |
[/][/].* ; |
| . yyerror("illegal character"); exit(1); |
. yyerror("illegal character"); exit(1); |