Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Standard view
Full view
of .
Add note
Save to My Library
Sync to mobile
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
MC0073 System Programming

MC0073 System Programming

Ratings: (0)|Views: 1,082|Likes:
Published by Ajay Dogney
MC0073 System Programming
MC0073 System Programming

More info:

Published by: Ajay Dogney on Aug 15, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, DOCX, TXT or read online from Scribd
See More
See less





ASSIGNMENT-11. Describe the following with respect to Language Specification:A) Programming Language Grammars B) Classification of GrammarsC) Binding and Binding Times
Ans:A) Programming Language GrammarsThe lexical and syntactic features of a programming language are specified by itsgrammar. This section discusses key concepts and notions from formal language grammars.A language L can be considered to be a collection of valid sentences. Each sentence can belooked upon as a sequence of words and each word as a sequence of letters or graphicsymbols acceptable in L. A language specified in this manner is known as & formallanguage. A formal language grammar is a set of rules which precisely specify the sentencesof L. It is clear that natural languages are not formal languages due to their rich vocabulary.However, PLs are formal languages.Terminal symbols, alphabet and stringsThe alphabet of L, denoted by the Greek symbol , is the collection of symbols in itscharacter set. We will use lower case letters a, b, c, etc. to denote symbols in . A symbol inthe alphabet is known as a terminal symbol (T) of L. The alphabet can be represented usingthe mathematical notation of a set, e.g. = {a, b,… z, 0, l,… 9}Here the symbols {, ‘,’ and} are part of the notation. We call them metasymbols todifferentiate them from terminal symbols. Throughout this discussion we assume thatmetasymbols are distinct from the terminal symbols. If this is not the case, i.e. if a terminalsymbol and a meta symbol are identical, we enclose the terminal symbol in quotes todifferentiate it from the meta symbol. For example, the set of punctuation symbols of Englishcan be defined as where ‘,’ denotes the terminal symbol ‘comma’.A string is a finite sequence of symbols. We will represent strings by Greek symbolsa, (α, ß, γ etc. Thus α = axy is a string over ∑. The length of a string is the number of symbols in it. Note that the absence of any symbol is also a string, the null string ε. Theconcatenation operation combines two strings into a single string. It is used to build larger strings from existing strings. Thus, given two strings α and ß, concatenation of α with ßyields a string which is formed by putting the sequence of symbols forming α before thesequence of symbols forming ß. For example, if α = ab, ß = axy, then concatenation of α andß, represented as α.ß or simply αß, gives the string abaxy. The null string can also participatein a concatenation, thus a.ε =ε.a = a. Nonterminal symbols
Page | 1
A nonterminal symbol (NT) is the name of a syntax category of a language, e.g.noun, verb, etc. An NT is written as a single capital letter, or as a name enclosed between<…>, e.g. A or < Noun >. During grammatical analysis, a nonterminal symbol represents aninstance of the category. Thus, < Noun > represents a noun.ProductionsA production, also called a rewriting rule, is a rule of the grammar. A production hasthe form A nonterminal symbol :: = String of Ts and NTs and defines the fact that the NT onthe LHS of the production can be rewritten as the string of Ts and NTs appearing on theRHS. When an NT can be written as one of many different strings, the symbol ‘|’ (standingfor ‘or’) is used to separate the strings on the RHS, e.g.< Article > ::- a | an | theThe string on the RHS of a production can be a concatenation of component strings,e.g. the production < Noun Phrase > ::= < Article >< Noun >expresses the fact that the noun phrase consists of an article followed by a noun.Each grammar G defines a language l
. G contains an NT called the distinguishedsymbol or the start NT of G. Unless otherwise specified, we use the symbol S as thedistinguished symbol of G. A valid string α of l
is obtained by using the following procedure1. Let α= ‘S’.2. While α is not a string of terminal symbols(a) Select an NT appearing in α, say X.(b) Replace X by a string appearing on the RHS of a production of X.ExampleGrammar (1.1) defines a language consisting of noun phrases in English< Noun Phrase > :: = < Article > < Noun >< Article > ::= a | an | the<Noun> ::= boy | apple< Noun Phrase > is the distinguished symbol of the grammar, the boy and an apple are somevalid strings in the language.Definition (Grammar)A grammar G of a language l
is a quadruple whereis the alphabet of L
, i.e. the set of Ts,SNT is the set of NTs,S is the distinguished symbol, andP is the set of productions.Derivation, reduction and parse treesA grammar G is used for two purposes, to generate valid strings of l
and to‘recognize’ valid strings of l
. The derivation operation helps to generate valid strings whilethe reduction operation helps to recognize valid strings. A parse tree is used to depict thesyntactic structure of a valid string as it emerges during a sequence of derivations or reductions.DerivationLet production pi of grammar G be of the form
Page | 2
***Aand let be a string such that ß = γAθ, then replacement of A by α in string constitutes aderivation according to production p
. We use the notation N Þη to denote direct derivationof η from N and N Þ η to denote transitive derivation of η (i.e. derivation in zero or moresteps) from N, respectively. Thus, A =>α only if A : = α is a production of G and A Þ δ if AÞ … Þ δ. We can use this notation to define a valid string according to a grammar G asfollows: δ is a valid string according to G only if S Þ δ, where S is the distinguished symbolof G.Example: Derivation of the string the boy according to grammar can be depicted as< Noun Phrase > => < Article > < Noun >=> the < Noun >=> the boyA string α such that S => α is a sentential form of l
. The string α is a sentence of l
if itconsists of only Ts.Example: Consider the grammar G< Sentence >::= < Noun Phrase > < Verb Phrase >< Noun Phrase >::= < Article >< Noun >< Verb Phrase >::= <verb> <Noun Phrase><Article> ::= = a | an | the< Noun >::= boy | apple<verb> ::= ateThe following strings are sentential forms of Lg< Noun Phrase > < Verb Phrase >the boy < Verb Phrase >< Noun Phrase > ate < Noun Phrase >the boy ate < Noun Phrase >the boy ate an appleHowever, only the boy ate an apple is a sentence.Reduction: To determine the validity of the stringExampleThe boy ate an appleaccording to grammar we perform the following reductions Step StringThe boy ate an apple1 < Article > boy ate an apple2 < Article > < Noun > ate an apple3 < Article > < Noun > < Verb > an apple4 < Article > < Noun > < Verb > < Article > apple5 < Article > < Noun > < Verb > < Article > < Noun >6 < Noun Phrase > < Verb > < Article > < Noun >7 < Noun Phrase > < Verb > < Noun Phrase >8 < Noun Phrase > < Verb Phrase >9 < Sentence >
Page | 3

Activity (12)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
acjit6 liked this
Gops Bisht liked this
Vishal Rajput liked this
Keshav Kumar liked this
Nikunj Gupta liked this
parmarb31 liked this
Manuj Kumar liked this
jitendrasain liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->