![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Programmer
Join Date: Aug 2005
Location: Norway
Posts: 56
Rep Power: 0
![]() |
It will check a token on the symbol table, and then next token, if this token is legal for what the previous token, it will look at next token. If it's not legal, it will report an error.
The tokens will be added straight forward, so: I am a boy Will be just added: I am a boy
__________________
Heh. |
|
|
|
|
|
#22 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
I am a boy the scanner will break it into I, am, a, boy tokens, right? but if you take a look at the link i copied pasted .. it says the parser does not start working until the scanner is finished working .... and after the scanner is finished working, you would have 4 tokens in the symbol table, right.... but how is the the parser supposed to know that they were received in the order of I am a boy... not in the order of am a boy I? do you see my doubt? I suspect I have a huge misunderstanding about either parser or scanner, coz this doesnt seem to be working in my head |
|
|
|
|
|
|
#23 |
|
Programmer
Join Date: Aug 2005
Location: Norway
Posts: 56
Rep Power: 0
![]() |
The scanner will break the source down to tokens, right.
While it's scanning, when one token is assembled, it will add it to the table, so it vill assemble next token, and so on. I have sent you a PM
__________________
Heh. |
|
|
|
|
|
#24 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
![]() |
|
|
|
|
|
|
#25 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
|
|
#26 |
|
Hobbyist Programmer
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3
![]() |
If you don't mind me asking, how do you know what you are compiling from and what you are compiling to? Are you making a general purpose compiler?
|
|
|
|
|
|
#27 | |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#28 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
but what if you pass the token to parser as soon as it is generated by the scanner? here's the pseudo-code given by my professor, which doesnt make much sense to me except they scan the text stream only when it's needed the code is for the function for the rule: <id-list> ::= $id | <id-list> , $id if NT->attr =! id, then return NULL. i = cons (NULL, NT, NULL); NT = Sc.get(); while (NT->attr == ,) do j = NT NT = Sc.get(); if NT->attr =!id, then return Null. cons (i, j, cons (NULL) NT, NULL); NT->attr =! id, then return NULL cons (i, j, cons (NULL, NT, NULL); NT = Sc.get(); return (i); NT means next token if you have any idea what i = cons... etc mean, please let me know |
|
|
|
|
|
|
#29 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
I'm having a hard time coding this particular rule for my yes/no parser ...
<proc/stmt> ::= <compound> ; | procedure <proc> <proc/stmt> Note: NT means Next Token item<string>* procstmt()
{
if (NT->theStruct.type != procedure)
{
if(compound()==NULL) return NULL;
if (NT->theStruct.type != scln){ return NULL;}
NT = Si.cget();
}
else{ NT = Si.cget();
y = proc();
if (y != NULL) {
while (y != NULL )
{if (NT->theStruct.type != procedure)
{if(compound() == NULL) return NULL;
if (NT->theStruct.type != scln){ return NULL;}
else return NT;}
else {NT = Si.cget();
y = proc(); }}}
else return NULL;
}
}i know i didnt make myself very clear .... it's really late, so i am gonna hit the sack ... i'll get up tomorrow and post more details if needed |
|
|
|
|
|
#30 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
Try something like:
tem<string>* procstmt()
{
if (NT->theStruct.type != procedure)
{
if(compound()==NULL) return NULL;
if (NT->theStruct.type != scln){ return NULL;}
NT = Si.cget();
}
else{ NT = Si.cget();
y = proc();
if (y != NULL) {
if (procstmt() == NULL)
return NULL;
}
else return NULL;
}
// Return something not NULL
} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|