编译原理last集c语言,编译原理作业集-第七章.doc

编译原理作业集-第七章

第七章 语义分析和中间代码产生

本章要点

1. 中间语言,各种常见中间语言形式;

2. 说明语句赋值语句布尔表达式控制语句的翻译;

3. 过程调用的处理;

4. 类型检查;

本章目标

掌握和理解中间语言,各种常见中间语言形式类型检查等内容。

本章重点

1.中间代码的几种形式,它们之间的相互转换:四元式、三元式、逆波兰表示3.赋值语句算术表达式、布尔表达式的翻译及其中间代码格式4.各种控制流语句的翻译及其中间代码格式5.过程调用的中间代码格式6.类型检查本章难点

2. 类型系统和类型检查;

作业题

一、单项选择题:

1. 布尔表达式计算时可以采用某种优化措施,比如A and B用if-then-else可解释为。

a. if A then true else Bb. if A then B else false;

c. if A then false else true; d. if A then true else false;

2. 为了便于优化处理,三地址代码可以表示成a. 三元式 b. 四元式 c. 后缀式 d. 间接三元式

3. 使用三元式是为了:

便于代码优化处理 b. 避免把临时变量填入符号表

节省存储代码的空间 提高访问代码的速度

4. if x relop y then L表示成四元式为 。

a. (relop,x,y,L);b. (relop,L,x,y);c. (relop,x,L,y);d. (L,x,y,relop);

8. 在编译程序中, 不是常见的中间语言形式。

a.波兰式;b. 三元式;c. 四元式; d. 抽象语法树;

9. 在编译程序中安排中间代码生成的目的是________。

a. 便于提高编译效率; b. 便于提高分析的正确性;

c. 便于代码优化和目标程序的移植;d.便于提高编译速度;

10. 按照教材中的约定,下面 不是类型表达式:

a. boolean;b. type-error;c. real;d. DAG;

11. 一个Pascal函数

function f ( a, b:char ) :↑integer;

……

其作用域类型是 :

a. char×integer;b. char×char;c. char×pointer(integer);d. integer×integer;

12. 因为标识符可用于多种情况,比如常量标识符、变量标识符、过程标识符等等。因此,在符号表中为了给出各个符号的标志,常给标识符引入一个属性kind,然后在相应产生式的语义动作中添加给kind属性赋值的语句。比如,在在产生式D(id:T的语义动作中添加赋值语句id.kind= 。

a. VAR; b. CONSTANT;c. PROC;d. FUNC;

13. 下面 情况下,编译器需要创建一张新的符号表。

a. 过程调用语句;b. 标号说明语句;c. 数组说明语句;d.记录说明语句;

14. 函数function f(a,b:char):↑integer;…

所以f函数的类型表达式为:

a. char×char→pointer(integer); b. char×char→pointer;

c. char×char→integer; d. char×char→integer (pointer)

15. 如果一个语言的编译器能保证编译通过的程序,在运行时不会出现类型错误,则称该语言是 。

a. 静态的;b. 强类型的;c. 动态的;d. 良类型的;

一.答案:1. b;2. d;3. b;4. d;5. c;6. c.;7. a;8. a;9. c;10. d;11. b;12. a;13. d;14. a;15. b;

二、填空题:

1. 语法分析是依据语言的语法规则进行的,中间代码产生是依据语言的规则进行的。

2. 多目运算x:=y[i]的三元式表示为两部分:和。

3. 生成三地址代码时,临时变量的名字对应抽象语法树的。

4. 一个类型表达式或者是基本类型,或者由施加于其它类型表达式组成。

5.。tblptr和offset分别保存尚未处理完的过程的 和它们的offset,这两个栈顶的元素分别是正在处理的过程的的符号表指针和 。

7. 在一些pascal的实现中,如果说明中出现了没有名字的类型表达式,编译器这样处理:建立一个 来和每个声明的变量标识符相联系。

8. 赋值语句a:=b*-c+b*-c的后缀式为 。

9. 多目运算

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441270.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【CodeForces - 244A 】Dividing Orange (构造,水题)

题干: One day Ms Swan bought an orange in a shop. The orange consisted of nk segments, numbered with integers from 1 to nk. There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided…

兔子吃萝卜的c语言编程,狼追兔子的c语言实现

满意答案16guoyuming2013.03.05采纳率:49% 等级:13已帮助:8005人用单链表实现#include #includetypedef struct node{int cave;struct node * next;}node,*LinkList;void main(){int i0,j,count1; // 初始值为1;LinkList L,p,h…

【CodeForces - 244B】Undoubtedly Lucky Numbers (dfs打表 + 二分)

题干: Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x  4, and y  7, then numbers 47, 74…

c语言二叉树构造与输出,C语言数据结构树状输出二叉树,谁能给详细的解释一下...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼void TranslevelPrint(Bitree bt){struct node{Bitree vec[MAXLEN]; //存放树结点int layer[MAXLEN]; //结点所在的层int locate[MAXLEN]; //打印结点的位置int front,rear;}q;int i,j,k;int nLocate;j 1;k 0;q.front 0;q.rear …

【CodeForces - 245C 】Game with Coins (思维,贪心)

题干: Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has aicoins. Polycarpus and Vasily move in turns. Polycarpus moves first. Du…

【CodeForces - 246D】Colorful Graph (暴力,图,存边,STL)

题干: Youve got an undirected graph, consisting of n vertices and m edges. We will consider the graphs vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer ci. Lets consi…

android 动态换肤框架,GitHub - ss520k/Android-Skin-Loader: 一个通过动态加载本地皮肤包进行换肤的皮肤框架...

Android-Skin-Loader更新日志导入到Android Studio,使用gradle构建皮肤包(见7. 皮肤包是什么?如何生成?)(2015-12-02)解决Fragment换肤在某些版本的support-v4包下失效的问题(感谢javake同学)(2015-12-02)对textColor加入selector类型的资源的…

【CodeForces - 349A】Cinema Line (贪心(其实不是贪心),乱搞)

题干: The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the boo…

android 获取默认程序图标,android – PackageManager.getApplicationIcon()返回默认图标?...

我刚想通了.有一个PackageManager.getDefaultActivityIcon()方法返回一个Drawable.如果Drawable的Bitmap与应用程序图标Drawable的Bitmap匹配,则它是默认图标.PackageManager pm context.getPackageManager();Drawable icon pm.getApplicationIcon(apk.package_name);Drawabl…

【CodeForces - 255A】Greg's Workout (水题)

题干: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in orde…

android吸附菜单,Android仿微博、人人Feed详情页吸附导航栏

仿微博、人人的feed详情页面:Listview上下滑动,导航栏view可吸附在顶部的效果。一、实现效果上图:效果图.gif欢迎拍砖,拍拍更进步。没有对比,怎么会有伤害,下面是 微博、人人的Feed详情页:微博、…

android 居右属性,使用layoutDirection属性设置布局靠左或靠右

通过设置layoutDirection属性值为mx.core.LayoutDirection.RTL(右到左)或mx.core.LayoutDirection.LTR(左到右),使布局为靠左或靠右(如下图)。该属性可设置3种值,LayoutDirection.RTL、LayoutDirection.LTR和null(ILayoutDirectionElement时)/undefined(…

【CodeForces - 255B】Code Parsing(思维,字符串)

题干: Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitalys algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: …

【CodeForces - 255C】Almost Arithmetical Progression (dp,离散化)

题干: Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: a1  p, wh…

Android手机mm开头的大文件,[2018年最新整理]2Android源代码编译命令m和mm和mmm以及make分析.doc...

[2018年最新整理]2Android源代码编译命令m和mm和mmm以及make分析老罗的新浪微博:/shengyangluo,欢迎关注!在前文中,我们分析了Android编译环境的初始化过程。Android编译环境初始化完成后,我们就可以用m/mm/mmm/make命…

【CodeForces - 349C】Mafia(思维模拟,优秀的二分)

题干: One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a pl…

android新材料设计,android - 如何实现新材料BottomAppBar为BottomNavigationView - SO中文参考 - www.soinside.com...

解决了基本上,而不是试图迫使菜单的资源,我需要的布局,我用这个方法,而不是,我只是把使用“空”元素作为dglozano建议BottomAppBar内的LinearLayout。使用?attr/selectableItemBackgroundBorderless我也能做到这一点实…

【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)

题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n  m meters. On the occasion of the citys anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the …

html教程是语音版,【HTML教程】HTML 语言简介

标签是一个容器标签,用于放置网页的主体内容。浏览器显示的页面内容,都是放置在它的内部。它是的第二个子元素,紧跟在后面。网页标题hello world

【POJ - 1664】放苹果 (递归经典题 或 dp 或 母函数)

题干: 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。 Input 第一行是测试数据…