A NOTE has been added to this issue. 
====================================================================== 
http://austingroupbugs.net/view.php?id=1269 
====================================================================== 
Reported By:                Clausecker
Assigned To:                
====================================================================== 
Project:                    1003.1(2016)/Issue7+TC2
Issue ID:                   1269
Category:                   Shell and Utilities
Type:                       Omission
Severity:                   Objection
Priority:                   normal
Status:                     New
Name:                       Robert Clausecker 
Organization:               Zuse Institute Berlin 
User Reference:              
Section:                    yacc 
Page Number:                3415, 3425–3426 
Line Number:                15000–15006, 115422–115425, 115447–115452 
Interp Status:              --- 
Final Accepted Text:         
====================================================================== 
Date Submitted:             2019-07-10 21:23 UTC
Last Modified:              2019-08-14 10:03 UTC
====================================================================== 
Summary:                    yacc: yychar is mentioned but not further specified
====================================================================== 

---------------------------------------------------------------------- 
 (0004518) Clausecker (reporter) - 2019-08-14 10:03
 http://austingroupbugs.net/view.php?id=1269#c4518 
---------------------------------------------------------------------- 
By request of Joerg, I'd like to clarify the intent of this report:

An LALR(1) parser as generated by yacc performs a lookahead of up to 1
character to determine the correct parse action.  Due to the way the parser
is constructed, such a lookahead token does not exist at all times.  The
parser needs to keep track if a lookahead token exists because that makes
the differences if a new token must be read before the current token can be
shifted.

Traditionally and in all yacc implementations I know, the lookahead token's
number is stored in yychar while its value is stored in yylval.  Two
special values with implementation-dependent values exist: one value to
indicate that the end of the input was reached and another one to indicate
that no lookahead token exists.  The symbolic constants YYEOF and YYEMPTY
are used by these two in yacc implementations by Robert Corbett (i.e. bison
and byacc); other implementations seem to have no symbolic constants for
these.

yacc provides one mean to modify the lookahead token: the macro yyclearin
discards the lookahead token.  Before discarding a lookahead token, it is
useful to know what the lookahead token is and whether it exists, otherwise
yyclearin may or may not discard a random token.  To do this, we can check
the value of yychar and compare it with the number for “no lookahead
token.”

This is possible in all yacc implementations known to me as they all work
the same: yychar and yylval hold the lookahead token with yychar holding a
special value (often -1 or -2 but I think I recall 0 being used, too) to
indicate no lookahead.  Since the state of the lookahead is only accounted
for through these two variables, actions can modify them arbitrarily.

It is however not possible to do this portably as there is no way to find
out what the number for “no lookahead” is.  This is why I am asking to
specify such a number, following the precedent in two popular yacc
implementations. 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2019-07-10 21:23 Clausecker     New Issue                                    
2019-07-10 21:23 Clausecker     Name                      => Robert Clausecker
2019-07-10 21:23 Clausecker     Organization              => Zuse Institute
Berlin
2019-07-10 21:23 Clausecker     Section                   => yacc            
2019-07-10 21:23 Clausecker     Page Number               => 3415, 3425–3426
2019-07-10 21:23 Clausecker     Line Number               => 15000–15006,
115422–115425, 115447–115452
2019-07-11 08:21 joerg          Note Added: 0004479                          
2019-07-11 09:33 Clausecker     Note Added: 0004480                          
2019-08-01 21:23 shware_systems Note Added: 0004505                          
2019-08-05 15:00 shware_systems Note Edited: 0004505                         
2019-08-14 10:03 Clausecker     Note Added: 0004518                          
======================================================================


Reply via email to