SD05 - Grammars 1 Flashcards
What is a language?
A sequence of symbols
What is a grammar?
A formal description of a language - a set of rules which define what a valid sentence looks like
What is a parser?
A machine which takes a sentence in a language and determines whether or not it adheres to the grammar
What is the syntax of a language?
How sentences are formed, not what they mean
Why are FSAs not desirable for parsing languages?
They look at input strings one character at a time which is not a ‘natural’ way to think about languages. We tend to think in terms of words
What are the two elements of grammars?
Non-terminals (or productions): patterns to match
Terminals (or literals): symbols that actually appear in the input string
Is it possible to have a language which contains infinitely many sentences?
Yes The following grammar can be of infinite length if we keep substituting A for 0A1 A → 0 A 1 A → 0 B 0 B → *
What is the 4-tuple of a grammar?
G = (N, T, P, N0 ) Where: - N is a set of non-terminals - T is a set of terminals - P is a set of productions mapping non-terminals to a sequence of non-terminals and terminals - N0 is the initial non-terminal
What is a derivation?
A particular sequence of production applications that yields a string in the language (All symbols are terminals)
What is a context-free grammar?
A grammar where any production can be used regardless of where it is in the string
In a grammar, what does the ‘|’ symbol mean?
It separates two different expansions for the same non-terminal e.g.:
A -> 0A1 | 1
In a grammar, what does the ‘ε’ symbol mean?
It is the empty production, producing no output.
0ε1 = 01