Null Production in grammar?

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Vincent Parrett
Version: 4.0.0253
Avatar
Hi

How do I specify a null production in a Nonterminal? For example :

'OpenBracket'
"ArgList"
'CloseBracket'
| 'OpenBracket'
'CloseBracket'
|
|
Note the empty | - if I use this then I get an error indicating I cannot have a null production. This sort of thing comes up a lot in languages like VBScript

Regards

Vincent.

Comments (6)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Correct me if I'm wrong but can't you just enclose the alternation with a [ ] block, which means optional? Then you don't need the null alternation option.


Actipro Software Support

Posted 12 years ago by Vincent Parrett
Avatar
I tried that, get an error complaining about an empty stack.

Regards

Vincent.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We'd have to debug it to see what was causing that. If you can, put together a simple grammar that shows this happening and email it over. Thanks!


Actipro Software Support

Posted 12 years ago by Vincent Parrett
Avatar
I was wrong about the error, something else must have caused it. With these non terminals

<NonTerminal Key="NL">
<Production>
<![CDATA[
'NewLine'
]]>
</Production>
</NonTerminal>
<NonTerminal Key="NLOpt">
<Production>
<![CDATA[
"NL"
| []
]]>
</Production>
</NonTerminal>

I get the error :

"No production data was located in the 'NLOpt' production near:
| []

Regards

Vincent.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Correct, an empty [] is not permitted. The [] must have contents. What you should be doing instead is make the production like this:
[ "NL" ]

That means NL is optional.


Actipro Software Support

Posted 12 years ago by Vincent Parrett
Avatar
Ah Yes, that makes sense, thanks. That parses fine and it looks like the code produced will work as expected.

Regards

Vincent.
The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.