View Code? Open in Web Editor
NEW
2022春夏编译原理大程——面向Pascal语言的编译器设计
License: MIT License
Lex 3.10%
Yacc 9.63%
C++ 71.69%
Pascal 7.66%
CMake 0.76%
Makefile 6.47%
Shell 0.69%
minipascal_compiler's Introduction
- 🔭 I'm pursuing a bachelor's degree in computer science and technology at Zhejiang Unerversity.
- 🌱 I'm currently learning NLP.
minipascal_compiler's People
Watchers
minipascal_compiler's Issues
start to write yacc
You can issue question here whenever you get trouble with it.
将完成的AST类,完整地放入yacc文件中,生成完整的抽象语法树
学生选课助手record.pas还没过,lex的column报错很大,应该是lex的问题,同时字符串赋值也识别不出来,但我还没看懂是lex哪里的问题
Int
和 Float
不应该加上符号
不要识别符号
LITERAL_INT [0-9]|[1-9][0-9]+
LITERAL_FLOAT ([0-9]+\.[0-9]+)|([0-9]+\.[0-9]+e{SIGN}?[0-9]+)|([0-9]+e{SIGN}?[0-9]+)
现在的main函数是从test.pas
文件读入输入
如何Cmake
在Our_Pascal_Compiler文件夹下,建一个build文件夹,
mkdir build
cd build
cmake ..
make
.src/opc < ../test/test.pas
lz@ubuntu:~/Documents/Our_Pascal_Compiler/build$ ./src/opc < ../test/test2.pas
new!
start program
program_head ready
new CodeBlock
define main
const_part ready
type_part ready
var_part ready
routine_part ready
routine_head ready
Routine_Body ready
routine ready
accept!
5/16 上午
能解析最简单的pascal
程序
program test;
begin
//comment
end.
ll程序为:
; ModuleID = 'pascal_module'
source_filename = "pascal_module"
define i32 @main() {
entry:
ret i32 0
}
增加break语句
AST_Break_Statement *break_statement;
我先写ast的base、type、expr、program。lz看看其他的,动态调度一波
首先,熟悉llvm
的操作
其次,逐步往ast
中添加codegen
方法
最后,完成中间代码生成