程序设计语言概念(ConceptsofProgrammingLanguages)英文第10版第7章P

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
• Precedence and associativity rules can be overriden with parentheses
Copyright © 2012 Addison-Wesley. All rights reserved.
1-8
Expressions in Ruby and Scheme
• To understand expression evaluation, need to be familiar with the orders of operator and operand evaluation
• Essence of imperative languages is dominant role of assignment statements
• Ruby
– All arithmetic, relational, and assignment operators, as well as array indexing, shifts, and bit-wise logic operators, are implemented as methods
– Left to right, except **, which is right to left – Sometimes unary operators associate right to left (e.g., in
FORTRAN)
• APL is different; all operators have equal precedence and all operators associate right to left
– parentheses – unary operators – ** (if the language supports it) – *, / – +, -
Copyright © 2012 Addison-Wesley. All rights reserved.
1-7
Arithmetic Expressions: Operator Associativity Rule
• The operator associativity rules for expression
evaluation define the order in which adjacent operators with the same precedence level are evaluated • Typical associativity rules
• Arithmetic expressions consist of operators, operands, parentheses, and function calls
Copyright © 2012 Addison-Wesley. All rights reserved.
1-4
Arithmetic Expressions: Design Issues
Copyright © 2012 Addison-Wesley. All rights reserved.
1-2
Introduction
• Expressions are the fundamental meanLeabharlann Baidu of specifying computations in a programming language
• Design issues for arithmetic expressions
– Operator precedence rules? – Operator associativity rules? – Order of operand evaluation? – Operand evaluation side effects? – Operator overloading? – Type mixing in expressions?
Copyright © 2012 Addison-Wesley. All rights reserved.
1-5
Arithmetic Expressions: Operators
• A unary operator has one operand • A binary operator has two operands • A ternary operator has three operands
Copyright © 2012 Addison-Wesley. All rights reserved.
1-3
Arithmetic Expressions
• Arithmetic evaluation was one of the motivations for the development of the first programming languages
Chapter 7
Expressions and Assignment Statements
Chapter 7 Topics
• Introduction • Arithmetic Expressions • Overloaded Operators • Type Conversions • Relational and Boolean Expressions • Short-Circuit Evaluation • Assignment Statements • Mixed-Mode Assignment
Copyright © 2012 Addison-Wesley. All rights reserved.
1-6
Arithmetic Expressions: Operator Precedence Rules
• The operator precedence rules for
expression evaluation define the order in which “adjacent” operators of different precedence levels are evaluated • Typical precedence levels
相关文档
最新文档