0

I'm trying to set up my parser to find the end of a certain parameter by recognizing that there isn't a comma, so I basically have it set up to find a parameter like this

parameter: end_parameter comma

(This data type is just a list, so there isn't anything to indicate it ends--just that it stops when there isn't a comma separating items)

And end_parameter is defined below and does what it's supposed to. The parser works with other data types by recognizing the right brace as the end, but I'm getting shift/reduce errors when I set up the type that is ended by a lack of a comma. Does anyone have any suggestions?

  • Show a bit more of your grammar, the rule *parameter: end_parameter comma* is probably not the source of your problem. – phlogratos Sep 13 '12 at 16:10
  • I guess my main question is how do you look for a lack of something? I need to look for a lack of a comma somehow – Elizabeth B Sep 13 '12 at 21:01
  • 1
    You can't look for a lack of something, because you never know whether something will follow later. This is similar to the *halting problem*, and it is proven that it is not decideable, see http://en.wikipedia.org/wiki/Halting_problem – phlogratos Sep 13 '12 at 21:06
  • Give more examples how your input (with probably missing pieces) will look like, and an example how you need the output, and you probably get an answer within minutes. Without that, it's just guessing. – Michael Oct 02 '12 at 17:45

1 Answers1

1

You recognize things by writing rules that match what they are, not what they are not. So for a parameter list separated by commas with no comma at the end, you would use:

parameter_list : parameter
               | parameter_list ',' parameter
               ;

Now depending on the context where you use this, and what other rules are used in the same context, you might get conflicts. If so, you need to look at the y.output file to see where the conflicts are coming from in order to resolve them.

You rarely get conflicts from a single rule -- conflicts generally come from the interaction of multiple rules.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226