1proj.html
来自「C ++ in action」· HTML 代码 · 共 34 行
HTML
34 行
<html>
<head>
<title>Software Project</title>
<meta name="description" content="Design of a calculator in C++">
<meta name="keywords" content="top-down, design, calculator, scanner, parser, symbol table, function pointer, switch">
<link rel="stylesheet" href="../../rs.css">
</head>
<body background="../../images/margin.gif" bgcolor="#FFFFDC">
<!-- Main Table -->
<table cellpadding="6">
<tr>
<td width="78">
<td>
<h2>Software Project</h2>
<p class=topics>Top down design and implementation. Scanner, top-down recursive parser, symbol table. The grammar, problems with associativity. Allocation and ownership of objects returned from a function. Function pointers, switch statements.
<p>Programmers are rarely totally satisfied with their code. So after I抳e written the program for this chapter梐 simple parser-calculator桰 immediately noticed that it could have been done better. Especially the top-level view of the program was not very clear. The nodes of the parsing tree needed access to such components as the <var>Store</var> (the calculator抯 "memory"), the symbol table (to print meaningful error messages), maybe even to the function table (to evaluate built-in functions). I could have either made all these objects global and thus known to everybody, or pass references to them to all the nodes of the tree.
<p>The order of construction of these objects was important, so I felt that maybe they should be combined into one high-level object, the <var>Calculator</var>. The temptation to redesign and rewrite the whole program was strong. Maybe after the nth iteration I could come up with something close to the ideal?
<p>Then I decided I shouldn抰 do it. Part of making a program is coming up with not-so-good solutions and then improving upon them. I would have cheated if I had come up with the best, and then reverse engineered it to fit the top-down design and implementation process. So here it is梩he actual, real-life process of <a href="2spec.html">creating a program</a>.
</table>
<!-- End Main Table -->
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?