For example, given the grammar
Expr -> Number | Number '+' Expr
Number -> [1-9][0-9]*
we see that for + 1
there exists a sentence (e.g. 1 + 1
) which is parsed by the grammar and for which + 1
is sub-sentence. Is there a general algorithm for this? I think that if we can put some kind of flags in the parser we should be able to tell it to skip some initial and some final tokens while parsing but I'm not sure whether this would work. Any ideas?