[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | David Allsopp <dra-news@m...> |
| Subject: | Fairly dumb ocamlyacc question |
This should be obvious, but I can't quite solve it!
If I use the following ocamlyacc script:
------------
%token BEFORE_KWD AFTER_KWD
%token FAILS_KWD
%token <int> WEEKDAY
%token <string> NAME
%type <unit> top
%start top
%%
top:
WEEKDAY AFTER_KWD NAME BEFORE_KWD NAME FAILS_KWD top {()}
| WEEKDAY relative NAME {()}
;
relative:
BEFORE_KWD {()}
| AFTER_KWD {()}
;
------------
Then I get a shift/reduce having parsed WEEKDAY AFTER_KWD... the parser
can't figure out what to do if it sees NAME. This problem can be made to
disappear by expanding the relative rules to give:
top:
WEEKDAY AFTER_KWD NAME BEFORE_KWD NAME FAILS_KWD top {()}
| WEEKDAY AFTER_KWD NAME {()}
| WEEKDAY BEFORE_KWD NAME {()}
;
I've tried a couple of tricks with %prec but can't get the parser to come
out the same way with the first rule... please could someone put me out of
my misery!!
Thanks,
David