|
4 | 4 |
|
5 | 5 | #include "mc_driver.hpp" |
6 | 6 |
|
7 | | -// wamckee 2013 APR 2 - Instead of testing for == FAIL below, |
8 | | -// we test for != ACCEPT (in which ACCEPT has a value of zero). |
9 | | -// When compiling on a MSVC 2010 platform using cygwin's Flex and Bison, |
10 | | -// we note that the return value from parse() is not -1 but rather +1. |
11 | | -// It is more likely that on different platforms the return value of zero |
12 | | -// will be used consistantly to indicate an accept state. Whereas, the |
13 | | -// value of the abort or fail state will be more likely not to be a specific |
14 | | -// value but rather a value that is not equal to zero. |
15 | | - |
16 | | -#ifndef ACCEPT |
17 | | -#define ACCEPT 0 |
18 | | -#endif |
19 | | - |
20 | 7 | MC::MC_Driver::~MC_Driver(){ |
21 | | - delete(scanner); // wamckee 2013 APR 2 |
22 | | - delete(parser); // wamckee 2013 APR 2 |
| 8 | + delete(scanner); |
| 9 | + delete(parser); |
23 | 10 | } |
24 | 11 |
|
25 | | -void MC::MC_Driver::parse( const char *filename ){ |
| 12 | +void |
| 13 | +MC::MC_Driver::parse( const char *filename ) |
| 14 | +{ |
26 | 15 | assert( filename != nullptr ); |
27 | 16 | std::ifstream in_file( filename ); |
28 | 17 | if( ! in_file.good() ) exit( EXIT_FAILURE ); |
29 | 18 |
|
30 | | - delete(scanner); // wamckee 2013 APR 2 |
| 19 | + delete(scanner); |
| 20 | + scanner = nullptr; |
31 | 21 | scanner = new MC::MC_Scanner( &in_file ); |
32 | 22 | /* check to see if its initialized */ |
33 | 23 | assert( scanner != nullptr ); |
34 | 24 |
|
35 | | - delete(parser); // wamckee 2013 APR 2 |
| 25 | + delete(parser); |
| 26 | + parser = nullptr; |
36 | 27 | parser = new MC::MC_Parser( (*scanner) /* scanner */, |
37 | 28 | (*this) /* driver */ ); |
38 | 29 | assert( parser != nullptr ); |
39 | 30 |
|
40 | | - if(parser->parse() != ACCEPT) // wamckee 2013 APR 2 |
| 31 | + const int accept( 0 ); |
| 32 | + if( parser->parse() != accept ) |
41 | 33 | { |
42 | 34 | std::cerr << "Parse failed!!\n"; |
43 | 35 | } |
44 | 36 | } |
45 | 37 |
|
46 | | -void MC::MC_Driver::add_upper(){ uppercase++; chars++; words++; } |
| 38 | +void |
| 39 | +MC::MC_Driver::add_upper() |
| 40 | +{ |
| 41 | + uppercase++; |
| 42 | + chars++; |
| 43 | + words++; |
| 44 | +} |
47 | 45 |
|
48 | | -void MC::MC_Driver::add_lower(){ lowercase++; chars++; words++; } |
| 46 | +void |
| 47 | +MC::MC_Driver::add_lower() |
| 48 | +{ |
| 49 | + lowercase++; |
| 50 | + chars++; |
| 51 | + words++; |
| 52 | +} |
49 | 53 |
|
50 | | -void MC::MC_Driver::add_word( const std::string &c ){ |
| 54 | +void |
| 55 | +MC::MC_Driver::add_word( const std::string &c ) |
| 56 | +{ |
51 | 57 | words++; |
52 | 58 | chars += c.length(); |
53 | 59 | for(auto it(c.begin()); it != c.end(); ++it){ |
54 | | - if( islower( (*it) ) ) { lowercase++; } |
55 | | - else if ( isupper( (*it) ) ) { uppercase++; } |
| 60 | + if( islower( (*it) ) ) |
| 61 | + { |
| 62 | + lowercase++; |
| 63 | + } |
| 64 | + else if ( isupper( (*it) ) ) |
| 65 | + { |
| 66 | + uppercase++; |
| 67 | + } |
56 | 68 | } |
57 | 69 | } |
58 | 70 |
|
59 | | -void MC::MC_Driver::add_newline(){ lines++; chars++; } |
| 71 | +void |
| 72 | +MC::MC_Driver::add_newline() |
| 73 | +{ |
| 74 | + lines++; |
| 75 | + chars++; |
| 76 | +} |
60 | 77 |
|
61 | | -void MC::MC_Driver::add_char(){ chars++; } |
| 78 | +void |
| 79 | +MC::MC_Driver::add_char() |
| 80 | +{ |
| 81 | + chars++; |
| 82 | +} |
62 | 83 |
|
63 | 84 |
|
64 | | -std::ostream& MC::MC_Driver::print(std::ostream &stream){ |
| 85 | +std::ostream& |
| 86 | +MC::MC_Driver::print( std::ostream &stream ) |
| 87 | +{ |
65 | 88 | stream << "Uppercase: " << uppercase << "\n"; |
66 | 89 | stream << "Lowercase: " << lowercase << "\n"; |
67 | 90 | stream << "Lines: " << lines << "\n"; |
|
0 commit comments