021_Syntax_Analysis

021_Syntax_Analysis - Syntax Analysis Where We Are Lexical...

Info iconThis preview shows pages 1–19. 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

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: Syntax Analysis Where We Are Lexical Analysis Syntax Analysis Semantic Analysis IR Generation IR Optimization Code Generation Optimization Source Code Machine Code Where We Are Lexical Analysis Syntax Analysis Semantic Analysis IR Generation IR Optimization Code Generation Optimization Source Code Machine Code Flex-pert Flex-pert Where We Are Lexical Analysis Syntax Analysis Semantic Analysis IR Generation IR Optimization Code Generation Optimization Source Code Machine Code while (ip < z) ++ip; w h i l e ( i < z ) \n \t + i p ; while (ip < z) ++ip; p + + w h i l e ( i < z ) \n \t + i p ; while (ip < z) ++ip; p + + T_While ( T_Ident < T_Ident ) ++ T_Ident ip z ip w h i l e ( i < z ) \n \t + i p ; while (ip < z) ++ip; p + + T_While ( T_Ident < T_Ident ) ++ T_Ident ip z ip While ++ Ident < Ident Ident ip z ip do[for] = new 0; do[for] = new 0; d o [ f ] n e w ; = o r do[for] = new 0; T_Do [ T_For T_New T_IntConst d o [ f ] n e w ; = o r ] = do[for] = new 0; T_Do [ T_For T_New T_IntConst d o [ f ] n e w ; = o r ] = What is Syntax Analysis? After lexical analysis (scanning), we have a series of tokens. Goal: Recover the structure described by that series of tokens. Goal: Report errors if those tokens do not properly encode a structure. Outline Today: Formalisms for syntax analysis. Next Week: Parsing algorithms. Parser generators. Recall: Languages Given an alphabet , a language over is a set of strings over . During scanning, we were concerned with languages defining tokens : Identifiers: {a, b, c, , aa, ab, } Numbers: {0, 1, 2, } etc. However, we can think of a programming language as a language as well. Each string is a complete program. Describing Programming Languages When dealing with tokens, we used regular expressions. Can we do the same for programming languages? In general, no . Intuition: Automata have finite memory . The only information retained at any point is what state(s) the automaton is is. No way of remembering unbounded paths through the automaton ( pumping lemma ). Non-Regular Languages Balanced parentheses. { , (), (()), ()(), ((())), (())(), (()()), etc. } Scheme programs. {1, 2, 3, , (lambda (x) (+ x 1)), etc. } Regular expressions. { , a, aa, a | a, a | , a*, *, (a), (), etc. } Context-Free Grammars A tool for describing languages that is strictly more powerful than regular languages. Excellent way of capturing recursive structure. Example: Regular expressions A regular expression can be Any letter The concatenation of regular expressions. The disjunction of regular expressions....
View Full Document

This document was uploaded on 07/18/2011.

Page1 / 128

021_Syntax_Analysis - Syntax Analysis Where We Are Lexical...

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

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