Re: Returning special EOF token when EOF found in scanner
Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]>
| Newsgroups | gmane.comp.lang.eiffel.gobo.general |
|---|---|
| Organization | Gobo |
| Message-ID | <[email protected]> |
Nicholas Allen wrote:
> I have a quick question though. I want to return my own token when EOF is
> matched in the scanner to my parser. The reason is that I gather up all the
> comments and add them to my own TOKEN object so that each token found also
> includes the comments that appeared immediately before it.
>
> So if I can pass my own special EOF token object back to my parser I can get
> the comments that appear at the end of the file. I tried this:
>
> <<EOF>> {
> terminate;
> last_token := EOF_TK;
> matched_token(create {TOKEN}.make(EOF_TK, line, column, line, column,
> comments));
> }
>
> But it seems the parser does not get this token.
In fact the parser might get this EOF_TK token, but it might
not receive the notification from the scanner that the end
of file has been reached.
> Any idea why or how I should be doing this instead?
I didn't try it, so it might not work, but here is a suggestion:
%x EOF_TOKEN
...
<INITIAL><<EOF>> {
last_token := EOF_TK
matched_token (create {TOKEN}.make(EOF_TK, line, column, line,
column, comments))
set_start_condition (EOF_TOKEN)
}
<EOF_TOKEN><<EOF>> {
set_start_condition (INITIAL)
terminate
}
--
Eric Bezault
mailto:ericb-D6Qt/9opevxWk0Htik3J/[email protected]
http://www.gobosoft.com
To Post a message, send it to: [email protected]
To Unsubscribe, send a blank message to: [email protected]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/gobo-eiffel/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/