问题 单项选择题

假设某程序语言的文法如下:

S→SaT|T

T→TbR|R

T→PdR|P P→fSg|e

其中:VT=a,b,d,e,f,g,VNS,T,R,P,S是开始符号。那么,此方法是 (38) 方法。这种文法的语法分析通常采用优先矩阵,优先矩阵给出了该文法中各个终结符之间的优先关系 (大于,小于,等于,无关系)。在上述文法中,某些终结符之间的优先关系如下:

b (39) a:f (40) g;a (41) a;d (42) d。

(42)处填()。

A.大于

B.小于

C.等于

D.无关系

答案

参考答案:B

解析:

[分析]: 所谓算符文法,可以描述如下:如果在一个文法G中,不含有形如“U→A…B…”的产生式,其中A,B∈Vn,则G为算符文法。也就是说,如果G是算符文法,那么G的任何产生式的右部都不会出现两个非终结符号相邻的情况,而且,对算符文法而言,也不会产生两个非终结符号相邻出现的句型。这种性质意味着,如果把终结符号看做广义运算符,而把非终结符号看做广义运算的对象,则在算符文法的任何句型中,两相邻运算符之间的运算对象至多只有一个,而不会出现其间运算对象个数不确定的情况。这样就使得广义运算总是按照中缀形式出现的,对语法分析工作非常有益。

对于给定的文法G,可以逐个检查G的各产生式,查看它们的右部是否含有相邻出现的非终结符号,以确定G是否为算符文法,然后再构造相应的优先矩阵。若此矩阵中无多重定义的元素,同理则可确认一算符优先文法。在算符文法中,一般按照如下规则判断终结符之间的优先关系。

当且仅当G中有形如“U→…ab…”或者“U→…aBb…”的产生式,a=b;

当且仅当G中有形如“U→…aA…”的产生式,且有或者“A=+=>b…”或者“A= +=>…aB”时,a>b;

当且仅当G中有形如“U→…Ab…”的产生式,且有或者“A=+=>a…”或者“A= +=>…aB”时,a>b。

如果算符文法G的任何一对终结符号之间,至多只有3种算符优先关系——等于、大于或者小于——成立,则称G为算符优先文法。

阅读理解

When I was young,I liked to play jokes on people I knew, especially on my parents and friends. One day my mother was cooking and I was playing with my younger brother Tony. Suddenly I ran to my mother and said: “Tony fell from the open window!” She was very worried and ran out of the kitchen. Then I said: “Don’t worry, I’m just joking.” My mother shouted at me, “If you do it again, I’ll hit you.”

Another day I went swimming with my friends in the sea. I wanted to play a joke on them. In the beginning I swam fast and I called out “Help!”. All my friends came to help me. However, they found that I was joking. But half an hour later I wasn’t joking. I was so fast, soon I got tired and couldn’t swim on in water. I tried my best to call my friends for help, but this time nobody came to help me.

In the end they found I was telling the truth. They came and saved my life. They took me to the hospital. This is the best lesson in my life. From then on I haven’t joked on anyone.

小题1:When he was young, the writer liked to _______.

A.play with his brother

B.help his mother cook

C.play jokes on people

D.go swimming with his friends小题2:What happened when the writer was playing with his brother?    ______

A.He got tired.

B.He played a joke on his mother.

C.Tony fell from the open window.

D.His mother hit him.小题3:In the beginning, all his friends came to help him because he ______.

A.swam fast

B.called for help

C.would sink in water

D.couldn’t swim on in the water小题4:When the writer called his friends for help for the second time, they ______.

A.took him to the hospital at once

B.came and saved him immediately

C.thought at first he was joking again

D.did nothing because the writer had lied to them小题5:The story tells us that ________.

A.swimming is dangerous

B.the writer is a naughty boy

C.one can play jokes only on people he knows

D.if someone always tells lies, others won’t trust (信任) him

单项选择题