22-06-2012, 06:01 PM
3 –Syntax Analysis ( Parsing )
3 –Syntax Analysis ( Parsing ).PPT (Size: 3.57 MB / Downloads: 52)
Syntax Analysis & Parsing
Just to recapitulate the definitions:
Syn-tax
The way in which words are stringed together to form phrases, clauses and sentences
Syntax analysis:
The task concerned with fitting a sequence of tokens into a specified syntax.
Parsing:
To break a sentence down into its component parts of speech with an explanation of the form, function, and syntactical relationship of each part
Intro to Context Free Grammar (CFG)
Essential formalism for describing the structure of the programs in a programming Language
A recipe for constructing elements of a set of strings of symbols ( or tokens)
Consists of a set production rules and a start symbol
Each production rule:
Defines a named syntactic construct using Two parts
An LHS (with a syntactic Construct) and
An RHS (showing the possible form of the construct)
Connected by an Arrow symbol ( meaning “ is defined as” )
Importance of the Grammar
Grammar offers significant advantages to both language Designers and Compiler writers:
Gives precise, yet easy-to-understand, syntactic specification of Programming Languages
Helps construct efficient parsers automatically ( not in all cases – of course)
Provides a good structure to the language which in turn helps generate correct object code
Makes language open ended easily amenable to add additional constructs at a later date
Notational Conventions
These Symbols are terminals
Lower case letters early in the alphabet ( like a, b, c)
Operator symbols such as +, - etc..
Punctuation symbols like ,(comma), (, ), etc
The digits 0, 1, ………..9
Boldface strings such as if, id etc…
These Symbols are nonterminals
Uppercase letters early in the alphabet ( like A, B, C)
The letter S when it appears, is usually the Start Symbol
Lower case letters late in the alphabet chiefly u, v, …. ……. z represent string of terminals