Re: What is a pragma?

> One snag in the rule suggested: if a pragma should not change the set of
> sentences recognized by a grammar, then doesn't a pragma meaning "reject
> input of length greater than n characters" fall on the wrong side of the
> line?  Unless the grammar would in any case reject all such sentences,
> in which case why the pragma?

When I wrote that suggestion, my idea was that one might know that only a string of a certain length could match. One could therefore check the string length before attempting to build the parse forest. Say I’m looking for UK geographic phone numbers. Each input is a sequence of digits (we’ll assume no parentheses or whitespace, for simplicity). A geographic phone number must have ten or eleven digits. So if the input string length is shorter than ten or longer than eleven, it can’t possibly match. In the case of such short inputs, it’s probably not worth pre-checking. But with larger inputs, you might save quite some time and effort by pre-checking that the input matches some basic criteria without which it cannot possibly be a valid sentence of the grammar. This avoids the expense of building partial parse forests when we can know in advance that there will not be a match. 

Of course, such a pragma could also be used as you outlined, to add additional constraints to the grammar. That would be non-conforming behaviour, which is not to say that it couldn’t be useful or reasonable in some contexts. 

Received on Sunday, 30 January 2022 12:54:58 UTC