Professional Documents
Culture Documents
Ministry of Higher Education & Scientific Research University of Baghdad Department of Computer Science
Ministry of Higher Education & Scientific Research University of Baghdad Department of Computer Science
Ministry of Higher Education & Scientific Research University of Baghdad Department of Computer Science
University of Baghdad
Department of Computer Science
In the above image we can see that S (a nonterminal) derives two non
terminals NP(nounPhrase) and VP(verbPhrase). In the case of NP, it has
derived two non terminals, Adj and Noun.
If you look at the grammar, NP could also have chosen Adj and
nounPhrase. While generating text, these choices are made randomly.
And finally the leaf nodes have terminals which are written in the bold
text. So if you move from left to right, you can see that a sentence is
formed.
METHODS AND APPLICATIONS
For example:
s -> a b
a -> 'the'
b -> c 'cat'
c -> 'happy'
c -> 'sad'
So “c” will be either ‘happy’ or ‘sad’ thus the result should be
the happy cat
the sad cat
RESULT AND CONCLUSIONS
A context-free grammar (CFG) consists of a set of
productions which allow one to replace a variable
by a string of variables and terminals.
The language of a grammar is the set of strings it
generates.
A language is context-free if there is a CFG for it.
Each string in the language has a leftmost derivation and a derivation
tree.
If these are unique for all strings, then the grammar is
called unambiguous.
REFERENCES
Freecodecamp.org
Google books
Shiffman.net
Wikipedia.org