0
$\begingroup$

Lets say I have a grammar I know that E -> E + T | T can be solved like this: E -> T ( + T)*. But instead can I just determine the set of terminal symbols that can be derived from E and then have a parser:

    if peek(symbol_A):
       consume_next_token()
       parse_E->A()

this would also resolve recursion right?

$\endgroup$

1 Answer 1

0
$\begingroup$

The obvious bits: The grammar states what derivations are allowed. You need a parser that is clever enough to find a derivation if one exists, or determines that none exist, or determines that multiple derivations exist.

If this doesn't work with some grammar and a simple parser, then you can change the grammar or the parser. Changing the grammar has the disadvantage that you may not get the exact same derivation. So changing the parser and making it more clever will be the better way.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.