When almost everything is a legal parse, a parser generator begins
to fail to be a good match for the problem. When hand-written C is
clearer, better able to identify errors, and possibly even shorter
than the grammar equivalent, then I figure it's probably not a job
for a parser generator.

Personally, I would just handle this grammar with simple hand-written
code, or if it's a sub-grammar of something more complex
(where the rest of the grammar does not have such
strikingly high entropy) then just hand-code this portion
via actions. E.g.:

/* So, problem is really unpleasant grammar. E.g., he wants these all to
parse:

    .                                <- Token
    a.                               <- VarName Token
    a.b                              <- VarName
    .b                               <- Token VarName
*/

%token VAR
%start mainLoop

%%
mainLoop:
    atoms {/*process array*/}
    ;
atoms:
      atom            {/* init array, store first atom */ }
      | atoms atom    {/* add atom to array */}
    ;

atom:
      VAR
    | '.'
    | '$'
    ;

%%
_______________________________________________
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to