Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (25 sloc) 1.36 KB

3.1 节的练习

3.1.1

将下面 C++ 程序:

float limitedSquare(x){float x;
    /* returns x-squared, nut never more than 100 */
   return (x <= -10.0 || x >= 10.0) ? 100 : x*x;
}

划分成正确的词素序列。哪些词素应该有关联的语法值?应该具有什么值?

解答

<float> <id, limitedSquaare> <(> <id, x> <)> <{>
    <float> <id, x>
    <return> <(> <id, x> <op,"<="> <num, -10.0> <op, "||"> <id, x> <op, ">="> <num, 10.0> <)> <op, "?"> <num, 100> <op, ":"> <id, x> <op, "*"> <id, x>
<}>

3.1.2

像 HTML 或 XML 之类的标记语言不同于传统的程序设计语言,他们要么包含有很多的标点符号(标记),如 HTML, 要么使用由用户自定义的标记集合,如 XML。而且标记还可以带有参数。请之处如何把如下的 HTML 文档

Here is a photo of <b>my house</b>;
<p><img src="house.gif"/><br/>
see <a href="morePix.html">More Picture</a> if you
liked that one.</p>

划分成适当的词素序列。哪些词素应该具有相关联的语法值?应该具有什么样的值?

解答

<text, "Here is a photo of"> <nodestart, b> <text, "my house"> <nodeend, b>
<nodestart, p> <selfendnode, img> <selfendnode, br>
<text, "see"> <nodestart, a> <text, "More Picture"> <nodeend, a>
<text, "if you liked that one."> <nodeend, p>