编程语言原理 [英] principle of programming languages

查看:100
本文介绍了编程语言原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下语言. a和b代表整数变量的名称. L是可以分配给语句的标签..语言的语句如下.

a=b
a=a+1
a=a-1
if a=0, goto L
if a>0, goto L
goto L
halt



问题1)找到两个整数的乘积.
问题2)找到整数除法的余数.
Q.3)交换两个变量的值(规则(i)只能使用一次)

例如.将两个数字a和b相加,我们可以生成代码:

L: a=a+1
b=b-1
if b>0 then goto L
halt.



请张贴解决方案.再次查看您的要求.您必须:

1)找到两个整数的乘积.
2)找到整数除法的余数.
3)互换两个变量的值(规则(i)只能使用一次-我不知道这意味着什么)

因此,您定义了五个整数:

a = 5
b = 6
c = 7
product = 0
remainder = 0


1)将ab相乘得到product

2)将c划分为product
时,找到余数remainder
3)交换ab的值,而不定义任何其他变量

它不是火箭科学,您当然不需要在代码中使用goto.

顺便说一句,我用四行代码得到了答案,但是我不会将它提供给您.您必须自己弄清楚.


如果要回答我的问题,我会学习.


Consider the following language. a and b represent names of integer variables. L is a label that can be assigned to a statement.. statements in the language are as follows.

a=b
a=a+1
a=a-1
if a=0, goto L
if a>0, goto L
goto L
halt



Q.1) find the product of two integers.
Q.2) find the remainder of integer division.
Q.3) Interchange the values of two variables (rule (i) can be used only once)

for example. to add two numbers a and b, we can generate the code:

L: a=a+1
b=b-1
if b>0 then goto L
halt.



please post the solutions.. PLEASE

解决方案

Exactly what are you going to learn if we do your homework for you?


Look at your requirements again. You have to:

1) find the product of two integers.
2) find the remainder of integer division.
3) Interchange the values of two variables (rule (i) can be used only once - I don''t know what this means)

So, you have five integers defined:

a = 5
b = 6
c = 7
product = 0
remainder = 0


1) Multiply a and b together to get product

2) Find the remainder remainder when you divide c into product

3) Swap the values of a and b without defining any other variables

It ain''t rocket science, and you certainly don''t need to use a goto ANYWHERE in the code.

By the way, I have the answer in four lines of code, but I''m not going to give it to you. You have to figure it out on your own.


i''ll learn if you answer my queries.


这篇关于编程语言原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆