0

I'm just starting to use antlr, with antlr for ruby. The version is 3.2.1

I'm trying to create a parser for the chef language, and the grammar is giving me a real headache :P I'm sure I'm missing some fundamental concept, but I just couldn't figure it out.

I created 3 grammars. The main one is the recipe parser, which (of course) parses the recipes. Once a recipe is parsed, I used the other 2 grammars, that parse ingredients and instructions (the method section).

My problem is with the last one, the one that parses the instructions, such as "put ... into the mixing bowl", "liquefy ...", etc. Everything works great except for a few rules. I've posted the Instructions.g source here, at paste.bin because of its length.

Here's what's happening:

  • When I uncomment the rules combine_ingredient_into_mixing_bowl or divide_ingredient_into_mixing_bowl, the parser stops recognizing almost all of the other rules (such as put_ingredient_into_mixing_bowl). This seems strange to me, because they don't seem to override each other (of course they are, somehow). I get the error: "line 0:-1 mismatched input "" expecting WS"

  • stir_mixing_bowl does not match anything, but it's really no different from the other rules that do work ok. I get the error: "line 0:-1 mismatched input "" expecting set nil"

  • Is it possible to include the rules verb_the_ingredient and liquefy_ingredient without making them conflict with the other rules? The former will actually conflict with everything else I guess, and the latter will conflict with liquefy_mixing_bowl. What would be the best way to deal with such a nasty grammar?

By the way, I haven't set the WS (whitespace such as space and tab) to the ignore channel because since an ingredient can consiste of one or more words (such as dijon mustard or just zuchinnis) I found that it is easier to specify the grammar by using the WS token as separators.

Also, running the antlr4ruby command to generate the parsers/lexers code shows no warnings at all.

Any tips, hints, or enlightening is really appreciated here :)

Thanks in advance.

marcelog
  • 7,062
  • 1
  • 33
  • 46
  • Why do you use 3 separate grammars instead of just 1 (by glancing over the language specs, it seems just 1 is doable...)? Could you post a small(er) grammar and provide some example input that throws the exceptions/errors you mention? Right now, it's rather hard to reproduce it. – Bart Kiers Aug 05 '12 at 19:45
  • Well, I couldn't do it with one actually. I'll update the question to include a smaller, concrete example (I did at first, but the question got a little too long) – marcelog Aug 05 '12 at 20:52

0 Answers0