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

Chapter 2 - Syntax. We shall see that most of the syntactic structure of modern programming languages is defined using a linguistic formalism called the contextjree grammm: Other elements of syntax are outside the realm of context-free grammars, and are defined by other means. A careful treatment of programming language syntax appears in Chapter 2. This chapter provides knowledge of grammars of syntax: backus-naur form, derivations, parse trees. | 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 Thinking about Syntax The syntax of a programming language is a precise description of all its grammatically correct programs. Precise syntax was first used with Algol 60, and has been used ever since. Three levels: Lexical syntax Concrete syntax Abstract syntax Levels of Syntax Lexical syntax = all the basic symbols of the language (names, values, operators, etc.) Concrete syntax = rules for writing expressions, statements and programs. Abstract syntax = internal representation of the program, favoring content over form. ., C: if ( expr ) . discard ( ) Ada: if ( expr ) then discard then Grammars A metalanguage is a language used to define other languages. A grammar is a metalanguage used to define the syntax of a language. Our interest: using grammars to define the syntax of a programming language. Backus-Naur Form (BNF) Stylized version of a context-free grammar (cf. Chomsky hierarchy) Sometimes called Backus Normal Form First used to define syntax of Algol 60 Now used to define syntax of most major languages BNF Grammar Set of productions: P terminal symbols: T nonterminal symbols: N start symbol: A production has the form where and Example: Binary Digits Consider the grammar: binaryDigit 0 binaryDigit 1 or equivalently: binaryDigit 0 | 1 Here, | is a metacharacter that separates alternatives. Derivations Consider the grammar: Integer Digit | Integer Digit Digit 0 | 1 | 2 | 3 | | 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 Thinking about Syntax The syntax of a programming language is a precise description of all its grammatically correct programs. Precise syntax was first used with Algol 60, and has been used ever since. Three levels: Lexical syntax Concrete syntax Abstract syntax Levels of Syntax Lexical syntax = all the basic symbols of the language (names, values, operators, etc.) Concrete syntax = rules for writing expressions, statements and .

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.