{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

330ScanningParsing - CSCE 330 Programming Language...

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

View Full Document Right Arrow Icon
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 [email protected] Syntactic sugar causes cancer of the semicolon A.Perlis
Background image of page 1

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

View Full Document Right Arrow Icon
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Contents 3.1  Chomsky Hierarchy 3.2  Lexical Analysis 3.3  Syntactic Analysis
Background image of page 2
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
Background image of page 3

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

View Full Document Right Arrow Icon
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 → ϖ
Background image of page 4
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Example Integer → 0 Integer | 1 Integer | ... | 9 Integer | 0 | 1 | ... | 9
Background image of page 5

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

View Full Document Right Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full Document Right Arrow Icon
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
Background image of page 8
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 ).
Background image of page 9

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

View Full Document Right Arrow Icon
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.
Background image of page 10
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Contents 3.1  Chomsky Hierarchy 3.2  Lexical Analysis 3.3  Syntactic Analysis
Background image of page 11

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

View Full Document Right Arrow Icon
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.
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}