1 / 9

Glowworm Group 20

Glowworm Group 20. 我们的工具. 我们选择使用 JavaCC 作为我们的词法及语法生成器。. JJ 文件生成. 扩展之前的 BNF ,并做了修改。 增加了注释,逻辑运算符等语法。 对左递归,公共前缀等问题进行了必要的处理,在必要的地方增加了 LOOKAHEAD 操作,以保证 编译器的正确生成。. 词法分析. 根 据 javacc 相关规范编写代码 String lex () : { String tokens = "", temp = ""; } { ( temp = reservedWords () {

rue
Download Presentation

Glowworm Group 20

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Glowworm Group 20

  2. 我们的工具 • 我们选择使用JavaCC作为我们的词法及语法生成器。

  3. JJ文件生成 • 扩展之前的BNF,并做了修改。 • 增加了注释,逻辑运算符等语法。 • 对左递归,公共前缀等问题进行了必要的处理,在必要的地方增加了LOOKAHEAD操作,以保证 编译器的正确生成。

  4. 词法分析 • 根据javacc相关规范编写代码 • String lex() : • { • String tokens = "", temp = ""; • } • { • ( • temp = reservedWords() • { • tokens += temp; • } • …. • }

  5. 语法分析 • SimpleNode program() : • {} • { • typeDecBlock() declarationBlock() functionForDecBlock() functionBlock() block() < EOF > • { • return jjtThis; • } • }

  6. 我们的汇编代码转换初步方案 • 我们将使用MASM作为我们的汇编器。

  7. 初步方案 • 词法、语法生成:使用Javacc以及预定义的BNF进行词法,语法分析,生成语法树。 • 中间代码转换:对语法树进行分析以及查错,在没有错误的情况下,生成三地址码。 • 汇编代码生成:对三地址码进行内存、寄存器分配,从而生成汇编代码。 • 使用MASM将汇编代码转换成机器码,从而生成可执行文件。

  8. 演示

  9. 谢谢老师! • 欢迎提出改进意见,我们不胜感激!

More Related