infix to postfix string translation error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The virus
    New Member
    • Mar 2017
    • 1

    infix to postfix string translation error

    i am trying to convert a string from infix to postfix but not getting the desired output
    my code is as follows:

    #include<iostre am>
    #include<stdio. h>
    #include<conio. h>
    #include<ctype. h>
    using namespace std;
    int expr();
    int term();
    int match(int t);

    int lookahead=0;

    int expr()
    {
    term();
    while(true)
    {
    if(lookahead = '+')
    {
    match('+');
    term();
    putchar('+');
    }
    else if(lookahead = '-')
    {
    match('-');
    term();
    putchar('-');
    }
    else
    break;
    }
    }

    int term()
    {
    if( isdigit (lookahead))
    {

    cout<<lookahead ;
    match(lookahead );
    }
    else
    cout<<"syntax error";
    }

    int match(int t)
    {
    if(lookahead==t )
    lookahead=getch ar();
    else
    cout<<"syntax error";
    }

    int main()
    {

    cout<<"Enter an infix epression"<<end l;
    lookahead=getch ar();
    cout<<"postfix expression is :";
    expr();
    getch();
    return 0;
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    There are two places where you use = instead of == in comparing lookahead to a character.

    Comment

    Working...