一、需求分析:
1、设计一个简单的LISP算法表达式计算器。
简单LISP算法表达式定义如下:
(1)、一个0…9的整数;或者
(2)、(运算符 表达式 表达式)
例如,6,(+45),(+(+25)8)都是表达式,其值分别为:6,9,15
2、实现LISP加法表达式的求值。

程序运行界面如上图
二、概要设计:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
#include <iostream.h>
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
#ifndef NULL
#define NULL 0
#endif
#ifndef ESC
#define ESC 27
#endif
#ifndef Enter
#define Enter 13
#endif
#ifndef Tab
#define Tab 9
#endif
//以下用顺序存储方式实现栈的定义与操作
typedef char SElemType;
#define STACK_INIT_SIZE 80
#define STACK_INCREMENT_SIZE 20
typedef struct Stack{
SElemType *elem;
int stacklen;
int stacksize;
}Stack;
//end typedef struct Stack
int InitStack(Stack &S)
{
//初始化栈
……
}
//end InitStack(Stack &S)
int Push(Stack &S,SElemType elem)
{
//入栈
……
}
//end Push(Stack &S,SElemType elem)
int Pop(Stack &S,SElemType &elem)
{
//出栈
}
//end Pop(Stack &S,SElemType &elem)
int StackEmpty(Stack S)
{
//判栈空
if(S.stacklen==0) return TRUE;
else return FALSE;
}
//end StackEmpty(Stack S)
//栈定义至此结束
int IsRightInData(char ch[])
{
……
}
int IsNumber(char ReadInChar)
{
……
}
int TurnToInteger(char IntChar)
{
return (int)(IntChar-48);
}
int ASMD(char ch)
{
if(ch=='+'||ch=='-'||ch=='/'||ch=='*') return TRUE;
return FALSE;
}
int Evaluate(char data[256],Stack &S)
{
//待扩展时用到栈
……
}
void DispAbout()
{
//输出本程序设计相关信息
……
}
void main()
{
char data[256],ch;
int value;
Stack S;
InitStack(S);
NEXT:
system("CLS");
DispAbout();
printf("请输入简单LISP算术表达式:");
scanf("%s",data);
if(IsRightInData(data)==TRUE)
{
value=Evaluate(data,S);
printf("计算结果为: %d\n",data,value);
}
else printf("输入表达式有误!\n");
ch=getch();
while(ch!=ESC&&ch!=Enter) ch=getch();
if(ch!=ESC) goto NEXT;
}
三、调试分析:
1、本程序特点:
本程序只支持简单的LISP算术表达式的计算,标准整型及标准整型四则运算尚没有实现。
2、程序主要时空分析:
(1)、本程序的时间复杂度为与表达式长度成线性关系;
(2)、本程序执行过程中需要用到较多空间的变量有 newdata[256],newdata2[256]及主函数中用于存储表达式的data[256];
四、用户手册:
(1)、本程序运行环境为DOS操作系统>,执行文件为:程序分析.EXE
(2)、程序支持中文名的输入,支持路径输入;
(3)、输入文件名时,须同时将文件的后缀名也写上,如ABC.C ,不能只输入ABC ,否则程序无法识别;
(4)、输入结束后,程序即进行分析,如果程序超过1M,可能需要等待一定时间,文件大小为1M时,大概要用 ??秒时间。
五、运行结果:
对本程序输入相关数据进行测试,结果如下所示:

***初始运行界面 ***