Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!apple!usc!henry.jpl.nasa.gov!elroy.jpl.nasa.gov!peregrine!ccicpg!taurus!capone!ndjc From: ndjc@capone.UUCP (Nick Crossley) Newsgroups: comp.unix.questions Subject: Re: Any YACC / BISON gurus out there? Summary: You might be able to use YYBACKUP Keywords: yacc bison Message-ID: <278@capone.UUCP> Date: 27 Oct 89 00:37:37 GMT References: <1341@ssf> Reply-To: ndjc@ccicpg.UUCP (Nick Crossley) Organization: ICL NA, Irvine CA Lines: 24 In article <1341@ssf> richard@ssf.uucp (Richard Thombs) writes: >I need to be able to get YACC (or BISON if need be) to fail a parse when an >action tells it to. Some versions of yacc have a YYBACKUP macro in the parser skeleton. This allows limited backup, possibly not as much as you want. I have found it most useful to reduce the number of 'reserved words' in a grammar: rule : identifier { YYBACKUP(special($1)); } | token1 { ... } | token2 { ... } ... ; The lexer never returns 'token1', etc. The function 'special' examines the identifier and returns token1, etc., as appropriate. So token1, etc., are only recognised as keywords in the correct context; elsewhere, they are just identifiers. -- <<< standard disclaimers >>> Nick Crossley, ICL NA, 9801 Muirlands, Irvine, CA 92718-2521, USA 714-458-7282 uunet!ccicpg!ndjc / ndjc@ccicpg.UUCP