⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lex.l

📁 一个用flex、bison和vc开发的堆栈机
💻 L
字号:
%{
#include <malloc.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "symbol.h"
#include "stkmach.h"
#include "cc_tab.h"
int lineno = 0;
%}
string \"[^\n"]+\"
ws [ \t]+
dig [0-9]
alpha [a-zA-Z]
name {alpha}({alpha}|{dig}|[_])*
uint  {dig}+
float {dig}+\.?({dig}+)?
%%
{ws}	/*skip*/
"/*" {
		int c;
		while ((c = input()) != 0)
		{
			if (c == '\n')
				lineno++;
			else if (c == '*')
			{
				if ((c = input()) == '/')
					break;
				else
					unput(c);
			}
		}
	}	
{float} {
		double d;
		sscanf(yytext, "%lf", &d); 
		yylval.tptr = putsym("", NUMBER, d);
		return NUMBER;
	}
{name} { 
	symrec *s;
	s = getsym(yytext);
	if (s == 0)
		s = putsym(yytext, UNDEF, 0);
	yylval.tptr = s;
	return s->type == UNDEF ? VAR:s->type;
	}
"$"	{ 
		int c;
		int n = 0;
		while (isdigit(c=input()))
			n = 10*n+c-'0';
		unput(c);
		if (n == 0)
			execerror("stange $...", (char *)0);
		yylval.narg = n;
		return ARG;
	}
{string}	{
				yylval.str = (char *)malloc(strlen(yytext) - 1);
				strcpy(yylval.str, &yytext[1]);
				yylval.str[strlen(yytext) - 2] = 0;
				return STRING;
			}
\n	{ lineno++; return NL; }
"(" { return LP;}
")" { return RP;}
"{" { return LB;}
"}" { return RB;}
"+" { return PLUS;}
"++" { return PLUSPLUS;}
"-" { return MINUS;}
"--" { return MINUSMINUS;}
"+-" { return PLUSMINUS;}
"-+" { return MINUSPLUS;}
"*" { return MUL;}
"^" { return POW;} 
"=" { return AS; }
"/" { return DIV;}
">" { return GT; }
">=" { return GE; }
"==" { return EQ; }
"<" { return LT; }
"<=" { return LE; }
"!=" { return NE; }
"&&" { return AND; }
"||" { return OR; }
"!" { return NOT; }
.	{ printf("unrecognized symbol\n"); getch(); exit(1);}
%%
yywrap()
{
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -