Hey, everyone,

Another tip that I think might be useful for grammar writing: if you’re treating spaces as separators between nonterminals, it’s a good idea to exclude spaces from appearing at the beginning and end of nonterminal definitions which are made up entirely of terminals. 

(Apologies for any formatting weirdness. I’m away from home and writing this on my phone.)

Usually, the easiest way to do this is to define a nonterminal which contains your text characters, but excludes spaces - e.g. 

-textchars : ([L];[“0”-“9”];[“,.?!’:;/-_”])+.

Then have a second nonterminal which is a sequence of these units, separated by your space character:

space : “ “+.
textblock : textchars++space.

If you do this, your <textblock> can’t start or end with a space character. You can then be sure that using a space as a separator before or after the <textblock> nonterminal in other rules isn’t going to cause ambiguity:

list : numbered++newline. 
numbered : [“0”-“9”]+, “.”, “ “*, textblock, “ “*.

If your <textblock> were instead

textblock : (“ “; [L];[“0”-“9”];[“,.?!’:;/-_”])+.

you’d have a potential ambiguity, as a space after the period in a <numbered> element might belong to the <numbered> itself, or to the <textblock>. 

BTW



****************************************************

Dr. Bethan Tovey-Walsh

LinguaCelta.com

LinkedIn 

Croeso i chi ysgrifennu ataf yn y Gymraeg


On 17 Jan 2025, at 14:24, Steven Pemberton <steven.pemberton@cwi.nl> wrote:

To keep track of how my implementation is doing, I check its logs every now and then, to see if it is failing anywhere, and to get a feel for what people are doing.

The most reoccurring beginner's error I see is not putting the top-level rule at the beginning of the grammar. (Also submitting pdf files instead of text files).

However, another mistake I see is testing a grammar for the first time on a huge input file. Typically the grammar is (immensely) ambiguous, and the huge input either takes an inordinate amount of time, and they think it has failed, or it runs out of memory and really does fail.

So advice: test your grammars on small amounts of input to smoke out the ambiguity errors, before running it on large input files.

 And if the author of the "hanayama" grammar is reading this, newline* should be newline+, and then you'll get some output. (And if you want more advice, feel free to contact me).

Steven