On Sat, Mar 29, 2008 at 10:31 PM, Sampath Gadamsetty
<[EMAIL PROTECTED]> wrote:

>     I am trying to build a Parse Tree with the following grammar. I have 
> implemented my insertions using a standard binary tree inserting algorithm. 
> With the psuedocode below, can you guys provide any helpful feedback to 
> placing insert statements into building nodes of the tree.  Any suggestions 
> on how to build the tree will be appreciated.
>     I hope to build the tree to look like that
>      5+4

Have you looked into using lex and yacc, aka flex and bison, which are
open source equivalents?


>                  Goal
>                  |
>                   |
>                   |
>                  Expr
>                  |
>                  |
>                  Term
>                  |
>                 Factor
>                  |
>                   |
>                  +
>                  / \
>                 5   4
>
>   eprime()
>   /*Expr' -> + Term Expr' */
>   /* Expr' -> - Term Expr'*/
>
>   if(word = t or word = -) then
>   word <-NextWord()
>   if(Term()=false)
>           then return false;
>           else return Eprime();
>   /*Expr' -> Empty Set */
>   return true;
>
>
>   Term()
>   /*Term -> Factor Term'*/
>   if(factor()=false)
>   then return false
>   else return Tprime()
>
>
>   Tprime ()
>   /* Term' -> x factor Term' */
>   /*Term' -> / factor Term'*/
>   if (word = x or word = / )
>           Word=NextWord()
>   if(factor () = false)
>           then return false;
>           then return TPrime();
>   /*Term' -> Empty Set */
>   return True;
>
>
>   Factor()
>   /*Factor -> (Expr) */
>   if(word = '(' ) then
>           word<-Nextword();
>   if(Expr()-> false)
>           then return false
>   else if (word != ')') then
>           return false;
>   /*Factor ->Num*/
>   /*Factor->ident*/
>
>   else if(word!= Num and word != ident) then
>   report syntax error
>   return false;
>
>   word <- Nextword()
>   return true;
>
>   Main()
>   /* goal-> Expr */
>   Word <-Nextword()
>   if(expr() and word=eof)
>   then proceed to the next step
>   else return false
>
>   Expr()
>   /*Expr -> Term Expr' */
>   if(Term ()= false)
>   then return false
>   else return Eprime()
>
>
>
>  [Non-text portions of this message have been removed]
>
>
>  ------------------------------------
>
>  To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.Yahoo! 
> Groups Links
>
>
>
>



-- 
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
 If I were to divulge it, it would overturn the world."
 -- Jelaleddin Rumi

Reply via email to