[comp.lang.c] Info. needed on parsing expressions

jayneus@reliant.Berkeley.EDU (System Hacker) (03/26/89)

I need to parse a file which contains a set of arithmetic expressions
in normal format and build up an expression tree for use in my C program.
The tree need not be balanced.
For example, given the following expression in a file:-

x = a*b + c*(d + e);

The resulting tree would be:-
		 +
		/ \
               /   \
	      *     *
	    /  \    /\
           a    b  c  \
                       +
                       /\
                      d  e

Is there some utility package for doing this ?
Any information/help shall be greatly appreciated.

Thanks,
Arvind
EMAIL: sarvind@janus.Berkeley.EDU
--
----------------------------------------------------------------------------
"There is a certain power in mirth that only the jokers know"
EMAIL: jayneus@reliant.Berkeley.EDU
----------------------------------------------------------------------------

chris@mimsy.UUCP (Chris Torek) (03/26/89)

In article <JAYNEUS.89Mar25175939@reliant.Berkeley.EDU>
jayneus@reliant.Berkeley.EDU (System Hacker) writes:
>I need to parse a file which contains a set of arithmetic expressions
>in normal format and build up an expression tree for use in my C program.

This sounds very much like someone trying to get the net to do his
homework for him.

In any case, the simplest solution is to use yacc or bison.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris