Thread: expression extraction

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    77

    expression extraction

    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!

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    505
    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.

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    77
    Can I have the link to your website..

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    505
    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


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. initializer expression list treated as compound expression
    By karthikeyanvisu in forum C Programming
    Replies: 7
    Last Post: 02-26-2011, 05:19 PM
  2. Replies: 2
    Last Post: 11-25-2009, 07:38 AM
  3. CSS extraction
    By anandganapati in forum C Programming
    Replies: 1
    Last Post: 04-29-2008, 11:26 PM
  4. extraction of the C/C++ help
    By altu99999 in forum C Programming
    Replies: 2
    Last Post: 09-19-2005, 12:56 PM
  5. extraction
    By Max in forum C Programming
    Replies: 13
    Last Post: 07-15-2002, 07:16 AM