1 / 7

Lexical and Syntax Analysis

Lexical and Syntax Analysis. David Woolbright. Syntax Analysers or Parsers. Usually based on a formal description of a language Context-free grammars or BNF are used to describe the syntax of a language Parsers are organized into two parts

jemma
Télécharger la présentation

Lexical and Syntax Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lexical and Syntax Analysis David Woolbright

  2. Syntax Analysers or Parsers • Usually based on a formal description of a language • Context-free grammars or BNF are used to describe the syntax of a language • Parsers are organized into two parts • Lexical analyser – small scale language constructs – names, literals • Syntax analyser – large scale language constructs – expressions, statements, …

  3. Why Separate? • Simplicity – lexical analysis is easier than syntax analysis • Efficiency – lexical analysis can be optimized • Portability – lexical analysis is platform dependent

  4. Lexical Analysis • Pattern matching • Languages described by DFA • Easily translated • Acts as a front end for syntactic analysis • Collects characters and outputs lexemes (character groupings). • Internal codes are called tokens

  5. Lexical Analysis • Produces the “next” lexeme and token • Skips comments and white space • Inserts user-defined names into a symbol table (for later use by a compiler) • Detect syntactic errors in tokens

  6. Building a Lexical Analyser • Write a formal description of the token patterns using a descriptive language related to regular expressions. Use a software tool to generate the lexical analyser • Design a DFA for the token patterns and write a program that implements the DFA • Design a DFA for the token patterns and hand-construct a table driven implementation of the DFA

More Related