1 Introducing ASML Methods, Values, Constraints, Constants, Variables Lecture 10 Software Engineering COMP201.

Slides:



Advertisements
Similar presentations
1 Introducing ASML ASML version 2, “Steps and Updates ” Lecture 9 Software Engineering COMP201.
Advertisements

ES 314 Lecture 2 Sep 1 Summary of lecture 1: course overview intro to matlab sections of Chapters 2 and 3.
1 Introducing ASML Enumerations, Conditionals and Loops, Quantifiers Lecture 13 Software Engineering COMP201.
1 Introducing ASML Classes, Structured Values, Sets, Sequences Lecture 11 Software Engineering COMP201.
1 Introducing ASML Methods, Values, Constraints, Constants, Variables, Sets, Sequences Lecture 11, 12 Software Engineering COMP201.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Data types and variables
Lecture 3 August 31 Chapter 3. Chapter 3 – numbers, string, booleans integer: MATLAB stores numeric data as double-precision floating point (double) by.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
Objectives You should be able to describe: Data Types
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Programming Languages
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
Built-in Data Structures in Python An Introduction.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Looping and Counting Lecture 3 Hartmut Kaiser
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Structure Programming Lecture 8 Chapter 5&6 - Function – part I 12 December 2015.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CSI 3125, Preliminaries, page 1 Data Type, Variables.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Controlling Program Flow with Decision Structures.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Expressions and Data Types Professor Robin Burke.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Definition of the Programming Language CPRL
Chapter 10 Programming Fundamentals with JavaScript
“Under the hood”: Angry Birds Maze
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lecture 2 Data Types Richard Gesick.
Object Oriented Programming
2. Understanding VB Variables
Chapter 10 Programming Fundamentals with JavaScript
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
PHP.
CMSC 202 Java Primer 2.
CS139 October 11, 2004.
Python Primer 1: Types and Operators
COMPUTER PROGRAMMING SKILLS
Chapter 2 Primitive Data Types and Operations
Review of Java Fundamentals
Presentation transcript:

1 Introducing ASML Methods, Values, Constraints, Constants, Variables Lecture 10 Software Engineering COMP201

2 I. Methods Methods are named operations that may be invoked in various contexts The definition of a method may include parameters that will be associated with particular values each time the method is invoked Methods may also specify a return value that is available after the operation has been performed

3 The general form for a method definition name (parameter 1 as Type, … parameter n as Type) as Type the values sent to the method, if there any the name of method The type of the return value, if there is one

4 Method IsWord() IsWord ( i as Integer ) as Boolean return (0<= i and i <= 0xFFFF) Main() step if IsWord ( 123 ) then Writelone (“123 is a word of memory.”) IsWord evaluates an argument i and returns the value true if i  0 and i  0xFFFF (hexadecimal number). If i doesn’t fit these criteria, IsWord returns the value false. An expression in the form IsWord() is an application of the name IsWord to argument i, which is a long integer.

5 Functions and update procedures Functions have no effect on state variables Functions must return a value IsWord ( i as Integer ) as Boolean return (0<= i and i <= 0xFFFF) Update procedures configure the values of state variables for the next sequential step of the machine Update procedures may optionally return a value

6 Update procedure power() var x as Integer = 3 var y as Integer = 0 var index as Integer = 3 power (x as Integer, n as Integer) as Integer var result as Integer = 1 var i as Integer = 1 step while i<=n result:=result*x i:=i+1 step return result Main() step y := power(5,3) step WriteLine (“5 cubed =” +y) WriteLine(“3 cubed =” + power(3,index)) x:= power(x, power(2,2)) step WriteLine (“x = ” +x) Output: 5 cubed = cubed = 27 x = 81

7 Local names for values Statement in the form identifier = expression introduce identifier as a local name for the value given on the right hand side of the equals sign (“ = ”) by expression. Main() mySet = {1, 2, 3} step WriteLine(“mySet has” + asString(size(mySet))+ “ elements. ”) Local names may be introduced within any block of statement. Local names could appear after the “then” keyword of an if … then … else statement

8 Local names in sequences of steps A local name can be referenced anywhere in its statement block. In a sequence of steps, local names introduced within a step block are available within any following step block. Main() step mySet1 = {1, 2, 3} WriteLine (“mySet has” + asString(size(mySet1))+ “ elements. ”) step mySet2 = mySet1 union {4, 5, 6} WriteLine(“mySet has” + asString(size(mySet2))+ “ elements. ”)

9 Method overloading Method overloading allows you: to use the same name in different methods in each instance to have the compiler choose the correct instance Must be a clear way for the compiler to decide which method should be called for any particular instance

10 Method overloading example S = { 1, 8, 2, 12, 13, 6} Max (i as Integer, j as Integer) as Integer return if i > j then i else j Max (s as Set of Integer) as Integer return any m | m in S where not (exists n in S where n>m ) run() step writeln(“The largest number in the set is ” + ( Max(S) ) ) step writeln(“The largest of the two integers is ” + ( Max(2,3) ) ) A series of methods with the same name but differentiated by their parameter lists are overloaded methods

11 II.Values What are values? If x and y are values, then we can ask whether x is equal to y If the S is a set, then we can ask whether x is an element of S A value is an immutable element that supports two operations: equality testing and set membership. The term value has the same meaning as in mathematical sets

12 Structured values Some values are composed of other values Some structured values are built into AsmL; others may be defined by you ordered pair structure Location base as Integer offset as Integer Location (1,4) is a value of the user-defined structure type Location

13 Built in value types Double-precision 64-bit floating-point format type as specified in IEEE 754 Double Single-precision 32-bit floating-point format type as specified in IEEE 754 Float 64-bit signed integer typeLong 32-bit signed integer typeInteger 16-bit signed integer typeShort 8-bit unsigned integer typeByte A type that can be assigned true and false Boolean MeaningData Type

14 Built in value types A set containing elements of type A Set of A A table whose entries map of elements of type A to type B Map of A to B A sequence of elements of type A Seq of A Unicode string typeString Unicode character typeChar MeaningData Type

15 Built in value types Types in the form t? includes all of the values of type t plus the special value undef. For example, a variable declared as Boolean? could contain either of the Boolean value true or false or the value undef. A? A tuple consisting of elements of type A1, A2, … Tuple values are written in the same form For example, (1,2) is of a value of the built-in type (Integer,Integer) (A1,A2,…) Meaning Data Type

16 III. Constraints Assertions Assertions require and ensure statements document constraints placed upon the model Violating a constraint at runtime is called an assertion failure AllTickets = { } IsTicketID (i as Integer) as Boolean require i > 0 return ( i in AllTickets) ChooseAnyTicket() as Integer ensure IsTicketID(result) return any t | t in AllTickets The keyword result denotes the value of the return statement

17 Type constraints Types of constants, variables and method parameters may be specified using the syntax : name as type Types may be explicitly checked using the “ is” operator : value is type an expression will be either true or false, depending on whether the value given is an element of the type Types are not themselves values. For example, you can’t pass a type as an argument

18 IV. Constants Constants are fixed, named values Constants can either be global or local Global constants are declared in the beginning of the program Local constants are declared within a statement block The general form of declaring and initialising a constant is: Name [as Type] = value MaxInteger = 100 run() MinInteger = 0

19 V. Variables Variables are names given to memory locations. Updating variables is the only way to change a state of a machine. Variables can be complex types such as structures or maps as well as simple types. Here is the general form for declaring and initialising variables: var name [as Type] = value

20 Types of variables There are three types of variables in AsmL –Global variables –Local variables –Instance-based variables Instance-based variables are variables that exist for each instance of a class var x as Integer = 10 // shows explicit typing var x = 10 // shows implicit typing var greeting as String = “Hello” // shows a // string variable var y = [1..6] // shows a sequence of // integers from 1 to 6 var menu = {“ham”, “cheese”, “bit”} // shows a // set