Giter Club home page Giter Club logo

compiling-principle-experiment's Introduction

编译原理课程实验

1 项目简介

1.1 系统介绍

  编译原理在源程序原型之前需要对其完成词法分析、语法分析、中间代码生成、代码优化和目标代码生成5个部分工作。该实验通过设计词法分析器和LL(1)语法分析器来实现其中的词法分析和语法分析部分功能。

1.2 实现思路

1.2.1 词法分析器:

(1)首先将语言的关键字、运算符和界限符存储起来并为其编号。
(2)词法分析器读取要分析的程序代码,识别并消除代码中的注释部分。
(3)对消除注释的代码进行词法分析,分别识别其中的关键字、运算符、界限符、标识符和常量并输出其在系统中的编号(标识符编号为100,常量为101)。

1.2.2 LL(1)语法分析器:

(1)首先将检验文法是否存在左递归,如果属于左递归文法则消除其中的递归部分使其变成非递归文法。
(2)读入待分析文法产生式,计算非终结符的First、Follow和Select集合。
(3)依据Select集合构造LL(1)语法分析表,最后依据分析表对所给句子进行语法分析。

2 程序运行结果图

2.1词法分析器

图片说明  
图1 词法分析器程序运行结果图

2.2 LL(1)语法分析器

图片说明  
图2 LL(1)语法分析器程序运行结果图

compiling-principle-experiment's People

Contributors

alan19108 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

compiling-principle-experiment's Issues

结果不对呀兄弟

结果不对呀兄弟,实验二语法分析里面,main函数后面最主要的那个while循环,flag直接被置1,然后就是analysis Failed!,另一方面那个Input.txt是不是也有问题呀,里面只有六个产生式,但是根据你发出来的运行结果图片,里面还用到了这六个之外的产生式。还有就是我愣是没找到你到底把 i+i*i 这个式子存在哪儿了。

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.