parse tree help

U

uche

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

Ian Collins

uche wrote:

Please don't multi-post on Usenet.

comp.programming is possibly the best group for this question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,044
Members
48,769
Latest member
Clifft

Latest Threads

Top