Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old May 27th, 2006, 5:15 PM   #21
mikaoj
Programmer
 
mikaoj's Avatar
 
Join Date: Aug 2005
Location: Norway
Posts: 56
Rep Power: 0 mikaoj is an unknown quantity at this point
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.
mikaoj is offline   Reply With Quote
Old May 27th, 2006, 5:27 PM   #22
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
Quote:
Originally Posted by mikaoj
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
suppose here is the text:
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
programmingnoob is offline   Reply With Quote
Old May 27th, 2006, 5:34 PM   #23
mikaoj
Programmer
 
mikaoj's Avatar
 
Join Date: Aug 2005
Location: Norway
Posts: 56
Rep Power: 0 mikaoj is an unknown quantity at this point
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.
mikaoj is offline   Reply With Quote
Old May 27th, 2006, 5:44 PM   #24
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
Quote:
Originally Posted by mikaoj
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
check your pm
programmingnoob is offline   Reply With Quote
Old May 27th, 2006, 8:31 PM   #25
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
Quote:
Originally Posted by The Dark
If the assignment is to write a parse, I am not sure that getting a program to generate one for you would be good enough.

You pretty much seem on track, programmingnoob. The parser takes tokens from the scanner and then processes them to see if there is a valid expression. IMO "Recursive Descent Parsers" are the easiest to write.
is the scanner supposed to preserve the order of the tokens?
programmingnoob is offline   Reply With Quote
Old May 27th, 2006, 10:02 PM   #26
Harakim
Hobbyist Programmer
 
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3 Harakim is on a distinguished road
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?
Harakim is offline   Reply With Quote
Old May 28th, 2006, 9:06 AM   #27
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 893
Rep Power: 4 The Dark is on a distinguished road
Quote:
Originally Posted by programmingnoob
is the scanner supposed to preserve the order of the tokens?
Yes, otherwise the parser won't be able to make any sense of the symbols.
The Dark is offline   Reply With Quote
Old May 28th, 2006, 10:43 PM   #28
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
Quote:
Originally Posted by The Dark
Yes, otherwise the parser won't be able to make any sense of the symbols.
exactly

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
programmingnoob is offline   Reply With Quote
Old Jul 11th, 2006, 3:10 AM   #29
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
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
programmingnoob is offline   Reply With Quote
Old Jul 11th, 2006, 3:19 AM   #30
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 893
Rep Power: 4 The Dark is on a distinguished road
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
	 }
The Dark 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:03 AM.

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