Indirect Semantic Predicates #4333
Replies: 2 comments
-
Usually a parser is being targeted at a specific implementation language, unless it is an example grammar or a contributed grammar. Hence i think this does not come up so much for a real-world implementation. It is rare to need semantic predicates in ANTLR4, if the language itself is not severely ambiguous, then such a need often implies that the grammar needs work. Perhaps you could share the grammar as maybe there are ways to avoid the need in the first place. The other trick is that mostly a function call can be language agnostic. This does sound a little like an XY question as you have worded it. Seeing the grammar is probably the only way to help as the idea of a simple language for predicates comes up often and there is no appetite for it so far. |
Beta Was this translation helpful? Give feedback.
-
At this very moment, I am cleaning up the Antlr Python target and documentation. Part of that includes a discussion of target-agnostic grammars, which is exactly what you want. |
Beta Was this translation helpful? Give feedback.
-
A couple of times when we have been discussing possible changes to the grammar of Malloy, we have hit a wall when the change would require a semantic predicate, and we don't want to embed a particular parser implementation into the grammar files.
What if there was some way to insert an indirect-reference to a semantic predicate, and then, depending on the target language, different code was inserted into the generated parser?
We could do this ourselves with some sort of macro processor before we ran antlr, but maybe it could just be a feature of antlr. We can't be the only people with this problem, can we?
Thinking about this, this is something like the visitor pattern, except happening as the parse tree is constructed, not after.
Beta Was this translation helpful? Give feedback.
All reactions