lex
%{
#include<stdio.h>
#include<stdlib.h>
#define TOKEN_ID 1
#define TOKEN_NUMBER 2
#define TOKEN_OPERATOR 3
#define TOKEN_KEYWORD 4
id
[a
-zA
-Z
][a
-zA
-Z0
-9]*number[0-9]+operator
[+*/-]keyword(if|else|while|for)
%%
{id}{printf("TOKEN_ID:%s\n",yytext);return TOKEN_ID;}
{number}{printf
("TOKEN_NUMBER
:%s\n",yytext);return TOKEN_NUMBER;} {operator}{printf("TOKEN_OPERATOR:%s\n",yytext);return TOKEN_OPERATOR;}
{keyword}{printf("TOKEN_KEYWORD:%s\n",yytext);return TOKEN_KEYWORD;}
[\t\n];
printf("error:invalid character'%c'\n",*yytext);
%%
int main()
{
yylex();
return 0;
}
int yywrap();
return 1;
%}
bGV4CiV7CiNpbmNsdWRlPHN0ZGlvLmg+CiNpbmNsdWRlPHN0ZGxpYi5oPgojZGVmaW5lIFRPS0VOX0lEIDEKI2RlZmluZSBUT0tFTl9OVU1CRVIgMgojZGVmaW5lIFRPS0VOX09QRVJBVE9SIDMKI2RlZmluZSBUT0tFTl9LRVlXT1JEIDQKCmlkW2EtekEtWl1bYS16QS1aMC05XSpudW1iZXJbMC05XStvcGVyYXRvclsrKi8tXQprZXl3b3JkKGlmfGVsc2V8d2hpbGV8Zm9yKQolJQp7aWR9e3ByaW50ZigiVE9LRU5fSUQ6JXNcbiIseXl0ZXh0KTtyZXR1cm4gVE9LRU5fSUQ7fQp7bnVtYmVyfXtwcmludGYoIlRPS0VOX05VTUJFUjolc1xuIix5eXRleHQpO3JldHVybiBUT0tFTl9OVU1CRVI7fQp7b3BlcmF0b3J9e3ByaW50ZigiVE9LRU5fT1BFUkFUT1I6JXNcbiIseXl0ZXh0KTtyZXR1cm4gVE9LRU5fT1BFUkFUT1I7fQp7a2V5d29yZH17cHJpbnRmKCJUT0tFTl9LRVlXT1JEOiVzXG4iLHl5dGV4dCk7cmV0dXJuIFRPS0VOX0tFWVdPUkQ7fQpbXHRcbl07CnByaW50ZigiZXJyb3I6aW52YWxpZCBjaGFyYWN0ZXInJWMnXG4iLCp5eXRleHQpOwolJQppbnQgbWFpbigpCnsKeXlsZXgoKTsKcmV0dXJuIDA7Cn0KaW50IHl5d3JhcCgpOwpyZXR1cm4gMTsKJX0=