Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > use streamtokenizer to implement lexical analyzer

Reply
Thread Tools

use streamtokenizer to implement lexical analyzer

 
 
Eric
Guest
Posts: n/a
 
      12-25-2003
Dear all:
I want to build a lex analyzer,
and streamtokenizer is seems a powerful API
but I have 2 question about it
1).how to use method slashSlashComments(boolean flag)
I try to set its flag as true,but it doesn't work when the comment
char be encountered. I also get a token that contains comments.
slashStarComments() has the same condition
2).I want to parse the java source code, and get the token
for example:
str1 = str2;
str1.compareTo("abc");
====================>use whitespace(' ','\t') and semicolon(';') to delimte
str1
=
str2
str1.compareTo("abc")
====================>but I want semicolon is also a token, like this
str1
=
str2
;
str1.compareTo("abc")
;

can only use streamtokenizer to implement this function?
thanks
Eric
 
Reply With Quote
 
 
 
 
Perica Milosevic
Guest
Posts: n/a
 
      12-26-2003
Eric wrote
> Dear all:
> I want to build a lex analyzer,
> and streamtokenizer is seems a powerful API
> but I have 2 question about it
> 1).how to use method slashSlashComments(boolean flag)
> I try to set its flag as true,but it doesn't work when the comment
> char be encountered. I also get a token that contains comments.
> slashStarComments() has the same condition
> 2).I want to parse the java source code, and get the token
> for example:
> str1 = str2;
> str1.compareTo("abc");
> ====================>use whitespace(' ','\t') and semicolon(';') to

delimte
> str1
> =
> str2
> str1.compareTo("abc")
> ====================>but I want semicolon is also a token, like this
> str1
> =
> str2
> ;
> str1.compareTo("abc")
> ;
>
> can only use streamtokenizer to implement this function?
> thanks
> Eric


Hello Eric,
Have you considered using StringTokenizer instead of StreamTokenizer.
It's constructor StringTokenizer(String str, String delim, boolean
returnDelims) allows you to choose whether to return the delimiters as
tokens or not. Just set the returnDelims flag to true.

Regards,
Perica
 
Reply With Quote
 
 
 
 
Eric
Guest
Posts: n/a
 
      12-26-2003
> Hello Eric,
> Have you considered using StringTokenizer instead of StreamTokenizer.
> It's constructor StringTokenizer(String str, String delim, boolean
> returnDelims) allows you to choose whether to return the delimiters as
> tokens or not. Just set the returnDelims flag to true.
>
> Regards,
> Perica



thanx for your suggestion
but, I want to parse the java program source code
the java code is so complex that I need powerful function to do this
job
1.I need more than one delimiter to get token once a time (e.g. '
','\t','\n')
2.comments in java code must ignore
3.white space char mention in 1. must ignore
4.some delimiter(';','{','}') must be reserve, and others must
discard(e.g. ' ','\t','\n')

StringTokenizer has not enough functionality for my requirement

StreamTokenizer is "almost" perfect, but can't return the delimiters
as tokens

any one can give more help?

Regards, Eric
 
Reply With Quote
 
nos
Guest
Posts: n/a
 
      12-26-2003

"Eric" <> wrote in message
news: om...
> > Hello Eric,
> > Have you considered using StringTokenizer instead of StreamTokenizer.
> > It's constructor StringTokenizer(String str, String delim, boolean
> > returnDelims) allows you to choose whether to return the delimiters as
> > tokens or not. Just set the returnDelims flag to true.
> >
> > Regards,
> > Perica

>
>
> thanx for your suggestion
> but, I want to parse the java program source code
> the java code is so complex that I need powerful function to do this
> job
> 1.I need more than one delimiter to get token once a time (e.g. '
> ','\t','\n')
> 2.comments in java code must ignore
> 3.white space char mention in 1. must ignore
> 4.some delimiter(';','{','}') must be reserve, and others must
> discard(e.g. ' ','\t','\n')
>
> StringTokenizer has not enough functionality for my requirement
>
> StreamTokenizer is "almost" perfect, but can't return the delimiters
> as tokens
>
> any one can give more help?
>
> Regards, Eric


it's not all that complicated to do yourself
go for it


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where find regexs needed to build lexical analyzer for Python sourcecode? Chris Seberino Python 1 09-12-2009 04:41 AM
lexical analyzer generators Jay G. Scott Perl Misc 2 06-01-2005 04:48 PM
StreamTokenizer (or ?) to use complex delimiters ATC Productions Java 3 05-28-2005 02:39 PM
Re: How does StreamTokenizer work John C. Bollinger Java 0 06-30-2003 04:48 PM
Re: How does StreamTokenizer work D. Lane Java 1 06-30-2003 06:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57