330ScanningParsing

330ScanningParsing - UNIVERSITY OF SOUTH CAROLINA...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Chapter 3: Lexical and Syntactic Analysis (based mainly on Tucker and Noonan; Watt and Brown) Fall 2010 Marco Valtorta mgv@cse.sc.edu Syntactic sugar causes cancer of the semicolon . A.Perlis UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Contents 3.1 Chomsky Hierarchy 3.2 Lexical Analysis 3.3 Syntactic Analysis UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 3.1 Chomsky Hierarchy Regular grammar -- least powerful Context-free grammar (BNF) Context-sensitive grammar Unrestricted grammar UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Regular Grammar Simplest; least powerful Equivalent to: Regular expression Finite-state automaton Right regular grammar: T*, B N A B A UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Example Integer 0 Integer | 1 Integer | ... | 9 Integer | 0 | 1 | ... | 9 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Regular Grammars Left regular grammar: equivalent Used in construction of tokenizers (scanners, lexers) Less powerful than context-free grammars Not a regular language { a b | n 1 } i.e., cannot balance: ( ), { }, begin end UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Context-free Grammars BNF a stylized form of CFG Equivalent to a pushdown automaton For a wide class of unambiguous CFGs, there are table-driven, linear time parsers UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Context-Sensitive Grammars Production: || || , (N T)* i.e., left-hand side can be composed of strings of terminals and nonterminals UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Undecidable Properties of CSGs Given a string and grammar G : L ( G ) L ( G ) is non-empty Defn: Undecidable means that you cannot write a computer program that is guaranteed to halt to decide the question for all L ( G ). UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Unrestricted Grammar Equivalent to: Turing machine von Neumann machine C++, Java That is, can compute any computable function. UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Contents 3.1 Chomsky Hierarchy 3.2 Lexical Analysis 3.3 Syntactic Analysis UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Lexical Analysis Purpose: transform program representation Input: printable Ascii characters Output: tokens Discard: whitespace, comments Defn: A token is a logically cohesive sequence of characters representing a single symbol. UNIVERSITY OF SOUTH CAROLINA...
View Full Document

This note was uploaded on 06/11/2011 for the course CSCE 330 taught by Professor Valtorta during the Spring '10 term at Columbia SC.

Page1 / 62

330ScanningParsing - UNIVERSITY OF SOUTH CAROLINA...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online