?? lex.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 + -