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+CiNpbmNsdWRlPHN0ZGxpYi5oPgojZGVmaW5lIFRPS0VOX0lEIDEKI2RlZmluZSBUT0tFTl9OVU1CRVIgMgojZGVmaW5lIFRPS0VOX09QRVJBVE9SIDMKI2RlZmluZSBUT0tFTl9LRVlXT1JEIDQKJX0KaWRbYS16QS1aXVthLXpBLVowLTldKm51bWJlclswLTldK29wZXJhdG9yWysqLy1dCmtleXdvcmQoaWZ8ZWxzZXx3aGlsZXxmb3IpCiUlCntpZH17cHJpbnRmKCJUT0tFTl9JRDolc1xuIix5eXRleHQpO3JldHVybiBUT0tFTl9JRDt9CntudW1iZXJ9e3ByaW50ZigiVE9LRU5fTlVNQkVSOiVzXG4iLHl5dGV4dCk7cmV0dXJuIFRPS0VOX05VTUJFUjt9CntvcGVyYXRvcn17cHJpbnRmKCJUT0tFTl9PUEVSQVRPUjolc1xuIix5eXRleHQpO3JldHVybiBUT0tFTl9PUEVSQVRPUjt9CntrZXl3b3JkfXtwcmludGYoIlRPS0VOX0tFWVdPUkQ6JXNcbiIseXl0ZXh0KTtyZXR1cm4gVE9LRU5fS0VZV09SRDt9CltcdFxuXTsKcHJpbnRmKCJlcnJvcjppbnZhbGlkIGNoYXJhY3RlciclYydcbiwqeXl0ZXh0KTsKJSUKaW50IG1haW4oKQp7Cnl5bGV4KCk7CnJldHVybiAwOwp9CmludCB5eXdyYXAoKTsKewpyZXR1cm4gMTsKfQ==