Context free grammars (CFG) and languages (CFL):
Aims of this section: CFGs and CFLs are models of computation which define the syntax of hierarchical formal notations as utilized in programming or mark-up languages. Recursion is an essential characteristic which distinguish CFGs and CFLs from FAs and regular languages. Properties, weakness and strengths of CFLs. Equivalence of the CFGs and NPDAs. Non-equivalence of the deterministic and non-deterministic PDAs, Parsing and Context sensitive grammars CSG.Context free grammars and languages (CFG, CFL):
Algol 60 pioneered the CFGs and CFLs to state the syntax of programming languages (Backus-Naur Form).
Example: Arithmetic expression E, term T, factor F, primary P, a-op A = {+, -}, m-op M = {•, /}, exp-op = ^.
E -> T | EAT | AT, T -> F | TMF, F -> P | F^P, P -> unsigned number |variable| function designator | (E) [Notice the recursion: E ->* (E)]
Example of Recursive data structures and their traversals:
Binary tree T, leaf L, node N: T -> L | N T T (prefix) or T -> L | T N T (infix) or T -> L | T T N (suffix).
Such definitions can be turned directly to the recursive traversal procedures, example: procedure traverse (p: ptr); begin when p ≠ nil then start visit(p); traverse(p.left); traverse(p.right); end; end;
Df CFG: G = (V, A, P, S)
V: non-terminal symbols, “variables”; A: terminal symbols; S ∈ V: start symbol, “sentence”;P: set of productions or rewriting rules of the form X -> w, Here X ∈ V, w ∈ (V ∪ A)*
Rewriting the step: for u, v, x, y, y’, z ∈ (V ∪ A)*: u -> v if u = xyz, v = xy’z and y -> y’ ∈ P.
Derivation: “->*” is the transitive, reflexive closure of “->”, that is, u ->* v iff ∃ w0, w1, .. , wk with k ≥ 0 and u = w0, wj-1 -> wj, wk = v.
L(G) context free language produce by G: L(G) = {w ∈ A* | S ->* w}.
Example Symmetric structures: L = {0n 1n | n ≥ 0}, or even palindromes L0 = {w wreversed | w ∈ {0, 1}*}
G(L) = ({S}, {0, 1}, { S -> 0S1, S -> ε}, S); G(L0) = ({S}, {0, 1}, { S -> 0S0, S -> 1S1, S -> ε}, S)
Palindromes (length even or odd): L1 = {w | w = wreversed}. G(L1): add all the rules: S -> 0, S -> 1 to G(L0).
Ex Parenthesis expressions: V = {S}, T = {(, ), [, ] }, P = { S -> ε, S -> (S), S -> [S], S -> SS }
Sample derivation: S -> SS -> SSS ->* ()[S][ ] -> ()[SS][ ] ->* ()[()[ ]][ ]
The rule S -> SS builds this grammar ambiguous. The ambiguity is undesirable in practice, as the syntactic structure is usually employed to convey the semantic information.
Ambiguous structures in natural languages:
‘Time flies like an arrow’ versus. ‘Fruit flies like a banana’.
Bad news: There exist CFLs which are inherently ambiguous, that is each and every grammar for them is ambiguous. Furthermore, the problem of deciding whether the given CFG G is ambiguous or not, is not decidable.
Good news: For practical purposes it is simple to design the unambiguous CFG’s.
Exercise:
i) For Algol 60 grammar G (simple arithmetic expressions) above, describe the aim of the rule E -> AT and show illustrations of its use. Prove or disprove: G is unambiguous.
ii) Build an unambiguous grammar for the language of above parenthesis expressions.
iii) The ambiguity of ‘dangling else’. Some programming languages (example: Pascal) assign to nested if-then[-else] statements an ambiguous structure. This is then left to the semantics of language to disambiguate.
Let E represents Boolean expression, S statement, and let consider the 2 rules:
S -> if E then S, and S -> if E then S else S. Explain the trouble with this grammar and fix it.
iv) Provide a CFG for L = {0i 1j 2k | i = j or j = k}. Try to verify: L is inherently ambiguous.
Latest technology based Theory of Computation Online Tutoring Assistance
Tutors, at the www.tutorsglobe.com, take pledge to provide full satisfaction and assurance in Theory of Computation help via online tutoring. Students are getting 100% satisfaction by online tutors across the globe. Here you can get homework help for Theory of Computation, project ideas and tutorials. We provide email based Theory of Computation help. You can join us to ask queries 24x7 with live, experienced and qualified online tutors specialized in Theory of Computation. Through Online Tutoring, you would be able to complete your homework or assignments at your home. Tutors at the TutorsGlobe are committed to provide the best quality online tutoring assistance for Theory of Computation Homework help and assignment help services. They use their experience, as they have solved thousands of the Theory of Computation assignments, which may help you to solve your complex issues of Theory of Computation. TutorsGlobe assure for the best quality compliance to your homework. Compromise with quality is not in our dictionary. If we feel that we are not able to provide the homework help as per the deadline or given instruction by the student, we refund the money of the student without any delay.
Solubility Properties of Polymers tutorial all along with the key concepts of Solubility of gaseous substances, Rate of dissolution, Expressing solubility, Applications of solubility, Organic compounds and solubility, Solid solutions
theory and lecture notes of inverse functions all along with the key concepts of graph of inverse function, finding inverses informally and finding inverses formally. tutorsglobe offers homework help, assignment help and tutor’s assistance on inverse functions.
tutorsglobe.com principle of acceleration assignment help-homework help by online determinant of income and employment tutors
tutorsglobe.com energy needed by bacteria assignment help-homework help by online energy and enzymes tutors
systems development generally has two major components - systems analysis and systems design. systems design is the process of planning new business systems or replacing or complementing an existing system. define various distinct systems analysis methods.
Air Pollution tutorial all along with the key concepts of Air Pollution-Past, Present and Future, Major Air Pollutants-their sources, Ozone, Carbon monoxide, Airborne carcinogens, Hydrocarbons, Cigarette smoking
Benzopyridines tutorial all along with the key concepts of Quinoline, Skraup Synthesis, Friedlander Synthesis, Methylquinolines, Aminoquinolines, Conrad-Limpach-Knorr Synthesis, Isoquinoline, Bischler-Napieralski Synthesis and Pictet-Spengler Synthesis
www.tutorsglobe.com offers Decision Criteria homework help, assignment help, case study, writing homework help, online tutoring assistance by computer science tutors.
The chairman should attempt to make sure that the board operates like an effectual decision making body and that board meetings are conducted in a business-like manner.
Power Supplies tutorial all along with the key concepts of Alternating current power supply, Basic direct current power supply, Linear power supply, Switching power supply, Alternating Current input, Direct Current voltage
tutorsglobe.com isogamy and heterogamy assignment help-homework help by online algae tutors
Method of analysis of lipids tutorial all along with the key concepts of Physical properties of lipids, Chemical properties of lipids, Acid value, Iodine value, Functions of lipids, Analyses of lipids and Extraction of lipids
tutorsglobe.com foxpro assignment help-homework help by online computer programming tutors
Morphological and Genetic adaptations of Microorganism tutorial all along with the key concepts of Microbial adaptation to Marine and Freshwater Environments, Marine and freshwater environments, Polymerase Chain Reaction and temperature-stable DNA polymerase
Code division multiple access is abbreviated as CDMA is a channel access method used by several radio communication technologies.
1943331
Questions Asked
3689
Tutors
1492489
Questions Answered
Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!