From: Zack Weinberg <zack@wolery.cumb.org>
To: gcc@gcc.gnu.org
Subject: confused by yyungetc() (cp/lex.c)
Date: Tue, 15 Aug 2000 16:48:00 -0000 [thread overview]
Message-ID: <20000815164839.A29496@wolery.cumb.org> (raw)
I'm presently trying to wean cp/lex.c off its dependency on text
streams so it can use the integrated preprocessor. I am severely
confused by yyungetc():
void
yyungetc (ch, rescan)
int ch;
int rescan;
{
/* Unget a character from the input stream. */
if (yychar == YYEMPTY || rescan == 0)
{
/* If we're putting back a brace, undo the change in indent_level
from the first time we saw it. */
if (ch == '{')
indent_level--;
else if (ch == '}')
indent_level++;
put_back (ch);
}
else
{
yychar = ch;
}
}
What it does is pretty straightforward: it puts a single-character
token back on the input so it will be reconsidered by yyparse. (It's
a hack around only having one lookahead token.)
What I don't understand is the choice between pushing the token back
into the lexer's stream and just setting yychar. In a very few cases
it's obvious, as when we're doing heroic error recovery by pushing
back *two* tokens - that looks like
yyungetc (':', 0);
yychar = ')';
-- here we have to put the colon somewhere other than yychar. In
almost all other cases, however, we are clobbering yychar if it is set
(yychar != YYEMPTY) and not using it if it isn't. There are a couple
of rules in cp/parse.y that call yyungetc with rescan=0 but don't
immediately set yychar, too.
zw
reply other threads:[~2000-08-15 16:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20000815164839.A29496@wolery.cumb.org \
--to=zack@wolery.cumb.org \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).