Feb 19, 2010 at 12:22am UTC
hii all ,
i have an assignment to implement scanner phase of some compiler based on some dfa.it should read from a file and output to a file..
i have a problem i made the function as
Token getToken(string str)
and then converts str to array of chars and it works well with individual words such as hi , for , if ...etc but when i enter
str ="int x ;"
it just considered the int and ignores the rest ..i don' know to figure the problem ..thx in advance:):)
Feb 19, 2010 at 12:30am UTC
Lexers are typically written so that they take characters from a stream (e.g. a FILE* or an std::istream), and each successive call returns a new token.
Feb 19, 2010 at 12:32am UTC
yes i know ..but in my code it takes the string before the first white space and ignores the rest :-s ..i don' know what 's the probelmm???
Feb 19, 2010 at 1:09am UTC
Is the string being set inside the function?
Feb 19, 2010 at 1:12am UTC
i don' understand what u mean sorry???!! but if u mean that i did that
getToken(string str)...so yes it gets the string and then i copy it to an array of chars to process it char by char..
Feb 19, 2010 at 1:15am UTC
It should ignore the rest.
Your argument should be either a string&
or a istream&
.
The point of tokenizing is to take a piece off of the input stream and return what it is.
So, given an input of int x;
getToken --> IntTypeToken, remaining input --> x;
getToken --> VariableToken "x", remaining input --> ;
getToken --> StatementTerminatorToken, remaining input -->
Hope this helps.
Feb 19, 2010 at 1:17am UTC
it supposes to,but realy the function i wrote doesn' do that ..it terminates after the first space .............it's massive function so i can't figure where that break comes from !!!