Unit 3 Scanning Parsing Scanning Scanning is a

  • Slides: 5
Download presentation
Unit 3 Scanning & Parsing

Unit 3 Scanning & Parsing

Scanning • • Scanning is a process of recognizing the lexical components in a

Scanning • • Scanning is a process of recognizing the lexical components in a source strings. Lexical feature of a language can be specified using regular grammar(type-3 grammar) (regular expression)

Problem with Scanning • • • In Fortran, scanning is required interaction with the

Problem with Scanning • • • In Fortran, scanning is required interaction with the parser For example DO 10 I = 1, 2 ->> Do statement DO 10 I = 1. 2 ->> assignment to variable DO 10 Since in Fortran blank space is allowed. So decision is taken only when “, ” is identified. Modern PLs does not contain such constructs.

Why scanning separated from parsing • • Scanning recognized lexical components regular grammar (TYPE-3

Why scanning separated from parsing • • Scanning recognized lexical components regular grammar (TYPE-3 grammar) Parsing identifies/validates syntactical components Context free grammar (TYPE -2 grammar) used Recognizer for type-3 grammar (FSA) is simpler, easier to build and more efficient during execution than a recognizer for type-2 grammar (PDA). Hence it is better to handle lexical and syntactical components of a source language separately

Finite State Automaton (FSA) Definition • • • A finite state automaton is a

Finite State Automaton (FSA) Definition • • • A finite state automaton is a triple (S, , T) where S = is a finite set of states --One of which is the initial state SInitial --One or more of which are the final states ∑ = is the alphabet of source symbols T= is a finite set of state transitions defining transitions out of each si S on encountering the symbols of ∑