![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#41 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
What compiler are you using? If I've understood your problem correctly, the usual solution is to increase the look-ahead.
|
|
|
|
|
|
#42 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
maybe it does, i am too tired to think of a reason it would though anyway, how do i increase the look-ahead? As of now, the technique i am using is to start working on the token as soon as the scanner returns one. In other words, I have not stored the tokens anywhere preserving their order. do you see what i am saying? |
|
|
|
|
|
|
#43 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
i hope i made my q clear enough
![]() |
|
|
|
|
|
#44 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
I have another q
please take a look at the rule and its abstract syntax tree below: [HTML] <stmt-list> ::= <stmt-list> ; <stmt> ; / \ / \ / \ <stmt-list> <stmt>[/HTML] The abstract syntax tree is given by my prof. however, dont you think the abstract syntax tree looks flawed? let me illustrate with an example... suppose i have a program that goes like stmt1 ; stmt2 now the tree would be like [HTML] ; / \ / \ / \ <stmt2> <stmt1>[/HTML] but that looks flawed .... doesnt it? doesnt this make more sense: [HTML] ; / \ / \ / \ <stmt1> <stmt2> [/HTML] but then the above tree doesnt go with the ast given by my prof what to do ![]() |
|
|
|
|
|
#45 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
just help me solve the problem discussed in post # 40 ![]() |
|
|
|
|
|
|
#46 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
One way, which you have already mentioned, it to have the ability to put the tokens back into the stream.
Just have a an extra stack in your scanner that holds tokens that have been pushed back. Then when you need to look ahead, push back the tokens afterwards. |
|
|
|
|
|
#47 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
|
|
#48 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
Consider the rule and its ast below:
[HTML]<stmt-list> ::= <stmt-list> ; <stmt> ; / \ / \ / \ <stmt-list> <stmt>[/HTML] suppose i have a lot of stmt's separated by semicolons (meaning they perfectly satisfy the stmt-list rule also suppose that the tree is supposed to printed like this [node child1 child2] so shouldnt i expect a lot of semi-colons one after another? the reason i ask is because i dont see any semi colons next to each other in my printed ast, although there are a lot of stmt's separated by semicolons only i do see the same number of semicolons, but they are not right next to each other |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|