SlideShare una empresa de Scribd logo
1 de 25
Computers can perform many tasks. Given a task, two questions
arise.
The first is:
 Can it be carried out using a computer?
Once we know that this first question has an affirmative Answer,
we can ask the second question:
 How can the task be carried out?
Models of computation are used to help answer these questions.
 There are three types of structures used in models of computation,
namely, grammars, finite-state machines, and Turing machines.
 We will only focus on grammar structural because it will lead to us BNF
 Grammars are used to generate the words of a language and to
determine whether a word is in a language.
 Formal languages, which are generated by grammars, provide models
both for natural languages, such as English, and for programming
languages, such as Pascal, Fortran, Prolog, C, and Java. In particular,
grammars are extremely important in the construction and theory of
compilers.
Derivation of BNF:
 LANGUAGE AND GRAMMER
 Phrase-structure grammar
 Types of phrase-structure grammar
 Derivation Tree
 G:{V,T,N,S,P}
 Phrase structure grammar consists of a finite
set V: consisting of the vocabulary
 A finite set of T: Terminal symbols(cannot be
replaced)
 V-T = N: A set of non-Terminal symbols.
 A start position set S: starting
 And a finite set of P: Production rules.
 V*: The superset of V, consisting of the
language generated by V.
 Consists of finite set of grammar rules.
 Ambiguity occurs in CFG ( Context free grammar ).
 BNF is a CFG( Context Free Grammar ).
 A context-free grammar (CFG) G is a quadruple (V, Σ,
R, S) where
 V: a set of non-terminal symbols
 Σ: a set of terminals (V ∩ Σ = Ǿ)
 R: a set of rules (R: V → (V U Σ)*); left side always non-
terminal
 S: a start symbol.
 G=(V,T,N,S,P)
 V=(a, boy, sleeps, soundly, sentence, noun
phrase, verb phrase, article, noun, verb, adverb)
 T=(a, boy, sleeps, soundly)
 N=(sentence, noun phrase, verb
phrase, noun, verb, article, adverb)
 P=(<sentence> <noun phrase> <verb phrase>,
<noun phrase> <noun> <article>, <verb phrase>
<verb> <adverb>, <article> a, <noun> boy,
<verb> sleeps, <adverb> soundly).
 <sentence> = <noun phrase> <verb phrase>
= <article> <noun> < verb > <adverb>
= a <noun> <verb> <adverb>
= a boy <verb> <adverb>
= a boy sleeps < adverb>
= a boy sleeps soundly.
Sentence
noun phrase verb phrase
article noun verb adverb
a boy sleeps soundly
 It describes the syntactical hierarchy of a
grammars productions
 If ambiguity exists their can be more then one
parse trees
 Basically is a graphical representation.
 Backus-Naur notation (more commonly known as BNF or Backus-Naur Form) is a
Meta Language used to describe a language, which was developed by John
Backus (and possibly Peter Naur as well) to describe the syntax of the Algol60
programming language.
 It was primarily developed by John Backus ,but adopted and slightly improved by
Peter Naur for Algol60, which made it well-known. Because of this Naur calls BNF
Backus Normal Form, while everyone else calls it Backus-Naur Form.)
 It is used to formally define the grammar of a language, so that there is no
disagreement or ambiguity as to what is allowed and what is not. In fact, BNF is so
unambiguous that there is a lot of mathematical theory around these kinds of
grammars, and one can actually mechanically construct a parser for a language
given a BNF grammar for it. (There are some kinds of grammars for which this isn't
possible, but they can usually be transformed manually into ones that can be
used.)
 Programs that do this are commonly called "compiler compilers". The most famous
of these is YACC, but there are many more.
The Principles
BNF is sort of like a mathematical game: you start with a
Symbol and are then given rules for what you
can replace this symbol with. The language defined by the
BNF grammar is just the set of all strings you can produce
by following these rules.
 The rules are called production rules, and look like this:
 symbol := alternative1 | alternative2 ...
 Terminal symbols are literal symbols which may appear in the inputs to or outputs
from the production rules of a formal grammar and which cannot be changed
using the rules of the grammar (this is the reason for the name "terminal").
 For concreteness, consider a grammar defined by two rules:
 x can become xa
 x can become a
Here a is a terminal symbol because no rule exists which would
change it in to something else. (On the other hand, x has two rules
that can change it, thus it is nonterminal.) A formal language defined
(or generated) by a particular grammar is the set of strings that can be
produced by the grammar and that consist only of terminal symbols.
Nonterminal symbols are those symbols which
can be replaced. A formal grammar
includes a start symbol, a designated member of
the set of nonterminals.
e.g:
digit = “0”|"1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
So digit is non-terminal because it‟s value lies at any
range in 0 - 9.
What is an integer?
 An integer can be a single digit and so:
<integer> ::= <digit>
 However, what is a digit?
A digit is 0 or 1 or 2 or … or 9.
 <digit> ::= 0|1|2|3|4|5|6|7|8|9
 The vertical line is read as or.
 All integers of more than one digit start with a single digit and are
followed by an integer and the final integer is a single digit integer.
 An indefinitely long integer is defined as
› <integer> ::= <digit><integer>
 E.g. 147
› Is a single digit integer ( 1 ) followed by the integer 47.
› 47 is a single digit integer ( 4 ) followed by a single digit integer (
7 ).
SAMPLE CODE OF BNF
Int A=1+2/3;
Console.writeLine(“{0}”,A);
BNFC Code:
EAdd ( (Eint 1) (Ediv (Eint 2 ) (Eint 3) ) )
Echo (A)
EXPLANATION:
;EAdd == exp1 + exp2 (exp can be of any type of num)
;Eint == Exp is of type int
;Echo == prints the value
C# code :
Int a=5
Int i=1;
Int ans=0;
While(i!=10)
{
Ans=a*i;
Console.writline(“{0}”,ans);
i++;
}
BNF CODE:
Eint A ::= 5
EInt I ::= 1
EInt ans ::= 0
While ::= <i != 11>
<
Eint ans ::= Emul (Eint A )(Eint i)
Echo ans
Eint i ::= Eadd (Eint i + 1)
>
Note: In some cases a lexical analyzer with syntax and
semantic analyzer make up a Parser!!
 Scans the Code, breaks it
down into „Tokens‟:
 constants (integer, double,
char, string, etc.)
 Identifier(Variables)
 Operators
 Punctuation(separator)
 reserved words(keywords)
 Process is called
„Tokenization‟
 Syntax tells of the valid
form of the program
 Described via CFG
 Determines whether a
statement is valid and
can be produced via
the production rules.
 Semantic tell of the
behavior of the
program.
 Two types:
 Static semantic
check(compile time
error checking).
Example: using
undeclared variables,
type checking.
 Dynamic semantic
check(run time error
checking). Example:
Array out of bounds,
division by zero
 BNF = Backus-Naur Form (also known as Context-Free Grammars).
 BNF is the standard format for
the specification and documentation of programming languages.
 BNFC makes BNF usable for implementation as well.
 BNFC is a high-level front end to traditional implementation formats
(in the style of Lex and YACC): "BNFC is a compiler compiler"
 BNFC saves 90% of source code writing in a typical compiler front
end.
 BNFC can be used for projects carried out in C, C++, C#, F#, Haskell,
Java, OCaml.
 Strongest case: when designing and implementing a new
programming language
 rapid development(can build on a previous language)
 guaranteed consistency of components
 freedom to change implementation of language(change
its grammar)
 ANSI C and Java have been implemented
but some languages have rough corners (e.g. Haskell)
 Q) What is computational model?
 Q)Description of Language and Grammar?
 Q)What is Parse-Structure grammar?
 Q)What is Context free Grammar?
 Q)Define BNF; who were main contributors to its
development?
 Q)BNF Model: Compiler. Explain?

Más contenido relacionado

La actualidad más candente

Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyserArchana Gopinath
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptApoorv Diwan
 
Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternBharat Rathore
 
Syntax analyzer
Syntax analyzerSyntax analyzer
Syntax analyzerahmed51236
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design MAHASREEM
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer ImplementationAkhil Kaushik
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.pptRatnakar Mikkili
 
LVEE 2014: Text parsing with Python and PLY
LVEE 2014: Text parsing with Python and PLYLVEE 2014: Text parsing with Python and PLY
LVEE 2014: Text parsing with Python and PLYdmbaturin
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical AnalyzerArchana Gopinath
 
Lecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptxLecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptxIffat Anjum
 
Interview questions
Interview questionsInterview questions
Interview questionsmaverick2203
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysisraosir123
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical AnalysisNayemid4676
 
Compiler Designs
Compiler DesignsCompiler Designs
Compiler Designswasim liam
 

La actualidad más candente (20)

Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyser
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
 
Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & Pattern
 
Syntax analyzer
Syntax analyzerSyntax analyzer
Syntax analyzer
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Lecture3 lexical analysis
Lecture3 lexical analysisLecture3 lexical analysis
Lecture3 lexical analysis
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer Implementation
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
LVEE 2014: Text parsing with Python and PLY
LVEE 2014: Text parsing with Python and PLYLVEE 2014: Text parsing with Python and PLY
LVEE 2014: Text parsing with Python and PLY
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
Lecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptxLecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptx
 
Lexical
LexicalLexical
Lexical
 
Interview questions
Interview questionsInterview questions
Interview questions
 
C++
C++C++
C++
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Compiler Designs
Compiler DesignsCompiler Designs
Compiler Designs
 

Similar a Computational model language and grammar bnf

Similar a Computational model language and grammar bnf (20)

match the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdfmatch the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdf
 
CH 2.pptx
CH 2.pptxCH 2.pptx
CH 2.pptx
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materials
 
Pcd question bank
Pcd question bank Pcd question bank
Pcd question bank
 
Syntax
SyntaxSyntax
Syntax
 
Unit-1 PPL PPTvvhvmmmmmmmmmmmmmmmmmmmmmm
Unit-1 PPL PPTvvhvmmmmmmmmmmmmmmmmmmmmmmUnit-1 PPL PPTvvhvmmmmmmmmmmmmmmmmmmmmmm
Unit-1 PPL PPTvvhvmmmmmmmmmmmmmmmmmmmmmm
 
Parser
ParserParser
Parser
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
 
role of lexical anaysis
role of lexical anaysisrole of lexical anaysis
role of lexical anaysis
 
Parsing
ParsingParsing
Parsing
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
Structure of the compiler
Structure of the compilerStructure of the compiler
Structure of the compiler
 
3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf3a. Context Free Grammar.pdf
3a. Context Free Grammar.pdf
 
6. describing syntax and semantics
6. describing syntax and semantics6. describing syntax and semantics
6. describing syntax and semantics
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
 
Lexical1
Lexical1Lexical1
Lexical1
 
Ch3_Syntax Analysis.pptx
Ch3_Syntax Analysis.pptxCh3_Syntax Analysis.pptx
Ch3_Syntax Analysis.pptx
 
01.ppt
01.ppt01.ppt
01.ppt
 

Último

Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxgindu3009
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhousejana861314
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxUmerFayaz5
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxAleenaTreesaSaji
 
Types of different blotting techniques.pptx
Types of different blotting techniques.pptxTypes of different blotting techniques.pptx
Types of different blotting techniques.pptxkhadijarafiq2012
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsSérgio Sacani
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptxanandsmhk
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...Sérgio Sacani
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...Sérgio Sacani
 
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡anilsa9823
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |aasikanpl
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real timeSatoshi NAKAHIRA
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...jana861314
 
Cultivation of KODO MILLET . made by Ghanshyam pptx
Cultivation of KODO MILLET . made by Ghanshyam pptxCultivation of KODO MILLET . made by Ghanshyam pptx
Cultivation of KODO MILLET . made by Ghanshyam pptxpradhanghanshyam7136
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsAArockiyaNisha
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​kaibalyasahoo82800
 
G9 Science Q4- Week 1-2 Projectile Motion.ppt
G9 Science Q4- Week 1-2 Projectile Motion.pptG9 Science Q4- Week 1-2 Projectile Motion.ppt
G9 Science Q4- Week 1-2 Projectile Motion.pptMAESTRELLAMesa2
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfnehabiju2046
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bSérgio Sacani
 

Último (20)

Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhouse
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptx
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptx
 
Types of different blotting techniques.pptx
Types of different blotting techniques.pptxTypes of different blotting techniques.pptx
Types of different blotting techniques.pptx
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
 
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real time
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
 
Cultivation of KODO MILLET . made by Ghanshyam pptx
Cultivation of KODO MILLET . made by Ghanshyam pptxCultivation of KODO MILLET . made by Ghanshyam pptx
Cultivation of KODO MILLET . made by Ghanshyam pptx
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based Nanomaterials
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​
 
G9 Science Q4- Week 1-2 Projectile Motion.ppt
G9 Science Q4- Week 1-2 Projectile Motion.pptG9 Science Q4- Week 1-2 Projectile Motion.ppt
G9 Science Q4- Week 1-2 Projectile Motion.ppt
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdf
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 

Computational model language and grammar bnf

  • 1.
  • 2. Computers can perform many tasks. Given a task, two questions arise. The first is:  Can it be carried out using a computer? Once we know that this first question has an affirmative Answer, we can ask the second question:  How can the task be carried out? Models of computation are used to help answer these questions.
  • 3.  There are three types of structures used in models of computation, namely, grammars, finite-state machines, and Turing machines.  We will only focus on grammar structural because it will lead to us BNF  Grammars are used to generate the words of a language and to determine whether a word is in a language.  Formal languages, which are generated by grammars, provide models both for natural languages, such as English, and for programming languages, such as Pascal, Fortran, Prolog, C, and Java. In particular, grammars are extremely important in the construction and theory of compilers.
  • 4. Derivation of BNF:  LANGUAGE AND GRAMMER  Phrase-structure grammar  Types of phrase-structure grammar  Derivation Tree
  • 5.  G:{V,T,N,S,P}  Phrase structure grammar consists of a finite set V: consisting of the vocabulary  A finite set of T: Terminal symbols(cannot be replaced)  V-T = N: A set of non-Terminal symbols.  A start position set S: starting  And a finite set of P: Production rules.  V*: The superset of V, consisting of the language generated by V.
  • 6.
  • 7.  Consists of finite set of grammar rules.  Ambiguity occurs in CFG ( Context free grammar ).  BNF is a CFG( Context Free Grammar ).  A context-free grammar (CFG) G is a quadruple (V, Σ, R, S) where  V: a set of non-terminal symbols  Σ: a set of terminals (V ∩ Σ = Ǿ)  R: a set of rules (R: V → (V U Σ)*); left side always non- terminal  S: a start symbol.
  • 8.  G=(V,T,N,S,P)  V=(a, boy, sleeps, soundly, sentence, noun phrase, verb phrase, article, noun, verb, adverb)  T=(a, boy, sleeps, soundly)  N=(sentence, noun phrase, verb phrase, noun, verb, article, adverb)  P=(<sentence> <noun phrase> <verb phrase>, <noun phrase> <noun> <article>, <verb phrase> <verb> <adverb>, <article> a, <noun> boy, <verb> sleeps, <adverb> soundly).
  • 9.  <sentence> = <noun phrase> <verb phrase> = <article> <noun> < verb > <adverb> = a <noun> <verb> <adverb> = a boy <verb> <adverb> = a boy sleeps < adverb> = a boy sleeps soundly.
  • 10. Sentence noun phrase verb phrase article noun verb adverb a boy sleeps soundly
  • 11.  It describes the syntactical hierarchy of a grammars productions  If ambiguity exists their can be more then one parse trees  Basically is a graphical representation.
  • 12.  Backus-Naur notation (more commonly known as BNF or Backus-Naur Form) is a Meta Language used to describe a language, which was developed by John Backus (and possibly Peter Naur as well) to describe the syntax of the Algol60 programming language.  It was primarily developed by John Backus ,but adopted and slightly improved by Peter Naur for Algol60, which made it well-known. Because of this Naur calls BNF Backus Normal Form, while everyone else calls it Backus-Naur Form.)  It is used to formally define the grammar of a language, so that there is no disagreement or ambiguity as to what is allowed and what is not. In fact, BNF is so unambiguous that there is a lot of mathematical theory around these kinds of grammars, and one can actually mechanically construct a parser for a language given a BNF grammar for it. (There are some kinds of grammars for which this isn't possible, but they can usually be transformed manually into ones that can be used.)  Programs that do this are commonly called "compiler compilers". The most famous of these is YACC, but there are many more.
  • 13. The Principles BNF is sort of like a mathematical game: you start with a Symbol and are then given rules for what you can replace this symbol with. The language defined by the BNF grammar is just the set of all strings you can produce by following these rules.  The rules are called production rules, and look like this:  symbol := alternative1 | alternative2 ...
  • 14.  Terminal symbols are literal symbols which may appear in the inputs to or outputs from the production rules of a formal grammar and which cannot be changed using the rules of the grammar (this is the reason for the name "terminal").  For concreteness, consider a grammar defined by two rules:  x can become xa  x can become a Here a is a terminal symbol because no rule exists which would change it in to something else. (On the other hand, x has two rules that can change it, thus it is nonterminal.) A formal language defined (or generated) by a particular grammar is the set of strings that can be produced by the grammar and that consist only of terminal symbols.
  • 15. Nonterminal symbols are those symbols which can be replaced. A formal grammar includes a start symbol, a designated member of the set of nonterminals. e.g: digit = “0”|"1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; So digit is non-terminal because it‟s value lies at any range in 0 - 9.
  • 16. What is an integer?  An integer can be a single digit and so: <integer> ::= <digit>  However, what is a digit? A digit is 0 or 1 or 2 or … or 9.  <digit> ::= 0|1|2|3|4|5|6|7|8|9  The vertical line is read as or.
  • 17.  All integers of more than one digit start with a single digit and are followed by an integer and the final integer is a single digit integer.  An indefinitely long integer is defined as › <integer> ::= <digit><integer>  E.g. 147 › Is a single digit integer ( 1 ) followed by the integer 47. › 47 is a single digit integer ( 4 ) followed by a single digit integer ( 7 ).
  • 18. SAMPLE CODE OF BNF Int A=1+2/3; Console.writeLine(“{0}”,A); BNFC Code: EAdd ( (Eint 1) (Ediv (Eint 2 ) (Eint 3) ) ) Echo (A) EXPLANATION: ;EAdd == exp1 + exp2 (exp can be of any type of num) ;Eint == Exp is of type int ;Echo == prints the value
  • 19. C# code : Int a=5 Int i=1; Int ans=0; While(i!=10) { Ans=a*i; Console.writline(“{0}”,ans); i++; } BNF CODE: Eint A ::= 5 EInt I ::= 1 EInt ans ::= 0 While ::= <i != 11> < Eint ans ::= Emul (Eint A )(Eint i) Echo ans Eint i ::= Eadd (Eint i + 1) >
  • 20. Note: In some cases a lexical analyzer with syntax and semantic analyzer make up a Parser!!
  • 21.  Scans the Code, breaks it down into „Tokens‟:  constants (integer, double, char, string, etc.)  Identifier(Variables)  Operators  Punctuation(separator)  reserved words(keywords)  Process is called „Tokenization‟
  • 22.  Syntax tells of the valid form of the program  Described via CFG  Determines whether a statement is valid and can be produced via the production rules.  Semantic tell of the behavior of the program.  Two types:  Static semantic check(compile time error checking). Example: using undeclared variables, type checking.  Dynamic semantic check(run time error checking). Example: Array out of bounds, division by zero
  • 23.  BNF = Backus-Naur Form (also known as Context-Free Grammars).  BNF is the standard format for the specification and documentation of programming languages.  BNFC makes BNF usable for implementation as well.  BNFC is a high-level front end to traditional implementation formats (in the style of Lex and YACC): "BNFC is a compiler compiler"  BNFC saves 90% of source code writing in a typical compiler front end.  BNFC can be used for projects carried out in C, C++, C#, F#, Haskell, Java, OCaml.
  • 24.  Strongest case: when designing and implementing a new programming language  rapid development(can build on a previous language)  guaranteed consistency of components  freedom to change implementation of language(change its grammar)  ANSI C and Java have been implemented but some languages have rough corners (e.g. Haskell)
  • 25.  Q) What is computational model?  Q)Description of Language and Grammar?  Q)What is Parse-Structure grammar?  Q)What is Context free Grammar?  Q)Define BNF; who were main contributors to its development?  Q)BNF Model: Compiler. Explain?