Get allowed-next-tokens in yacc?

"R Faulds" <rfaulds@avici.com>
3 Mar 1998 10:38:10 -0500

          From comp.compilers

Related articles
Get allowed-next-tokens in yacc? rfaulds@avici.com (R Faulds) (1998-03-03)
Re: Get allowed-next-tokens in yacc? vitale@esat.kuleuven.ac.be (Maurizio Vitale) (1998-03-06)
Re: Get allowed-next-tokens in yacc? vladimir@cs.ualberta.ca (Vladimir Alexiev) (1998-03-07)
| List of all articles for this month |

From: "R Faulds" <rfaulds@avici.com>
Newsgroups: comp.compilers
Date: 3 Mar 1998 10:38:10 -0500
Organization: The Internet Access Company, Inc.
Keywords: yacc, question

Hello,


I'm using lex&yacc (MKS) to buid a command line parser. It works okay
but there are a few CLI features I can't figure out how to implement.


1) Is there a way (without hacking y.tab.c) to get the list of allowed
        tokens for some (any) point in the parse process?


        I'm looking to implement a context sensitive help where user may
        query (via special key) the next allowed keyword or the list of
        such allowed keywords (or fields) if it exists.


        e.g. For the commands SHOW INTERFACE <num>
                                                                                  SHOW INTERFACE ALL


        If the user presses the help-key...


                >show interface<help-key>


        I want the following output...


                >show interface


                Choose:
                                                <num> - numeric input required
                                                ALL - display all


2) When I'm parsing down a specific rule, how do I use error to localize
          the error handling?


        e.g. For the command...
|
SET INTERFACE ADDRESS num ip-addr
                        { setIfAddr($4,$5);
                        }
|


        The user types...
                >set interface address <CR>


        I'd like to have an error token (or other means) to trap the error
        at the rule's action code so I could issue "numeric required,
        choose an interface between [1..7]".


        Instead yacc just makes a default call to yyerror() "syntax error" and
        exits with an error.


        Any ideas?


Thanks,
-Rob
[Honestly, I wouldn't use yacc. Getting the actual list of allowed tokens
at each point is really hard due to the state and table compaction that
yacc does. And the error recovery is no prize-winner. -John]








--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.