I’m sure there’s a standard way to do this, but I don’t even know where to start searching for it.
How can i recognize, in any language, structures (grammars) in the form of, for example:
Exp ::= Number |(Exp) | Exp + Exp
Number ::= Number Digit | Digit
Digit ::= 0 | ... | 9
I mean, given a string like 32 + (43 + 23), how can I tell if it’s legal? Is there a standard algorithm or something? I don’t know what to search for, so I wasn’t able to search this site neither.
You are looking for parsing algorithm (membership algorithim). Parsing is the process of analyzing a string of language symbols in Formal Languages. And Yes for any context-free-grammar there is a possible parsing algorithm-that is Brute-Force a fundamental algorithm but inefficient, Like phrase-structure parsing, its worst-case complexity is O(n3) (you are to start from here) REFF1 . But if grammar is in standard (restricted) form then more efficient algorithm is possible. there are various parsing algorithms e.g. LL parser and LR parser..etc. REFFRENCE