1

I am using Gold Parser v5.2.

I attempting to slightly modify the Object Pascal Engine (by Rob van den Brink) so that it can parse .dpr and .dpk files as well as .pas files.

The garmmar file (named D7Grammar.grm, in the file downloaded from above link) passes Gold's analysis [Project | Analyze the Grammar] (with the modifications below) but fails with 'Project | Create LALR Parse tables'.

Modifications to 'D7Grammar.grm' file:

  1. Find definition for 'FloatLiteral' and rewrite it as this:

    FloatLiteral = {Digit} + '.' + {Digit} +
    
  2. Find '<UsesClause>' and rewrite it as this:

    <UsesClause> ::= USES <UnitList> ';'
     | SynError
    
  3. Add the following rules

    <UnitRef> ::= <RefID> !see http://stackoverflow.com/questions/35871440/
      | <RefID> IN 'StringLiteral'
      | <RefID> IN 'StringLiteral' Comment Start <RefID> Comment End
    
    <UnitList> ::= <UnitList> ',' <UnitRef>
      | <UnitRef>
    

Having done these, when I issue Project | Create LALR Parse tables' in Gold Parser, I get the following error.

')' can follow more than one completed rule. A Reduce-Reduce error is a caused when a grammar allows two or more rules to be reduced at the same time, for the same token. The grammar is ambigious. Please see the documentation for more information.

Further clicking around displays a table showing/hinting that 'FieldDesignator' and 'EnumId' are the culprits --as well as some more information I have no idea what they mean.

I am guessing this new ambiguity was looked over by older versions of Gold (since D7Grammar.grm had no issues then) but brought to surface by the new version.

Trouble is, other than doing trial-error (mostly copy/paste from random ideas or from other peoples suggestions) I am useless with grammar rules.

Hence, goes without saying, help is badly needed to get past this problem.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Adem
  • 265
  • 3
  • 10
  • 2
    If you guess the ambiguity is because of the new parser version, then I suggest confirming that guess by undoing your modifications and testing the original file first. – Rob Kennedy Mar 10 '16 at 18:23
  • What @RobKennedy says, test the original D7 grammar. Plus maybe the Uses clauses are a distraction from your q - none of them refer to '(', so what's the point in mentioning them? I confess that in view of the problems you've been having here and in comments to my answer on your previous q, I've been wondering how these problems went unnoticed previously - it's as if someone has been fiddling with the Gold library files which are up for downloading. – MartynA Mar 10 '16 at 21:39
  • Incidentally, I can understand why FieldDesignator and EnumId might yield a reduce/reduce conflict; both are satisfied by RefId. That is, once the parser recognizes that it has a RefId, there's no way for it to choose whether that RefId should reduce to a FieldDesignator or an EnumId. Bison lets you solve this type of problem by specifying precedence. Perhaps Gold offers something similar. (I'm not sure where the closing parenthesis comes into this, though.) – Rob Kennedy Mar 10 '16 at 22:01
  • Rob, I did run the original grammar with Gold 5.2 and, yes, it does have the same problems with 'FieldDesignator' and 'EnumId'. So, my additions (actually, they were Martyn's) didn't cause them. – Adem Mar 12 '16 at 06:10
  • I deleted everything Gold obejected to and then it did go on to produce an '.egt. file. Needless to say, the newly produced file turned out to be useless. I am more or less sure there's a bug in Gold, but pursuing it any further is beyond my reserves of effort. – Adem Mar 12 '16 at 07:28

0 Answers0