Preview

Context Free Grammars

Good Essays
Open Document
Open Document
2219 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Context Free Grammars
. . . . . . . . .

L E C T U R E

3

Context-Free Grammars
1 Where are Context-Free Grammars (CFGs) Used?
CFGs are a more powerful formalism than regular expressions. They are more powerful in the sense that whatever can be expressed using regular expressions can be expressed using grammars (short for context-free grammars here), but they can also express languages that do not have regular expressions. An example of such a language is the set of well-matched parenthesis. Grammars are used to express syntactic rules. These rules are used by the compiler to take a steam of tokens (the output from a scanner/lexical analyzer) and parse it for syntactic correctness, e.g. checking that each construct is well formed, all parentheses are matched, or all keywords are spelled correctly. This process is known as parsing.

2

Definitions
A context-free grammar G is a 4-tuple where N is a set of nonterminals, T is a set of terminals, P is a set of production rules of the form A→α, A is an element of set N, i.e. A∈ N, and α ∈ (N ∪ T)*, and S is a specific non-terminal called the start symbol. Sometimes, the set of terminals is also referred to as the alphabet. Recall that for a set of strings I, the notation I*, Kleene closure, refers to the set of all strings obtained by concatenation of zero or more elements taken from the set I in any order. For example, if I={a,b,A,B}, then the set I* is {ε, a, b, A, B, aa, bb, AA, BB, ab, ba, aA, Aa,aB, Ba, bA, Ab, bB, Bb,...} where ε is the empty string. Here are other definitions related to context-free grammars and languages: A derivation using the rule A→α is the process of obtaining a new string from a string w by replacing an occurrence of A in w with α. A sentence is a string consisting of only terminal symbols. A valid sentence with respect to grammar G is a sentence that can be derived using the production rules of G starting from S and ending with a sentence. A leftmost (rightmost) derivation is

Ramki Thurimella ©

You May Also Find These Documents Helpful

  • Powerful Essays

    you do after reading an essay assignment. Before you develop an argument on any topic,…

    • 2895 Words
    • 24 Pages
    Powerful Essays
  • Powerful Essays

    GRAMMAR: A system of rules in a language that enables us to communicate with and understand others.…

    • 1113 Words
    • 5 Pages
    Powerful Essays
  • Powerful Essays

    Ap Psychology Unit 6 Essay

    • 1319 Words
    • 6 Pages

    rules for deriving meaning in a given language. Syntax, also a part of grammar, is a set of…

    • 1319 Words
    • 6 Pages
    Powerful Essays
  • Good Essays

    13.1 Grammar

    • 1303 Words
    • 4 Pages

    Some employers provide on-site care for the children of their employees, yet other reimburses workers for daycare costs.…

    • 1303 Words
    • 4 Pages
    Good Essays
  • Powerful Essays

    -Grammar= knowledge of other rules beyond those governing relations between words like between elements inside words.…

    • 10440 Words
    • 42 Pages
    Powerful Essays
  • Good Essays

    Language Synthesis Essay

    • 325 Words
    • 2 Pages

    Language and how we communicate is an intricate system, made up of rules and processes that ultimately affect the delivery of meaning amongst a group of people (Fellowes & Oakley, 2014, p. 32). This system can be broken down into five areas that are; phonology, lexis, orthography, semantic and syntax (Gardener, 2017a). Therefore, as this system's taught, the development of language should evolve (Fellowes & Oakley, 2014). The syntax is an important area of this complex system and comprises of how people make meaning of words and how they are used to produce an unlimited number of sentences (Fromkin & Hyams, 2012, p. 98). Sentences are formed using words, clauses and phrases and syntax assists with these sentences to have meaning and sound accurate…

    • 325 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    HPE 2023 Grammar

    • 1227 Words
    • 5 Pages

    1) Please construct five (5) questions using YES/NO Information Question and five (5) Questions Word- when, where, who, why and how. The answers must be included as well.…

    • 1227 Words
    • 5 Pages
    Powerful Essays
  • Good Essays

    Gillette Case Study

    • 596 Words
    • 3 Pages

    Chester Allan, Gillette’s country manager of Indonesia, needs to decide whether increasing spending in marketing beyond 12% of sales will cause a 20-25% increase in blade sales in 1996. Despite the high market share of 48% and 97% brand awareness (See Exhibit 1) of Gillette-brand blades, the company needs to target several factors that hinder its growth by switching rural population to lower priced Gillette blades; targeting 48% of the urban male population that uses knives to start using blades; and increasing the productivity by improving the warehouses with new equipment and selecting better, more reliable distributors in order to eventually reduce expenses for the company.…

    • 596 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    An Overview of a Compiler

    • 1494 Words
    • 6 Pages

    LEX has a language for describing regular expressions It generates a pattern matcher for the REs described General structure of a LEX program {definitions} %% {rules} %% {user subroutines} A LEX compiler generates a C-program lex.yy.c as output…

    • 1494 Words
    • 6 Pages
    Powerful Essays
  • Satisfactory Essays

    Distinguish between the various translators. Explain why the compiler is called an n-pass compiler. What are lexicons? Differentiate between scanning and parsing. What are grammars?…

    • 283 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Compiler Construction

    • 376 Words
    • 3 Pages

    Compiler-a program that translates an executable program in one language into an executable program in another language…

    • 376 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Paper

    • 2134 Words
    • 9 Pages

    | |structure and usage of language. |structure and usage of language. |structure and usage of language. |…

    • 2134 Words
    • 9 Pages
    Satisfactory Essays
  • Satisfactory Essays

    English DBA NOTES

    • 373 Words
    • 2 Pages

    Syntax is the part of grammar that helps us make meaning from the way that words are arranged within a sentence.…

    • 373 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Grammar Basics

    • 6393 Words
    • 26 Pages

    Grammar, Meaning & Concision: In SC English? 2) Meaning: Is the meaning of the sentence obvious and…

    • 6393 Words
    • 26 Pages
    Good Essays
  • Good Essays

    Any language, whether natural or artificial has lexemes (symbols) and a grammar. Example : void, ;…

    • 291 Words
    • 2 Pages
    Good Essays

Related Topics