Hi
I have a homework program to convert from postfix to infix, almost most of the functions are done but i can't make few functions to make the program run correctly
Please help me finishing the remaining functions
Here is the code
//-------------------------------------------------------------------------------------------------------
// NextToken.h
#ifndef NEXTTOKENH
#define NEXTTOKENH
#include <iostream>
using namespace std;
class NextToken
{
public:
NextToken( );
void next_token( );
void write_token( ) const;
void write_token( char ) const;
char get_token( ) const;
void match( char );
private:
char token;
};
inline NextToken::NextToken( )
{
next_token();
}
inline char NextToken::get_token( ) const
{
return token;
}
inline void NextToken::write_token( ) const
{
cout << " " << token;
}
inline void NextToken::write_token( char c ) const
{
cout << " " << c;
}
#endif
//---------------------------------------------------------------------------------------------------
// NextToken.ccp
#include <iostream>
#include "NextToken.h"
using namespace std;
void error( char, char * );
void NextToken::match( char et )
{
if ( et == token ) // expected token et matches current token ?
{
next_token(); // yes, read the next token
}
else // otherwise it is a syntax error
{
error( token, "match()" );
}
}
void NextToken::next_token( )
{
char c;
while ( cin.get( c ) ) // get the next char and store it in c
{
if ( c == ' ' )
{
; // ignore spaces
}
else
{
break; // found a non-blank input char
}
}
token = c; // remember the character token
}
//---------------------------------------------------------------------------------------------------------
// parser.ccp
#include <iostream>
#include <cstdlib>
#include <cctype>
#include "NextToken.h"
using namespace std;
void error ( char, char * );
void expr ( NextToken & );
void term ( NextToken & );
void factor ( NextToken & );
void moreterms ( NextToken & );
void morefactors( NextToken & );
int main()
{
NextToken nt; // next input token
expr( nt ); // handle expr()
nt.write_token( '\n' );
return 0;
}
// . . .
void error( char c, char *function )
{
cerr << "\nsyntax error: ";
cerr << "char is '" << c << "' in " << function << "\n";
cout << "\n";
exit( 1 );
}
And here is the assignment
Please use NextToken.h and NextToken.cpp from the examples in class.
Please use the grammar in the file grammar. Note that we have a few
more productions and some of the productions (like term) were modified.
Please modify parser.cpp that we used in class to accomodate the new or
modified productions.