![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#31 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
thats why i followed the longer route |
|
|
|
|
|
|
#32 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
That sounds a bit harsh, if the spec calls itself, your program should be able to!
|
|
|
|
|
|
#33 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
let me give you an example though ... //<dec-list> ::= <dec> | <dec-list> ; <dec> item<string>* declist()
{
if (dec() == NULL) { return NULL;}
while (NT->theStruct.type == cma)
{NT = Si.cget();
if (dec() == NULL) {return NULL;}}
NT = Si.cget();
return NT;
} |
|
|
|
|
|
|
#34 |
|
Programmer
Join Date: Aug 2005
Location: Norway
Posts: 56
Rep Power: 0
![]() |
[EDIT] Shit, I was on the wrong site. Sorry! [/EDIT]
Delete this post, please.
__________________
Heh. |
|
|
|
|
|
#35 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
How about something like:
item<string>* procstmt()
{
while (true)
{
if (NT->theStruct.type != procedure)
{
if (compound()==NULL)
return NULL;
if (NT->theStruct.type != scln)
{
return NULL;
}
NT = Si.cget();
break;
}
else
{
NT = Si.cget();
if (proc()==NULL)
return NULL;
// Loop around again
}
}
return OK;
}Also in your last example: while (NT->theStruct.type == cma) while (NT->theStruct.type == scln) |
|
|
|
|
|
#36 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
|
|
#37 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
now, i have to create abstract syntax tree. how do i do that?
i mean i dont actually understand the concept i think for every single rule, the abstract syntax tree is given ... but I just do not know what they are talking about ... |
|
|
|
|
|
#38 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
Take the following expression: x = y + 1 =
/ \
x +
/ \
y 1From a data structure point of view, each node of the tree has a number of pointers to its children (and possible one to its parent). You can represent the node as a struct, or a class. |
|
|
|
|
|
|
#39 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
thanks arevos, i was just lacking confidence to actually implement the tree
|
|
|
|
|
|
#40 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
As you guys know, I am done with my parser that only validates a given expression. However I did a little bit of cheating with the rule of stmt:-
<stmt> ::= <assign> | <call> | <pread> | <pwriteln> | <compound> | <conditional> Now what I did was just take a look at the first token, and determine which funcion should be called. Here are the corresponding rules that clash though: <call> ::= <proc-name> ( <params> ) <assign> ::= $id := <exp> They would clash because both <proc-name> and $id require the first token to be $id. So I wouldnt know which function to call unless I take a look at the second token. However, if I do get the second token, then I can not call the respective functions (assign or call in this case) because it would mess thing up, if you know what i am talking about. I think the main problem is there is no way i can put the token back, so what i basically did is i didnt call the functions "call" and "assign", instead i just wrote them out like this: if (NT->theStruct.type==id)
{
NT = Si.cget(); if (NT->theStruct.type==asgn){ NT = Si.cget(); if (exp() == NULL) {return NULL;}}
else if (NT->theStruct.type==lp) {NT = Si.cget(); if (params() == NULL) { return NULL;} if (NT->theStruct.type != rp){return NULL;}NT = Si.cget();}
return NT;
}but that's cheating! isnt it? but what's the way out? ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|