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

    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
  • Good Essays

    Syntax

    • 268 Words
    • 2 Pages

    Syntax is the grammatical tool that deals with how sentences are put together and the relationship between words. It is a very methodical and logical sequence, ensuring that sentences are put together using subject, verb and object and that the words in the sentence all have agreement, so that the correct forms of words are used.…

    • 268 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
  • 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
  • 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
  • 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

    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

    Enter the correct answer for each item by typing A or B in the second column. Provide an explanation for each choice in the Rationale column. The boxes expand to accommodate the text.…

    • 453 Words
    • 2 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
  • Powerful Essays

    Basic Syntactic Notions

    • 6639 Words
    • 27 Pages

    The hypothesis of generative grammar is that language is a structure of the human mind. The goal of generative grammar is to make a complete model of this inner language (known as i-language). This model could be used to describe all human language and to predict the grammaticality of any given utterance (that is, to predict whether the utterance would sound correct to native speakers of the language). This approach to language was pioneered by Noam Comsky. Most generative theories (although not all of them) assume that syntax is based upon the constituent structure of sentences. Generative grammars are among the theories that focus primarily on the form of a sentence, rather than its communicative function.…

    • 6639 Words
    • 27 Pages
    Powerful 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

Related Topics