parse tree help



Hi Guys,
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

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()


.



Relevant Pages

  • Re: parse tree help
    ... I am trying to build a Parse Tree with the following grammar. ... implemented my insertions using a standard binary tree inserting ... else return Tprime() ... else return Eprime() ...
    (comp.programming)
  • parsing tree help
    ... I am trying to build a Parse Tree with the following grammar. ... implemented my insertions using a standard binary tree inserting ... else return Tprime() ... else return Eprime() ...
    (comp.lang.c)
  • Re: parsing tree help
    ... implemented my insertions using a standard binary tree inserting ... feedback to placing insert statements into building nodes of the tree. ... terms and factors are parse level concepts. ... typedef struct parsenode ...
    (comp.lang.c)