Slide 1 Chapter 5-b Attributes of variables. Slide 2 Attributes of variables { int sum = 5;... } sum int 0000 0000 0000 0101 IdentifierType Value 0110.

Slides:



Advertisements
Similar presentations
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Advertisements

Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Names and Bindings.
Chapter 5 Names, Bindings, and Scopes
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Lifetime “The lifetime of a variable is the time during which the variable is bound to a specific memory location.” [p. 219] “…the lifetime of a variable.
CS 330 Programming Languages 10 / 18 / 2007 Instructor: Michael Eckmann.
Variables Six properties: Binding times of properties:
The Concept of Variables
CS 330 Programming Languages 10 / 24 / 2006 Instructor: Michael Eckmann.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
Names, Bindings, and Scopes
Names, Bindings, and Scopes
Software II: Principles of Programming Languages Lecture 5 – Names, Bindings, and Scopes.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
ISBN Chapter 10 Implementing Subprograms.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
Runtime Environments Compiler Construction Chapter 7.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Chapter 10 Implementing Subprograms. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 10 Topics The General Semantics of Calls and Returns.
Chapter 5 Names, Bindings, and Scopes. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 5 Topics Introduction Names Variables The Concept.
ISBN Chapter 5 Names, Bindings, and Scopes.
Storage Bindings Allocation is the process by which the memory cell or collection of memory cells is assigned to a variable. These cells are taken from.
1 Program Layout in memory –Code –Data Global variables –Stack Local variables & function Invocation Frames –Heap Dynamically allocated memory Today’s.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
Basic Semantics Associating meaning with language entities.
ISBN Chapter 5 Names, Bindings, and Scopes.
ECE 103 Engineering Programming Chapter 36 C Storage Classes Herbert G. Mayer, PSU CS Status 8/4/2014 Initial content copied verbatim from ECE 103 material.
1 CS Programming Languages Class 09 September 21, 2000.
ISBN Chapter 6 Data Types Pointer Types Reference Types Memory Management.
Names, Bindings, and Scope Session 3 Course : T Programming Language Concept Year : February 2011.
CS415 C++ Programming Takamitsu Kawai x4212 G11 CERC building WV Virtual Environments Lab West Virginia University.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
10-1 Chapter 10: Implementing Subprograms The General Semantics of Calls and Returns Implementing “Simple” Subprograms Implementing Subprograms with Stack-Dynamic.
ISBN Chapter 10 Implementing Subprograms.
Implementing Subprograms
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
Names, Scope, and Bindings Programming Languages and Paradigms.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
ISBN Chapter 10 Implementing Subprograms.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
CHAPTER 4 VARIABLES & BINDING SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Data Types Chapter 6: Data Types Lectures # 11. Topics Introduction Primitive Data Types Character String Types Array Types Associative Arrays Record.
Implementing Subprograms
Object Lifetime and Pointers
Chapter 10 : Implementing Subprograms
Implementing Subprograms
Chapter 4 Variables & Binding
CSE 3302 Programming Languages
Names, Bindings, and Scopes
CSC 253 Lecture 8.
Chapter 10: Implementing Subprograms Sangho Ha
Implementing Subprograms
CSC 253 Lecture 8.
Implementing Subprograms
Memory Allocation CS 217.
Local Variables, Global Variables and Variable Scope
Binding Times Binding is an association between two things Examples:
Dynamic Memory A whole heap of fun….
Semantic Analysis Chapter 6.
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Dynamic Memory.
Names, Bindings, and Scopes
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Implementing Subprograms
Presentation transcript:

Slide 1 Chapter 5-b Attributes of variables

Slide 2 Attributes of variables { int sum = 5;... } sum int IdentifierType Value Address Storage Symbol Table

Slide 3 Variable Names sum=0.0 DO I = 1 TO 10 sum = sum + i END DO... t = SQR(SUM)... FUNCTION sqr(val) val = val*val RETURN VAL Names: Fortran is not case sensitive. Type: Fortran allows implicit declarations.

Slide 4 Naming Conventions public void actionPerformed (ActionEvent e){ int value = Math.PI;... } Method names start with lower case Class names start with upper case Constants are all upper case Local variables are all lower case

Slide 5 Aliasing: Variables union { short i; float f; char c; } uval; c i f uval Aliasing using variables is meant for conserving storage space.

Slide 6 Aliasing: Pointers int i; int *p=&i; char *c; c=(char*)p; p c i Aliasing using pointer variables is not meant for conserving storage space.

Slide 7 Static Variables (Fortran) SUBROUTINE fun() DATA k/0/ K=K+1 PRINT *, K RETURN Call statementOutput CALL FUN() 1 CALL FUN() 2 CALL FUN() 3 CALL FUN() 4... In Fortran, all variables are by default static

Slide 8 Static Variables (C) void fun(){ int k=0; k++; printf(“\n %d”,k); } Call statementOutput fun( ); 1... fun( ); 1 fun( ); 2 fun( ); 3 fun( ); 4... void fun(){ static int k=0; k++; printf(“\n %d”,k); }

Slide 9 Stack Dynamic Variables i i ji { int i;... { int j;... }... }

Slide 10 Recursion n=3 n=2 n=3 n=2 n=1 n=3 n=2 1 n= int fact (int n){ if(n==1) return 1; else return n*fact(n-1); } 2 int fact (int n){ if(n==1) return 1; else return n*fact(n-1); } 1 int fact (int n){ if(n==1) return 1; else return n*fact(n-1); }

Slide 11 Heap-Dynamic Variables (1) int size=100; int *p; p = (int *) malloc(size*2);... free(p); 0 99 p p Heap allocation requires effective memory management ????

Slide 12 Heap-Dynamic Variables (2) int *node; node = new int; //Allocates an int cell.... delete node; //free the allocated memory. C++ Stack s = new Stack(); Java

Slide 13 Scope (C) int x;... main(){ int k;... { int k;... }... } Global variable Local variable

Slide 14 Scope (Java) public float fun(){ int[] x = {10, 20, 30}; float sum=0; for (int i=0; i<3; i++){ sum=sum+x[i]; } System.out.println(“Sum=”+sum); float v; v=sum/2; return v; } Local variables

Slide 15 Scope (Java classes) public class Myclass{ public void add(int y){ x = x+y; } int x=10; } Java allows the above type of declaration of instance variables but it is not advised.

Slide 16 Scope Vs. Lifetime (1) void compute() { static int k;... } Scope of the variable is limited to the function block, while its lifetime is the same as the total program execution time.

Slide 17 Scope Vs. Lifetime (2) void compute() { int value;... printinfo();... } void printinfo(){... } Scope of “value” does not extend to the function “printinfo”, but lifetime of value does.