5752112 [rkeene@sledge /home/rkeene/personal/school/comp-sci-ii/lab3]$ cat -n lab3.cpp
 1 /* Roy Keene
 2    CS 2314
 3    Section 04
 4    Lab 03
 5    03 Sept 02
 6    lab3.cpp
 7 
 8    Fully tested configurations:
 9         *MSVC++       6.0    i386    Windows XP
10         Sun Workshop 6.0    sun4u   Solaris
11         pgCC         4.0-2  i386    Linux
12         g++          3.0.3  sun4u   Solaris
13         g++          3.0.2  ip27    IRIX
14         g++          2.95.4 i386    FreeBSD
15         g++          2.95.4 alpha   Linux
16         g++          2.95.4 sun4u   Linux
17         g++          2.95.4 powerpc Linux
18         g++          2.95.3 i386    Linux
19         g++          2.95.3 sun4u   Solaris
20         c++          2.95.2 powerpc MacOS X
21         g++          2.8.1  sun4u   Solaris
22 */
23 
24 #include <iostream>
25 #include <string>
26 
27 using namespace std;
28 #include "stack.h"
29 
30 int main(void) {
31     Stack exprstack;
32     string expr;
33     int eVal;
34     unsigned int i, unbal=0;
35 
36     cout << "Please enter your expresion? ";
37     cin >> expr;
38     for (i=0;i<expr.size();i++) {
39         if (expr[i]=='#') break;
40         cout << "Token=" << expr[i] << "     ";
41         if (expr[i]=='(' || expr[i]=='{' || expr[i]=='[') {
42             exprstack.Push(expr[i]/40);
43             cout << "push " << expr[i]/40;
44         }
45         if (expr[i]==')' || expr[i]=='}' || expr[i]==']') {
46             eVal=exprstack.Pop();
47             cout << "pop " << eVal;
48             if (eVal!=(expr[i]/40)) {
49                 if (eVal!=-1) {
50                     cout << "; push " << eVal;
51                     exprstack.Push(eVal);
52                 }
53                 cout << "\nUnexpected '" << expr[i] << "' in expression.";
54                 unbal++;
55             }
56         }
57         cout << "\n";
58     }
59     if (exprstack.Empty() && unbal==0) cout << "Balanced\n";
60     while (!exprstack.Empty()) cout << "Unmatched '" << "#([{"[exprstack.Pop()] << "'.\n";
61     return(unbal!=0);
62 }
5752113 [rkeene@sledge /home/rkeene/personal/school/comp-sci-ii/lab3]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2002-09-10 23:04:44