Application Domains : Business Processing Scientific System Control Publishing

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 21

PPL

Application domains
Business Processing
Scientific
System Control
Publishing
Pragmatic Constraints in PL design
1. Architecture
VON-Neumann architecture, RISC,CISC etc

2. Technical Settings
Operating system, environment, System S\W

3. Standards
Standardization of any language is very time consuming
process. There are several organizations involved
in the process which give their comments and look
all the technical aspects.

4. Legacy system
A new developed must support the required functionality
of old version’s language.
Qualities
Simplicity & Readability
• Easy to write
• Should intelligible & easy to read by average
people
• Easy to learn & to teach
Clarity about binding
A language element bounded to the property at the
time property is defined for it.
Major binding times-
1. Language definition time
when the language is defined, basic data types
are bounded to a special tag called Reserved
words.
2. Language implementation time
When the compiler/interpreter for the language is written,
values are bound to machine representation.
e.g. size of int (C lang) determine at this level.

3. Program writing time-


Variable names are bounded to the types.

4. Compile time-
When programs are compiled, statements and
expressions are bounded to equivalent machine
instruction code.
5. Program Load time-
When Loader load machine code static variables are
assigned to fixed memory location and run time stack is
allocated to a block of memory.
6. Program run time-
Variables bound to the values at the run time.

Reliability-
Does the program behave the same way every times
it is run with the same input data?
Does it behave same way when it run on diff
platforms?
Support
Easily availability of compiler, documentation (manual)
and IDE . Any one should install it.
Orthogonality-
A language is said to be orthogonal if its statements &
features are built upon a small, mutually independent
set of primitive operation. More orthogonal a language,
fewer exceptional rules are needed for writing the
correct program.
(unit 2) Syntax
Form of a program called syntax and meaning of a program is
called semantics.

“The Syntax of a programming language is precise description of


all its grammatically correct programs.”

Syntax can be described by a set of rules, just as its in natural


language. For programming language a clear and precise
description is necessary; without such a specification, compiler
writers and programmer would not function well.
Lexical syntax- a language’s lexical syntax defines
the rules for basic symbol including identifiers,
literals, operators, and punctuations mark.

Concrete Syntax- it refers to the actual


representation of its program using lexical symbols
as its alphabet.

Abstract syntax- carries only the essential program


information without much concern of syntactical
grammar like punctuation or parenthesis.
Grammar-
The syntax of a grammar can be largely
specified using a formalism called a grammar.
A grammar is written in metalanguage
(language-description-language), and its
purpose is to define the all the legal strings of
character that can form a syntactically program.

Levels of grammar-
1- regular
2- context free
3- context sensitive
4- Unrestrictive.
Context free language- its has a set of production P, a set of
terminal symbol T, a set of non-terminal symbol N and Start symbol S.
One form of CFG called Backur Naur Form (BNF).

BNF-
A production is a rule for rewriting, that can be applied to a string of
symbols called a sentential form.
The nonterminal A can be replaced by w in sentential form.
Symbol A called left hand side and w is called right hand side of
production.

Eg.
BinaryDigit  0
BinaryDigit  1
This pair define that a binaryDigit either 0 or 1.
Non-terminal symbols are symbols that appear on the left hand side
of production and Terminal are the symbols that appear in the
production.
binaryDigit could be expressed in below form.
binaryDigit  0 | 1
BNF grammer Ginteger, which define the grammatical category
Integer as a sequence of decimal digits.
Integer  Digit | Integer Digit
Digit  0|1|2|3|4|5|6|7|8|9
Derivations.
Determine 352 is an Integer or not/
Develop the grammar for it-
1- 1st write down the strat symbol integer.
2- Replace the Integer with the string Integer Digit, which is the second
alternative of first production rules.
3- Substitute the Integer Digit for Integer, and produce the string Integer
Digit Digit.
4- substitute Digit for Integer, this time using the first alternative in the
first production rule.
5- Substitute 3 as a particular kind of Digit using the second production
rules.
6- Substitute the 5 for the next Digit in this string,
7- substitute the 2 for digit in this string.

Leftmost derivation vs Rightmost derivation???


Parse Tree-
Another way to describe the previous derivation in
graphical form, called Parse tree in which each
derivation step corresponds to a new subtree.
E.g.
Integer  Integer Digit.
Can be written as
Integer

Integer Digit
Ambiguous Grammar-
Specification that can be interpreted two or more different ways.
“A grammar is ambiguous if its language contains at least one string
with two distinct pares trees”
If ambiguity is exist, that can be resolved by establishing conventions
that rule out all but one parse tree for each string.

Eg. 1-0-1 has two parse tree, (1-0)-1 and 1-(0-1).

E - E

E E 1

1 0
Construct second parse tree…………………….(assign)
Dangling-Else Ambiguity-
If (x<0)
if (y<0) y=y-1;
else y=0;
Here grammar permits the else clause to be attached to either if.
Issue- which if the else should be attached?
How to resolve ?
Every else clause is associated with the textually closest preceding
unmatched if Statement. If a different attachment desired,
programmer must use {}.
CLite Grammer

Program → int main ( ) { Declarations


Statements }
Declarations → { Declaration }
Declaration → Type Identifier [ [ Integer ] ] {
, Identifier [ [ Integer ] ] }
Type → int | bool | float | char
Statements → { Statement }
Statement → ; | Block | Assignment
IfStatement | WhileStatement
Block → { Statements }
Assignment → Identifier [ [ Expression ] ] =
Expression ;
IfStatement → if ( Expression ) Statement
[ else Statement ]
WhileStatement → while ( Expression )
Statement
Expression → Conjunction { ||
Conjunction }
Conjunction → Equality { && Equality }
Equality → Relation [ EquOp Relation ]
EquOp → == | !=
Relation → Addition [ RelOp Addition ]
RelOp → < | <= | > | >=
Addition → Term { AddOp Term }
AddOp → + | -
Term → Factor { MulOp Factor }
MulOp → * | / | %
Factor → [ UnaryOp ] Primary
UnaryOp → - | !
Primary → Identifier [ [ Expression ] ] |
Literal | ( Expression ) |
Type ( Expression )
Identifier → Letter { Letter | Digit }
Letter → a | b | … | z | A | B | … | Z
Digit → 0 | 1 | … | 9
Literal → Integer | Boolean | Float | Char
Integer → Digit { Digit }
Boolean → true | false
Float → Integer . Integer
Char → ‘ ASCII Char ‘
Expression
Z=x+2*Y
Create a parse tree for this exp according
to the grammar of CLite.?????
Linking syntax and semantics-
. sometime non-terminal contain no useful information, so better to
remove them.
. Following transformation could be performed-
i. Discard all the separator terminal symbol, such as semicolon.
ii. Discard all the non-terminal which are trivial roots, that is, one
with only a single sub-tree.
iii. Finally replace the non-terminal with the operator which are a leaf
of one of their immediate subtree.

Result of above said separator called Abstract Syntax Tree.


The abstract tree have fewer intermediate nodes and sub-trees,
while it has same essential structure as the original expression.
Tree contain all the important information of the original parse
tree but is much smaller.

You might also like