GOLD parser creator and terminals

304 views Asked by At

I am trying to create a grammar for a script language using the GOLD parser builder, since I want output in C#. However, the parser apparenntly wants the terminals to be unique. However, the meaning of a terminal can be context-sensitive?! Consider the symbol '-'. Both -x and x-y are valid and one could write a grammar as follows:

! -------------------------------------------------
! Terminals
! -------------------------------------------------
Opers = [+-*/]

! -------------------------------------------------
! Rules
! -------------------------------------------------

<Expression> ::= <Expression> <Operator> <Expression>
               | '-' <Expression>
               | <Value>
<Operator>   ::= Opers

However, now the symbol '-' is defined twice, once by the implicitely (!) defined symbol in the 2nd production rule of <Expression> and once as a terminal (defined by Opers).

On top of that, a string could contain the - symbol aswell, adding a third definition of '-' !? How do you circumvent this? I have not seen any information about this in the documentation of GOLD or anywhere on the web. I think there is some major way of working with Parser builders that I do not know.

If this is a issue that is not resolvable with a table-based parser, what alternatives do I have, since I want C# output?

1

There are 1 answers

1
almiien On

The error is because the -< EXPRESSION> is in conflict with the operator, put the minus into the value something like this:

< value> ::= int|'-'< value>