Lecture Programming languages (2/e): Chapter 2d - Tucker, Noonan

Lecture Programming languages (2/e) - Chapter 2: Syntax. The main contents of this chapter include all of the following: Compilers and interpreters; linking syntax and semantics: abstract syntax, abstract syntax trees, abstract syntax of clite. | Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth Contents Grammars Backus-Naur Form Derivations Parse Trees Associativity and Precedence Ambiguous Grammars Extended BNF Syntax of a Small Language: Clite Lexical Syntax Concrete Syntax Compilers and Interpreters Linking Syntax and Semantics Abstract Syntax Abstract Syntax Trees Abstract Syntax of Clite Compilers and Interpreters Lexical Analyzer Syntactic Analyzer Semantic Analyzer Code Optimizer Code Generator Tokens Abstract Syntax Machine Code Intermediate Code (IC) Source Program Intermediate Code (IC) Lexer Input: characters Output: tokens Separate: Speed: 75% of time for non-optimizing Simpler design Character sets End of line conventions Parser Based on BNF/EBNF grammar Input: tokens Output: abstract syntax tree (parse tree) Abstract syntax: parse tree with punctuation, many nonterminals discarded Semantic Analysis Check that all identifiers are declared Perform type checking Insert implied conversion operators (., make them explicit) Code Optimization Evaluate constant expressions at compile-time Reorder code to improve cache performance Eliminate common subexpressions Eliminate unnecessary code Code Generation Output: machine code Instruction selection Register management Peephole optimization Interpreter Replaces last 2 phases of a compiler Input: Mixed: intermediate code Pure: stream of ASCII characters Mixed interpreters Java, Perl, Python, Haskell, Scheme Pure interpreters: most Basics, shell commands Linking Syntax and Semantics Output: parse tree is inefficient Example: Fig. Parse Tree for z = x + 2*y; Fig. Finding a More Efficient Tree The shape of the parse tree reveals the meaning of the program. So we want a tree that removes its inefficiency and keeps its shape. Remove | Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth Contents Grammars Backus-Naur Form Derivations Parse Trees Associativity and Precedence Ambiguous Grammars Extended BNF Syntax of a Small Language: Clite Lexical Syntax Concrete Syntax Compilers and Interpreters Linking Syntax and Semantics Abstract Syntax Abstract Syntax Trees Abstract Syntax of Clite Compilers and Interpreters Lexical Analyzer Syntactic Analyzer Semantic Analyzer Code Optimizer Code Generator Tokens Abstract Syntax Machine Code Intermediate Code (IC) Source Program Intermediate Code (IC) Lexer Input: characters Output: tokens Separate: Speed: 75% of time for non-optimizing Simpler design Character sets End of line conventions Parser Based on BNF/EBNF grammar Input: tokens Output: abstract syntax tree .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.