I'm trying to compute the FIRST and FOLLOW sets of a CFG (using Python).
To do this I need to recognise terminals and non-terminals. I can (as a human) read them, but I was wondering if there was computational logic for inferring terminals and non-terminals, if one's given only the grammar.
It sounds like one'd need to construct the parse tree and then label terminals and non-terminals? A terminal is a node that has no childs.
One could also use the definition of "terminals" and "non-terminals":
Terminals
A terminal is a symbol which does not appear on the left-hand side of any production.
Nonterminals
Nonterminals are the non-leaf nodes in a parse tree.
Or perhaps non-terminals are also all of those that don't fit into the definition of terminals.