Infix, Postfix, Pseudo-Calculator using Stack ADT

This is a discussion on Infix, Postfix, Pseudo-Calculator using Stack ADT within the C Programming forums, part of the General Programming Boards category; basically, what i want to do is create a generic pseudo-calculator which takes a string containing a mathematical expression in ...

  1. #1
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117

    Talking Infix, Postfix, Pseudo-Calculator using Stack ADT

    basically, what i want to do is create a generic pseudo-calculator which takes a string containing a mathematical expression in standard or infix form, converts it to postfix form, convert the characters to respective int values, then perform the calculation, and finally output the result..

    i already have the code which converts infix to postfix using stack ADT, and the code to "calculate" the postfix using stack also...

    can anyone give me a pseudocode for the main function?? my main problem is converting the characters in the string to their respective mathematical tokens.

    thanks!!!
    It is not who I am inside but what I do that defines me.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You could always try the search button, since every few months some one posts nearly this same topic.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    Well, i tried searching and here's what i got: (using infix postfix keywords)

    Sorry - no matches. Please try some different terms.

    oh well, i guess i'll just wait till some1 takes pity on lil me...
    It is not who I am inside but what I do that defines me.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You're a liar.

    Searching with both infix and postfix gives you this (two pages of results).
    Searching with just infix gives you this (two pages of results).
    Searching with just postfix gives you this (three pages of results).

    I hate liars.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    Jeeze, you really have this habbit of calling people BAD names... i swear i searched and it came up with the result.... why dont you try searching for someting you're sure doesnt exist in this forum and i'll bet a million bucks that's the error message you'll get...

    hmm, i think i might have included a comma "," on my search or sumthin... tis funny...
    It is not who I am inside but what I do that defines me.

  6. #6
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    Anyway, thanks for the links and for calling me a liar...
    It is not who I am inside but what I do that defines me.

  7. #7
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    Hahaha! stupid me!!! i accidentally searched on the "Search this Thread" search field... dummy.. LOL
    It is not who I am inside but what I do that defines me.

  8. #8
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    If you Google "infix postfix conversion", this page is yielded as the top result. I used it when I wrote my calculator, and it was a wonderful resource. The Wikipedia article on Reverse Polish Notation also helped me a lot.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  9. #9
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I woulndn't conver to ints if I were you, unless you want to be inaccurate

  10. #10
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    If I were to be doing this, I'd add in builtin support for large numbers; maybe with GMP, though I could go homebrew if I wanted to. Ints are generally inadequate.

    You might want to look into finite state machines, lexer programs and tokenization in general to parse the expressions. For such a program the Shunting Yard algorithm to convert infix notation to postfix, coupled with Reverse Polish Notation, should be all you need, really; once you're done with the tokenization bit that is. Go search on Wikipedia; I'll bet you "a million bucks" you will find more than you ever need.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expression: Convert infix notation to postfix notation.
    By Nutshell in forum C Programming
    Replies: 7
    Last Post: 02-27-2010, 06:44 AM
  2. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  3. Replies: 4
    Last Post: 03-12-2006, 01:17 PM
  4. infix evaluation using stack
    By lewissi in forum C++ Programming
    Replies: 0
    Last Post: 11-03-2005, 01:56 AM
  5. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 05:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21