📄 mylexer.l
字号:
%{
/****************************************************************************
mylexer.l
ParserWizard generated Lex file.
Date: 2007年11月1日
****************************************************************************/
#include <stdio.h>
#include <string.h>
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
typedef enum{HEAD,ELSE,IF,INT,RETURN,VOID,WHILE,LT,GT,LE,GE,EQ,NE,COMMENT,LETTER,DIGIT,ID,NUMBER} TOKEN;
%}
/////////////////////////////////////////////////////////////////////////////
// declarations section
// place any declarations here
letter [A-Za-z]
digit [0-9]
id {letter}{letter}*
number {digit}{digit}*
%%
/////////////////////////////////////////////////////////////////////////////
// rules section
// place your Lex rules here
"else" {printf("ELSE:%s%c ",yytext,' ');return ELSE;}
"if" {printf("IF:%s%c ",yytext,' ');return IF;}
"int" {printf("INT:%s%c ",yytext,' ');return INT;}
"return" {printf("RETURN:%s%c ",yytext,' ');return RETURN;}
"void" {printf("VOID:%s%c ",yytext,' ');return VOID;}
"while" {printf("WHILE:%s%c ",yytext,' ');return WHILE;}
"<" {printf("LT:%s%c ",yytext,' ');return LT;}
">" {printf("GT:%s%c ",yytext,' ');return GT;}
"<=" {printf("LE:%s%c ",yytext,' ');return LE;}
">=" {printf("GE:%s%c ",yytext,' ');return GE;}
"==" {printf("EQ:%s%c ",yytext,' ');return EQ;}
"!=" {printf("NE:%s%c ",yytext,' ');return NE;}
"{" {printf("{:%s%c ",yytext,' '); return '{';}
"}" {printf("}:%s%c ",yytext,' '); return '}';}
"(" {printf("(:%s%c ",yytext,' ');return '(';}
")" {printf("):%s%c ",yytext,' ');return ')';}
"[" {printf("[:%s%c ",yytext,' ');return '[';}
"]" {printf("]:%s%c ",yytext,' ');return ']';}
"+" {printf("+:%s%c ",yytext,' ');return '+';}
"-" {printf("-:%s%c ",yytext,' ');return '-';}
"*" {printf("*:%s%c ",yytext,' ');return '*';}
"/" {printf("/:%s%c ",yytext,' ');return '/';}
"%" {printf("%:%s%c ",yytext,' ');return '%';}
";" {printf(";:%s%c ",yytext,' ');return ';';}
"=" {printf("=:%s%c ",yytext,' ');return '=';}
"," {printf(",:%s%c ",yytext,' ');return ',';}
{id} {printf("id:%s%c ",yytext,' ');return ID;}
{number} {printf("number:%s%c ",yytext,' '); return NUMBER;}
"/*" {
char c;
int done = FALSE;
ECHO;
do
{ while((c=input())!='*')
putchar(c);
putchar(c);
while((c=input())=='*')
putchar(c);
putchar(c);
if(c=='/') done =TRUE;
} while(!done);
printf("\n: There are the conment!");
return COMMENT;
}
%%
/////////////////////////////////////////////////////////////////////////////
// programs section
int main(void)
{
while (yylex()) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -