[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Change to shift instead of reduce
From: |
Ron Burk |
Subject: |
Re: Change to shift instead of reduce |
Date: |
Mon, 3 Jun 2013 06:31:41 -0700 |
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
| '.'
| '$'
;
%%
Re: Change to shift instead of reduce,
Ron Burk <=