Download presentation
Presentation is loading. Please wait.
1
Context Free Grammars-II
CSC312 Automata Theory Lecture # 27 Chapter # 12 by Cohen Context Free Grammars-II
2
Example: The following CFG generate all valid variable (identifier) names in ‘C’ language according to the following rules. The variable name can only start with alphabet or underscore there is no maximum length for the variable name after first character any alphabet, digit, underscore or $ can appear. S XY X alpha | _ Y alpha Y| digit Y | _Y | $Y | alpha A | B| C | … | Z | a | b | c | … | z digit 0 | 1 | 2 | … | 9
3
Note: Any ambiguous CFG for a regular language can be converted into un-ambiguous CFG by first finding out the language and then making DFA for that language. Then convert the DFA into CFG once again. The new CFG will be un-ambiguous as the DFA is always deterministic and un-ambiguous.
4
Trees Trees: The graphical representation of the derivation of a word is called syntax tree, parse tree, derivation tree, generation tree or production tree. Note:The syntax tree of a word should only contains leaf nodes i.e. only terminals should be at the end of the tree. Example: Consider the CFG S AA A AAA|bA|Ab|a The syntax tree to generate a word “babbaaa” is as follows
5
operator-operand-operand (o-o-o) prefix notation + 3 * 4 5
LUKASIEWICS Notation: (also known as Polish notation) operator-operand-operand (o-o-o) prefix notation + 3 * 4 5 operand-operand-operator (o-o-o) postfix notation * The expression * 5 is an infix arithmetic expression.
6
Total Language Tree: (TLT)
A total language tree is a tree with the start symbol S as its root and whose nodes are working strings of terminals and non-terminals. The descendents of each node are all possible results of applying every production to the working string. Examples: Practice Question: Q. 1, 2, 3, 5, 7, 8, 10, 15, 16, 17, 18, 19
Automata Theory December 2001 NPDAPart 3:. 2 NPDA example Example: a calculator for Reverse Polish expressions Infix expressions like: a + log((b + c)/d)
Erik Jonsson School of Engineering and Computer Science FEARLESS Engineering CS 4384 – 001 Automata Theory Thursday: Context-Free.
Lecture # 8 Chapter # 4: Syntax Analysis. Practice Context Free Grammars a) CFG generating alternating sequence of 0’s and 1’s b) CFG in which no consecutive.
Translator Architecture Code Generator ParserTokenizer string of characters (source code) string of tokens abstract program string of integers (object.
1 Introduction to Computability Theory Lecture5: Context Free Languages Prof. Amos Israeli.
1 Foundations of Software Design Lecture 23: Finite Automata and Context-Free Grammars Marti Hearst Fall 2002.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 4: Syntax Specification COMP 144 Programming Language Concepts Spring 2002 Felix.
Lecture 9UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 9.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Lecture # 19. Example Consider the following CFG ∑ = {a, b} Consider the following CFG ∑ = {a, b} 1. S aSa | bSb | a | b | Λ The above CFG generates.
LANGUAGE DESCRIPTION: SYNTACTIC STRUCTURE
Lecture # 9 Chap 4: Ambiguous Grammar. 2 Chomsky Hierarchy: Language Classification A grammar G is said to be – Regular if it is right linear where each.
CS 3240: Languages and Computation Context-Free Languages.
1 Syntax Specification (Sections ) CSCI 431 Programming Languages Fall 2003 A modification of slides developed by Felix Hernandez-Campos at UNC.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Context-free.
Context Free Grammars.
Lecture 11 Theory of AUTOMATA
Context Free Grammars CFGs –Add recursion to regular expressions Nested constructions –Notation expression identifier | number | - expression | ( expression.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
LESSON 04.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.