📄 mylexer.c
字号:
/****************************************************************************
* U N R E G I S T E R E D C O P Y
*
* You are on day 1 of your 30 day trial period.
*
* This file was produced by an UNREGISTERED COPY of Parser Generator. It is
* for evaluation purposes only. If you continue to use Parser Generator 30
* days after installation then you are required to purchase a license. For
* more information see the online help or go to the Bumble-Bee Software
* homepage at:
*
* http://www.bumblebeesoftware.com
*
* This notice must remain present in the file. It cannot be removed.
****************************************************************************/
/****************************************************************************
* mylexer.c
* C source file generated from mylexer.l.
*
* Date: 11/20/08
* Time: 09:38:15
*
* ALex Version: 2.07
****************************************************************************/
#include <yylex.h>
/* namespaces */
#if defined(__cplusplus) && defined(YYSTDCPPLIB)
using namespace std;
#endif
#if defined(__cplusplus) && defined(YYNAMESPACE)
using namespace yl;
#endif
#define YYFASTLEXER
#line 1 ".\\mylexer.l"
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
#include "string.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define MAXRESERVED 6
#define MAXTOKENLEN 40
typedef enum
{ENDFILE, ERROR,
ELSE, IF, INT, RETURN, VOID, WHILE,
ID, NUM,
// + - * / < <= > >= == != =
PLUS, MINUS, TIMES, OVER, LESS, LESSEQ, MORE, MOREEQ, EQ, NOTEQ, ASSIGN,
// ; , ( ) { } [ ] /* */
SEMI, COMMA, LP, RP, LB, RB, LSB, RSB, LCOMMENT, RCOMMENT
}TokenType;
FILE* source;
FILE* listing;
int lineno;
char tokenString[MAXTOKENLEN+1];
void printToken( TokenType, const char* );
#line 79 "mylexer.c"
/* repeated because of possible precompiled header */
#include <yylex.h>
/* namespaces */
#if defined(__cplusplus) && defined(YYSTDCPPLIB)
using namespace std;
#endif
#if defined(__cplusplus) && defined(YYNAMESPACE)
using namespace yl;
#endif
#define YYFASTLEXER
#include ".\mylexer.h"
#ifndef YYTEXT_SIZE
#define YYTEXT_SIZE 100
#endif
#ifndef YYUNPUT_SIZE
#define YYUNPUT_SIZE YYTEXT_SIZE
#endif
#ifndef YYTEXT_MAX
#define YYTEXT_MAX 0
#endif
#ifndef YYUNPUT_MAX
#define YYUNPUT_MAX YYTEXT_MAX
#endif
/* yytext */
static char YYNEAR yysatext[(YYTEXT_SIZE) + 1]; /* extra char for \0 */
char YYFAR *YYNEAR YYDCDECL yystext = yysatext;
char YYFAR *YYNEAR YYDCDECL yytext = yysatext;
int YYNEAR YYDCDECL yystext_size = (YYTEXT_SIZE);
int YYNEAR YYDCDECL yytext_size = (YYTEXT_SIZE);
int YYNEAR YYDCDECL yytext_max = (YYTEXT_MAX);
/* yystatebuf */
#if (YYTEXT_SIZE) != 0
static int YYNEAR yysastatebuf[(YYTEXT_SIZE)];
int YYFAR *YYNEAR YYDCDECL yysstatebuf = yysastatebuf;
int YYFAR *YYNEAR YYDCDECL yystatebuf = yysastatebuf;
#else
int YYFAR *YYNEAR YYDCDECL yysstatebuf = NULL;
int YYFAR *YYNEAR YYDCDECL yystatebuf = NULL;
#endif
/* yyunputbuf */
#if (YYUNPUT_SIZE) != 0
static int YYNEAR yysaunputbuf[(YYUNPUT_SIZE)];
int YYFAR *YYNEAR YYDCDECL yysunputbufptr = yysaunputbuf;
int YYFAR *YYNEAR YYDCDECL yyunputbufptr = yysaunputbuf;
#else
int YYFAR *YYNEAR YYDCDECL yysunputbufptr = NULL;
int YYFAR *YYNEAR YYDCDECL yyunputbufptr = NULL;
#endif
int YYNEAR YYDCDECL yysunput_size = (YYUNPUT_SIZE);
int YYNEAR YYDCDECL yyunput_size = (YYUNPUT_SIZE);
int YYNEAR YYDCDECL yyunput_max = (YYUNPUT_MAX);
/* backwards compatability with lex */
#ifdef input
#ifdef YYPROTOTYPE
int YYCDECL yyinput(void)
#else
int YYCDECL yyinput()
#endif
{
return input();
}
#else
#define input yyinput
#endif
#ifdef output
#ifdef YYPROTOTYPE
void YYCDECL yyoutput(int ch)
#else
void YYCDECL yyoutput(ch)
int ch;
#endif
{
output(ch);
}
#else
#define output yyoutput
#endif
#ifdef unput
#ifdef YYPROTOTYPE
void YYCDECL yyunput(int ch)
#else
void YYCDECL yyunput(ch)
int ch;
#endif
{
unput(ch);
}
#else
#define unput yyunput
#endif
#ifndef YYNBORLANDWARN
#ifdef __BORLANDC__
#pragma warn -rch /* <warning: unreachable code> off */
#endif
#endif
#ifdef YYPROTOTYPE
int YYCDECL yylexeraction(int action)
#else
int YYCDECL yylexeraction(action)
int action;
#endif
{
yyreturnflg = YYTRUE;
switch (action) {
case 1:
{
#line 50 ".\\mylexer.l"
return IF;
#line 200 "mylexer.c"
}
break;
case 2:
{
#line 51 ".\\mylexer.l"
return ELSE;
#line 207 "mylexer.c"
}
break;
case 3:
{
#line 52 ".\\mylexer.l"
return INT;
#line 214 "mylexer.c"
}
break;
case 4:
{
#line 53 ".\\mylexer.l"
return RETURN;
#line 221 "mylexer.c"
}
break;
case 5:
{
#line 54 ".\\mylexer.l"
return VOID;
#line 228 "mylexer.c"
}
break;
case 6:
{
#line 55 ".\\mylexer.l"
return WHILE;
#line 235 "mylexer.c"
}
break;
case 7:
{
#line 56 ".\\mylexer.l"
return PLUS;
#line 242 "mylexer.c"
}
break;
case 8:
{
#line 57 ".\\mylexer.l"
return MINUS;
#line 249 "mylexer.c"
}
break;
case 9:
{
#line 58 ".\\mylexer.l"
return TIMES;
#line 256 "mylexer.c"
}
break;
case 10:
{
#line 59 ".\\mylexer.l"
return OVER;
#line 263 "mylexer.c"
}
break;
case 11:
{
#line 60 ".\\mylexer.l"
return LESS;
#line 270 "mylexer.c"
}
break;
case 12:
{
#line 61 ".\\mylexer.l"
return LESSEQ;
#line 277 "mylexer.c"
}
break;
case 13:
{
#line 62 ".\\mylexer.l"
return MORE;
#line 284 "mylexer.c"
}
break;
case 14:
{
#line 63 ".\\mylexer.l"
return MOREEQ;
#line 291 "mylexer.c"
}
break;
case 15:
{
#line 64 ".\\mylexer.l"
return EQ;
#line 298 "mylexer.c"
}
break;
case 16:
{
#line 65 ".\\mylexer.l"
return NOTEQ;
#line 305 "mylexer.c"
}
break;
case 17:
{
#line 66 ".\\mylexer.l"
return ASSIGN;
#line 312 "mylexer.c"
}
break;
case 18:
{
#line 67 ".\\mylexer.l"
return SEMI;
#line 319 "mylexer.c"
}
break;
case 19:
{
#line 68 ".\\mylexer.l"
return COMMA;
#line 326 "mylexer.c"
}
break;
case 20:
{
#line 69 ".\\mylexer.l"
return LP;
#line 333 "mylexer.c"
}
break;
case 21:
{
#line 70 ".\\mylexer.l"
return RP;
#line 340 "mylexer.c"
}
break;
case 22:
{
#line 71 ".\\mylexer.l"
return LB;
#line 347 "mylexer.c"
}
break;
case 23:
{
#line 72 ".\\mylexer.l"
return RB;
#line 354 "mylexer.c"
}
break;
case 24:
{
#line 73 ".\\mylexer.l"
return LSB;
#line 361 "mylexer.c"
}
break;
case 25:
{
#line 74 ".\\mylexer.l"
return RSB;
#line 368 "mylexer.c"
}
break;
case 26:
{
#line 75 ".\\mylexer.l"
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);
#line 387 "mylexer.c"
}
break;
case 27:
{
#line 89 ".\\mylexer.l"
return NUM;
#line 394 "mylexer.c"
}
break;
case 28:
{
#line 90 ".\\mylexer.l"
return ID;
#line 401 "mylexer.c"
}
break;
case 29:
{
#line 91 ".\\mylexer.l"
lineno++;
#line 408 "mylexer.c"
}
break;
case 30:
{
#line 92 ".\\mylexer.l"
/* skip whitespace */
#line 415 "mylexer.c"
}
break;
case 31:
{
#line 93 ".\\mylexer.l"
return ERROR;
#line 422 "mylexer.c"
}
break;
default:
yyassert(0);
break;
}
yyreturnflg = YYFALSE;
return 0;
}
#ifndef YYNBORLANDWARN
#ifdef __BORLANDC__
#pragma warn .rch /* <warning: unreachable code> to the old state */
#endif
#endif
YYCONST yymatch_t YYNEARFAR YYBASED_CODE YYDCDECL yymatch[] = {
0
};
int YYNEAR YYDCDECL yytransitionmax = 176;
YYCONST yytransition_t YYNEARFAR YYBASED_CODE YYDCDECL yytransition[] = {
{ 0, 0 },
{ 4, 1 },
{ 5, 1 },
{ 4, 4 },
{ 14, 14 },
{ 14, 14 },
{ 14, 14 },
{ 14, 14 },
{ 14, 14 },
{ 14, 14 },
{ 14, 14 },
{ 14, 14 },
{ 14, 14 },
{ 14, 14 },
{ 35, 23 },
{ 31, 16 },
{ 32, 17 },
{ 33, 18 },
{ 34, 22 },
{ 30, 13 },
{ 37, 24 },
{ 38, 25 },
{ 36, 23 },
{ 39, 26 },
{ 4, 1 },
{ 6, 1 },
{ 4, 4 },
{ 40, 34 },
{ 41, 36 },
{ 42, 37 },
{ 43, 38 },
{ 44, 39 },
{ 7, 1 },
{ 8, 1 },
{ 9, 1 },
{ 10, 1 },
{ 11, 1 },
{ 12, 1 },
{ 45, 40 },
{ 13, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 14, 1 },
{ 46, 42 },
{ 15, 1 },
{ 16, 1 },
{ 17, 1 },
{ 18, 1 },
{ 47, 43 },
{ 48, 44 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 20, 1 },
{ 49, 46 },
{ 21, 1 },
{ 50, 48 },
{ 51, 49 },
{ 29, 6 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 22, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 23, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 24, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 25, 1 },
{ 26, 1 },
{ 19, 1 },
{ 19, 1 },
{ 19, 1 },
{ 27, 1 },
{ 0, 0 },
{ 28, 1 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 },
{ 19, 51 }
};
YYCONST yystate_t YYNEARFAR YYBASED_CODE YYDCDECL yystate[] = {
{ 0, 0, 0 },
{ -3, -8, 0 },
{ 1, 0, 0 },
{ 0, 0, 31 },
{ 0, -6, 30 },
{ 0, 0, 29 },
{ 0, 27, 31 },
{ 0, 0, 20 },
{ 0, 0, 21 },
{ 0, 0, 9 },
{ 0, 0, 7 },
{ 0, 0, 19 },
{ 0, 0, 8 },
{ 0, -23, 10 },
{ 0, -44, 27 },
{ 0, 0, 18 },
{ 0, -46, 11 },
{ 0, -45, 17 },
{ 0, -44, 13 },
{ 51, 0, 28 },
{ 0, 0, 22 },
{ 0, 0, 23 },
{ 51, -90, 28 },
{ 51, -88, 28 },
{ 51, -81, 28 },
{ 51, -90, 28 },
{ 51, -81, 28 },
{ 0, 0, 24 },
{ 0, 0, 25 },
{ 0, 0, 16 },
{ 0, 0, 26 },
{ 0, 0, 12 },
{ 0, 0, 15 },
{ 0, 0, 14 },
{ 51, -88, 28 },
{ 51, 0, 1 },
{ 51, -88, 28 },
{ 51, -87, 28 },
{ 51, -75, 28 },
{ 51, -74, 28 },
{ 51, -63, 28 },
{ 51, 0, 3 },
{ 51, -67, 28 },
{ 51, -45, 28 },
{ 51, -52, 28 },
{ 51, 0, 2 },
{ 51, -30, 28 },
{ 51, 0, 5 },
{ 51, -15, 28 },
{ 51, -23, 28 },
{ 51, 0, 6 },
{ 0, 53, 4 }
};
YYCONST yybackup_t YYNEARFAR YYBASED_CODE YYDCDECL yybackup[] = {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
};
#line 96 ".\\mylexer.l"
void printToken( TokenType token, const char* tokenString)
{
switch(token) {
case IF:
case ELSE:
case INT:
case RETURN:
case VOID:
case WHILE:
fprintf(listing, "reserved word: %s\n", tokenString);
break;
case PLUS: fprintf(listing, "+\n"); break;
case MINUS: fprintf(listing, "-\n"); break;
case TIMES: fprintf(listing, "*\n"); break;
case OVER: fprintf(listing, "/\n"); break;
case LESS: fprintf(listing, "<\n"); break;
case LESSEQ: fprintf(listing, "<=\n"); break;
case MORE: fprintf(listing, ">\n"); break;
case MOREEQ: fprintf(listing, ">=\n"); break;
case EQ: fprintf(listing, "==\n"); break;
case NOTEQ: fprintf(listing, "!=\n"); break;
case ASSIGN: fprintf(listing, "=\n"); break;
case SEMI: fprintf(listing, ";\n"); break;
case COMMA: fprintf(listing, ",\n"); break;
case LP: fprintf(listing, "(\n"); break;
case RP: fprintf(listing, ")\n"); break;
case LB: fprintf(listing, "{\n"); break;
case RB: fprintf(listing, "}\n"); break;
case LSB: fprintf(listing, "[\n"); break;
case RSB: fprintf(listing, "]\n"); break;
case ENDFILE: fprintf(listing, "EOF\n"); break;
case NUM:
fprintf( listing, "NUM, val= %s\n", tokenString);
break;
case ID:
fprintf( listing, "ID, name= %s\n", tokenString);
break;
case ERROR:
fprintf( listing, "ERROR: %s\n", tokenString);
break;
default:
fprintf(listing, "Unknow token: %d\n", token);
}
}
TokenType getToken(void)
{
static int firstTime = TRUE;
TokenType currentToken;
if(firstTime)
{
firstTime = FALSE;
lineno++;
yyin = source;
yyout = listing;
}
currentToken = yylex();
strncpy(tokenString,yytext,MAXTOKENLEN);
fprintf(listing,"\t%d: ",lineno);
printToken(currentToken,tokenString);
return currentToken;
}
void main()
{
char pgm[20] = "1.txt" ;
source = fopen(pgm,"r");
if (source == NULL)
{
fprintf(stderr,"File %s not found\n",pgm);
exit(1);
}
listing = stdout;
fprintf(listing,"\nC- COMPILATION: %s\n",pgm);
while (getToken() != ENDFILE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -