Representing a finite unordered set in a formal grammar
Goal: find a way to formally define a grammar that recognizes elements
from a set 0 or 1 times in any order. Subsequently, I want to parse it and
generate an AST as well.
For example: Say the set of valid strings in my language is {A, B, C}. I
want to define a grammar that recognizes all valid permutations of any
number of those elements.
Syntactically valid strings would include:
(the empty string)
A,
B A, and
C A B
Syntactically invalid strings would include:
A A, and
B A C B
To be clear, defining all possible permutations explicitly in a CFG is
unacceptable for my purposes, since larger sets would be impossible to
maintain.
From what I understand, such a language fails the pumping lemma for
context free languages, so the solution will not be context free or
regular.
No comments:
Post a Comment