[net.unix-wizards] YACC wizardry sought

cosell@BBN-UNIX@sri-unix (06/03/82)

From: Bernie Cosell <cosell@BBN-UNIX>
Date: 13 May 1982 11:42:29 EDT (Thursday)
I am trying to write a library routine that will parse a string and I'd like to
use YACC to express the grammar for the acceptable strings.  I am having a
problem that perhaps some wizard out there might be able to help me with:

I want to match the longest possible string.  That is, I want to snake along
the supplied string accepting as much as I can and have my parsing routine
not only set upa suitable structure with the results of the parse, but
have as its value a pointer to the first character in the string that didn't
match.  Here's is the best shot I've been able to come up with so far, and I'm
not even sure it works:
    when I get an error, have the `error' rule save the current text pointer
    and set to restart the parse at the beginning of the string, and then
    with a yyerrok and yyclearin, go and reparse.  my yylex routine will
    always be checking the current text pointer against the saved text
    pointer.  When the lex pointer reaches the saved pointer, yylex stops
    parsing and simply returns 0's.

any help or advice would be appreciated.

Thanks
   /Bernie