Skip to content
/ SOUP Public

SOUP: Simple, Ordinary, Ugly Pascal compiler

Notifications You must be signed in to change notification settings

Yeeef/SOUP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

zju compiler project, yet another pascal compiler

requirments

  • 用 lex 写出一个 tiger 语言或者类 C 或者类 PASCAL 某个语言的词法分析器
  • 用 YACC 的 分析方法完成语法分析,并生成语法树和中间代码
  • 如果生成目标代码, 可加分

what we will do

overview

类 pascal 语言的 compiler, 只做到中间代码这一部分( *.asm )

lex -> parse -> semantic analyze -> code generation

我们要实现的 pascal 语法子集见 pascal_grammar/pascal 语法子集.doc

methods

简单的 ply tutorial, ply demo 见 ply_notes

refs

Q&A

  • 什么是编译器生成的中间代码?
  • 我们做完 syntax analysis, 生成的是 parse tree 而非 syntax tree?
    • no. 我们构造的就是 abstract syntax tree
  • 什么时候要构建一个节点,什么时候又不需要?这个必须从书中获得答案
    • 其实不用,这件事有点像艺术,但是并没有那么艺术
  • 是否需要区分 NAME 和 ID?
    • 不需要,在 pascal 语法子集.doc 中 ID 包括了所有的 identifier + reserved word, NAME 实际上是 identifier
    • 在我们的 lex 中,ID 就是 identifier, reserved word 有他们自己的 type
  • Pascal.pdf 中讲的不同,pascal 语法子集.doc 不需要一个特别的声明部分 (对于 function, procedure) 而言,我觉得这很合理;
    • 想错了,routine 中就包含了这个声明部分
  • pascal 语法子集.doc 中 subroutine 和 routine 语法重复,可以直接写成 subroutine: routine 吗?
  • else 的最近匹配规则是怎么实现的来着?
    • parse 直接实现好了
  • 突然觉得 parse tree 需要构建的纯粹一点,能建节点的都尽量建
  • 如何更加有效的利用 ply 的 debug 机制
  • 需要注意的一个点,token 读进去的 char 实际上是 'l', 我们在做运算的时候,要用的是 l
    • 修改了 lex, 解决

About

SOUP: Simple, Ordinary, Ugly Pascal compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published