I want to extract expressions like <23.34 463.2 23.2 + *> in program runtime from the user.(You can see I am trying to evaluate postfix expression)
.
Very urgent please reply asap!
I want to extract expressions like <23.34 463.2 23.2 + *> in program runtime from the user.(You can see I am trying to evaluate postfix expression)
.
Very urgent please reply asap!
The trick is to have one token of lookahead. You read it, but you don't extract it from your stream. So you determine what sort of input - number, operator, whitespace, delimiter you are looking at based on the first token, and you process it later on.
Conventionally the functions are called gettoken() to look at a token without extracting it, and match() to remove it from the stream. Match takes the token type as an argument, and raises an error if it is wrong, which can happen if the user types something syntactically incorrect.
Your tokens could be characters, which case a number has to be built up of several tokens, or they could be numbers and operators, in which case you have a token for "Number". It depends if you want the complexity in making the tokens (the lexer) or in processing them (the parser).
Postfix is designed to be easy for a computer to evaluate once parsed, so this step should be quite easy.
Look at the MiniBasic material on my website or download the book, if you want to understand how parsers work more deeply.
Can I have the link to your website..
It should be in my sig.
If it doesn't appear, it;s Malcolm McLean's Homepage. Go to the MiniBasic webpages section, beneath the image of the book.
I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
Visit my website for lots of associated C programming resources.
https://github.com/MalcolmMcLean