0% found this document useful (0 votes)
35 views11 pages

Context-Free Grammars Programming Languages

The document discusses context-free grammars which are used to define programming languages. A context-free grammar consists of variables, terminals, production rules, and a start symbol. Production rules are used to derive strings by rewriting variables with strings of terminals and variables.

Uploaded by

Emmanuel Anceno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views11 pages

Context-Free Grammars Programming Languages

The document discusses context-free grammars which are used to define programming languages. A context-free grammar consists of variables, terminals, production rules, and a start symbol. Production rules are used to derive strings by rewriting variables with strings of terminals and variables.

Uploaded by

Emmanuel Anceno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Programming Languages

Context-Free Grammars

A context-free grammar basically consists of a finite set of grammar rules. In order to define grammar
rules, we assume that we have two kinds of symbols: the terminals, which are the symbols of the
alphabet underlying the languages under consideration, and the non-terminals, which behave like
variables ranging over strings of terminals. A rule is of the form A, where A is a single nonterminal, and
the right-hand side x is a string of terminal and/or nonterminal symbols. As usual, first we need to define
what the object is (a context free grammar), and then we need to explain how it is used. Unlike
automata, grammars are used to generate strings, rather than recognize things.

A context-free grammar G is a tuple G= (V,T,P,S) where:

1. V is the (finite) set of variables (or non-terminals or syntactic categories). Each variable
represents a language i.e., a set of strings
2. T is a finite set of terminals, i.e., the symbols that form the strings of the language being defined.
3. P is a set of production rules that represent the recursive definition of the language.
4. S is the start symbol that represents the language being defined. Other variables represent
auxiliary classes of strings that are used to help define the language of the start symbol.

3.1 Production Rules

The productions of a grammar are used to derive strings. In this process, the productions are used a
rewrite rules.

Each production rule consists of:

1. A variable that is being (partially) defined by the production. This variable is often called the
head of the production.
2. The production symbol --->.
3. A string zero or more terminals and variables. This string called the body of the prodcution,
represents one way to form strings in the language of the variable of the head.

In doing so, we leave terminals unchanged and substitute for each variable of the body any string that is
known to be in the language of that variable.

3.2 Derivations and Context Free Languages

Formally, we define the derivation relation associated with a context-free grammar. First, let us review
the concepts of transitive closure and reflexive and transitive closure of a binary relation.

You might also like