1 Star 0 Fork 1

ylyhappy/编译原理虎书代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tiger.lex 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
ylyhappy 提交于 2024-05-28 10:35 . 增加boolExp
%{
#include <string.h>
#include "util.h"
#include "symbol.h"
#include "absyn.h"
#include "y.tab.h"
#include "errormsg.h"
int charPos=1;
int yywrap(void)
{
charPos=1;
return 1;
}
void adjust(void)
{
EM_tokPos=charPos;
charPos+=yyleng;
}
%}
%%
" " {adjust(); continue;}
"\n" {adjust(); EM_newline(); continue;}
"," {adjust(); return COMMA;}
":" {adjust(); return COLON;}
";" {adjust(); return SEMICOLON;}
array {adjust(); return ARRAY;}
if {adjust(); return IF;}
then {adjust(); return THEN;}
else {adjust(); return ELSE;}
while {adjust(); return WHILE;}
for {adjust(); return FOR;}
to {adjust(); return TO;}
do {adjust(); return DO;}
let {adjust(); return LET;}
in {adjust(); return IN;}
end {adjust(); return END;}
of {adjust(); return OF;}
break {adjust(); return BREAK;}
nil {adjust(); return NIL;}
func {adjust(); return FUNCTION;}
var {adjust(); return VAR;}
type {adjust(); return TYPE;}
"[" {adjust(); return LPAREN;}
"]" {adjust(); return RPAREN;}
"(" {adjust(); return LBRACK;}
")" {adjust(); return RBRACK;}
"{" {adjust(); return LBRACE;}
"}" {adjust(); return RBRACE;}
"." {adjust(); return DOT;}
"+" {adjust(); return PLUS;}
"-" {adjust(); return MINUS;}
"*" {adjust(); return TIMES;}
"/" {adjust(); return DIVIDE;}
"==" {adjust(); return EQ;}
"<>" {adjust(); return NEQ;}
"<" {adjust(); return LT;}
"<=" {adjust(); return LE;}
">" {adjust(); return GT;}
">=" {adjust(); return GE;}
"&" {adjust(); return AND;}
"|" {adjust(); return OR;}
":=" {adjust(); return ASSIGN;}
[a-zA-Z]+ {adjust(); printf("ID is %s", yytext); yylval.sval=yytext; return ID;}
[0-9]+ {adjust(); yylval.ival=atoi(yytext); return INT;}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ylyhappy/hushu.git
git@gitee.com:ylyhappy/hushu.git
ylyhappy
hushu
编译原理虎书代码
master

搜索帮助