Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 22nd, 2006, 5:46 AM   #41
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
What compiler are you using? If I've understood your problem correctly, the usual solution is to increase the look-ahead.
Arevos is offline   Reply With Quote
Old Jul 22nd, 2006, 6:11 AM   #42
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
Quote:
Originally Posted by Arevos
What compiler are you using? If I've understood your problem correctly, the usual solution is to increase the look-ahead.
i am using visual studio.net 2003 ... does it matter in this case?
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?
programmingnoob is offline   Reply With Quote
Old Jul 22nd, 2006, 9:50 PM   #43
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
i hope i made my q clear enough
programmingnoob is offline   Reply With Quote
Old Jul 22nd, 2006, 10:18 PM   #44
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
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
programmingnoob is offline   Reply With Quote
Old Jul 23rd, 2006, 6:33 AM   #45
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
Quote:
Originally Posted by programmingnoob
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
you can ignore post # 44, i got what i was doing wrong ...

just help me solve the problem discussed in post # 40
programmingnoob is offline   Reply With Quote
Old Jul 23rd, 2006, 8:50 PM   #46
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 893
Rep Power: 4 The Dark is on a distinguished road
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.
The Dark is offline   Reply With Quote
Old Jul 24th, 2006, 4:27 AM   #47
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
Quote:
Originally Posted by The Dark
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.
thanks i will look into that
programmingnoob is offline   Reply With Quote
Old Jul 24th, 2006, 4:28 AM   #48
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
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
programmingnoob is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC