0% found this document useful (0 votes)
66 views20 pages

Formal Systems & Programming Languages: An Introduction

This document introduces formal systems and programming languages. It defines a formal system as an uninterpreted calculus consisting of an alphabet, set of words, and rules of inference. Formal systems are important for specifying syntax, syntax-directed compilation, compiler verification, and analyzing language complexity and structure. The document also describes formal grammars, which use productions to generate strings from a start symbol. Grammars are classified based on restrictions of productions into phrase-structured, context-sensitive, context-free, and regular grammars.

Uploaded by

Nishi Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views20 pages

Formal Systems & Programming Languages: An Introduction

This document introduces formal systems and programming languages. It defines a formal system as an uninterpreted calculus consisting of an alphabet, set of words, and rules of inference. Formal systems are important for specifying syntax, syntax-directed compilation, compiler verification, and analyzing language complexity and structure. The document also describes formal grammars, which use productions to generate strings from a start symbol. Grammars are classified based on restrictions of productions into phrase-structured, context-sensitive, context-free, and regular grammars.

Uploaded by

Nishi Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Formal Systems & Programming

Languages
An Introduction
Contents
Introduction to Formal Systems
Uses
Formal Specification
Formal Grammars
Types and Hierarchy of Languages
Examples
Formal System
Uninterpreted calculus
Logistic system
Consists of
◦ An alphabet
◦ Set of words (Axioms)
◦ Finite set of relations (Rules of Inference)
Examples
◦ Set Theory, Boolean Algebra, Proposition and
Predicate Calculus
Uses
Important in design, implementation and
study of programming languages
Used for
◦ Syntax – specification
◦ Syntax – directed compilation
◦ Compiler verification
◦ Complexity studies
◦ Analysis of structure of languages
Syntax Specification
Define the form of programming
language
Important both to
◦ User – needs clear description
◦ Implementer – problem of transferability &
maintenance
Exact specification of acceptable strings
of corresponding language
Syntax – Directed Compilers
Parse – recognize, find sequence of rules that generate the
string
Formal systems used as
◦ Database of syntactical rules of source language
Increasing no. of programming languages & machines –
automatic generation of compilers – formal definition of
both input & output language
Lsource, Lobject
Output of compiler generator – translator T: Lsource
-› Lobject
Similar problem – generating test-programs for validating
language processors
Complexity Structure Studies
Complexity of programming languages &
their compilers
Compiler writers & language designers
need to know
◦ Features of language – that increase
complexity of recognition phase
◦ Basis of evaluation of compiler performance
◦ Optimum level of performance
Structure Analysis
Used in attempt to prove
◦ Equivalence
◦ Validity of programs
Global optimization
Structure Analysis of Languages
Analysis & comparison of languages as of
◦ Basic language features
◦ Constructs & various combinations of
constructs available
◦ Categories of problems that can be programmed
◦ Cost/difficulty of writing a program

Basic features of language – formalization –


computer operations - machine design
Formal Specification
Approaching a formalism
◦ Problem and basis of defining a language
◦ Language – set of sentences – strings of symbols having
 Well-defined structure (syntax) &
 Meaning
◦ Unlimited number of valid sentences – impossible to be
stored as lists
◦ Problem of decidability
◦ Approaches of specification
 Generative specification
 Analytic specification
◦ Meta-language – formalism for language - definitions
Formal Specification - 2
Development of formal specification
◦ Using Syntactic-meta-language
◦ Object language & meta-language
 Symbols for object language – terminal symbols
 Symbols for meta language – nonterminal symbols
◦ Symbols are concatenated to form strings –
valid/invalid (for particular universe of
discourse)
◦ Alphabet & Language
Universe of Discourse
 Specifies the objects being discussed.
 Symbol – the most elementary objects
 Symbols concatenated to form strings
Alphabet
 Finite set of terminal symbols
 Formula or string – concatenation of these symbols
 T* - set of all possible finite concatenations of elements of T
 Λ – represents null or empty strings
Language
 Subset of set of finite concatenation of symbols in an alphabet T
 L ᄃ T*
 Groups of words – underlying structure connecting the words
Formal Grammar
Generative specification
Terminal symbols – symbols of alphabet
T
Non-terminal symbols – set N of symbols
not in T, that represents intermediate
states in the generation process
Start symbol – distinguished not terminal
symbol from which all strings of language
are derived
Formal Grammar - 2
Production – a string transformation rule
having
◦ LHS – pattern to match a substring of string to
be transformed
◦ RHS – indicates a replacement for the portion
of string
Any substring can be replaced by any
applicable production
Formal Grammar – definition
4 – tuple G = (N, T, ∑, P) where
◦ N – set of nonterminal symbols
◦ T – set of terminal symbols
◦ ∑ - starting symbol, ∑ € N
◦ P is the set of productions
Sentential Form and Sentences
Derivation of sentences
A sentential form is any string that can be
derived from the starting symbol ∑
A sentence is a sentential form containing
only terminal symbols
Hierarchy of Languages
Restrictionson the form of production –
various sub-classes of formal languages
Noam Chomsky gave four classes
◦ Phrase structured
◦ Context sensitive
◦ Context free
◦ Regular grammar
Phrase Structured Grammar
No restriction on productions
Elimination of symbols allowed
Intermediate strings can expand/contract
Type 0
Context Sensitive Grammars
Erasing of symbols not permitted
Left and right context present
Monotonic characteristics – length
increasing grammars
Type 1
Context Free Grammars
No context present
LHS has just one nonterminal symbol
Type 2
Recognized by Push-down Automata

Regular Grammar
Restrictionon number of terminals and
nonterminals generated at each step
Type 3
Recognized by Finite State Automata

You might also like