Skip to content
Snippets Groups Projects
Commit 2d085531 authored by chaoei's avatar chaoei
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
# Auto detect text files and perform LF normalization
* text=auto
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Lab.iml" filepath="$PROJECT_DIR$/.idea/Lab.iml" />
</modules>
</component>
</project>
\ No newline at end of file
File added
# GNU make手册:http://www.gnu.org/software/make/manual/make.html
# ************ 遇到不明白的地方请google以及阅读手册 *************
# 编译器设定和编译选项
CC = gcc
FLEX = flex
BISON = bison
CFLAGS = -std=c99
# 编译目标:src目录下的所有.c文件
CFILES = $(shell find ./ -name "*.c")
OBJS = $(CFILES:.c=.o)
LFILE = $(shell find ./ -name "*.l")
YFILE = $(shell find ./ -name "*.y")
LFC = $(shell find ./ -name "*.l" | sed s/[^/]*\\.l/lex.yy.c/)
YFC = $(shell find ./ -name "*.y" | sed s/[^/]*\\.y/syntax.tab.c/)
LFO = $(LFC:.c=.o)
YFO = $(YFC:.c=.o)
parser: syntax $(filter-out $(LFO),$(OBJS))
$(CC) -o parser $(filter-out $(LFO),$(OBJS)) -lfl -ly
syntax: lexical syntax-c
$(CC) -c $(YFC) -o $(YFO)
lexical: $(LFILE)
$(FLEX) -o $(LFC) $(LFILE)
syntax-c: $(YFILE)
$(BISON) -o $(YFC) -d -v $(YFILE)
-include $(patsubst %.o, %.d, $(OBJS))
# 定义的一些伪目标
.PHONY: clean test
test:
./parser ../Test/test1.cmm
clean:
rm -f parser lex.yy.c syntax.tab.c syntax.tab.h syntax.output
rm -f $(OBJS) $(OBJS:.o=.d)
rm -f $(LFC) $(YFC) $(YFC:.c=.h)
rm -f *~
%{
int chars = 0;
%}
// {definitions}
INT
FLOAT
ID
SEMI ;
COMMA ,
ASSIGNOP =
RELOP >|<|>=|<=|==|!=
PLUS +
MINUS -
STAR *
%%
// {rules}
%%
// {user subroutines}
File added
README 0 → 100644
文件结构:
/Lab
/Code
Makefile
lexical.l
syntax.y
main.c
.
.
/Test
test1.cmm
test2.cmm
.
.
/report.pdf
/parser
/README
Code目录: 1. 用于存放所有flex,bison,C语言源文件和头文件以及Makefile;
2. 该目录下有一个Makefile文件,请使用它。除了定义和修改一些伪目标外不可对文件做其它修改(否则助教测试失败必扣分);
3. 请勿在该目录下创建子目录(如include、src等),实验的代码量还没有复杂到需要将头文件以及源文件分开管理的程度;
4. 避免不合理的文件include关系,比如一个C文件include另一个C文件,Makefile执行时会报错。
Test目录: 1. 用于存放测试文件以及输出文件(如果有输出文件的话);
2. 请将测试文件以".cmm"作为后缀名。
report.pdf: 1. 该文件为你所需提交的实验报告,请自行完成后替换该文件。请在实验报告里写明姓名,学号和联系邮箱。
(如果是组队提交的,只需一份实验报告)
parser: 1. 用你编译生成的二进制文件替换该文件。
README: 1. 你正打开着的...
int main()
{
int i = 1;
int j = 2;
}
int main(){
float a[10][2];
int i;
a[5,3] = 1.5;
if(a[1][2] == 0) i = 1 else i = 0;
}
parser 0 → 100644
File added
# Project 1
完成包括语法规则在内的Flex代码
Flex对.l文件进行编译 flex lexical.l
gcc main.c lex.yy.c -lfl -o scanner
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment