Giter Site home page Giter Site logo

zju-stu-lizheng / minipascal_compiler Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 0.0 40.45 MB

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%
compiler

minipascal_compiler's Introduction

Hi there 👋

Liodb

Top Langs

  • 🔭 I'm pursuing a bachelor's degree in computer science and technology at Zhejiang Unerversity.
  • 🌱 I'm currently learning NLP.

minipascal_compiler's People

Contributors

alice-6161 avatar moscow70 avatar zju-stu-lizheng avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

minipascal_compiler's Issues

根据CFG写parser

start to write yacc

You can issue question here whenever you get trouble with it.

Finish ast

将完成的AST类,完整地放入yacc文件中,生成完整的抽象语法树

lex的引号匹配似乎有bug

学生选课助手record.pas还没过,lex的column报错很大,应该是lex的问题,同时字符串赋值也识别不出来,但我还没看懂是lex哪里的问题

lex 问题

IntFloat 不应该加上符号

不要识别符号

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]+)

llvm test

如何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
}

ast

我先写ast的base、type、expr、program。lz看看其他的,动态调度一波

llvm finish

首先,熟悉llvm的操作

其次,逐步往ast中添加codegen方法

最后,完成中间代码生成

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.