programming languages
play

Programming Languages Janyl Jumadinova September 24, 2020 Janyl - PowerPoint PPT Presentation

Programming Languages Janyl Jumadinova September 24, 2020 Janyl Jumadinova Programming Languages September 24, 2020 1 / 17 Name, Scope, and Binding Janyl Jumadinova Programming Languages September 24, 2020 2 / 17 Name, Scope, and Binding


  1. Programming Languages Janyl Jumadinova September 24, 2020 Janyl Jumadinova Programming Languages September 24, 2020 1 / 17

  2. Name, Scope, and Binding Janyl Jumadinova Programming Languages September 24, 2020 2 / 17

  3. Name, Scope, and Binding A name is exactly what you think it is – Most names are identifiers – symbols (like ‘+’) can also be names Janyl Jumadinova Programming Languages September 24, 2020 2 / 17

  4. Name, Scope, and Binding A name is exactly what you think it is – Most names are identifiers – symbols (like ‘+’) can also be names A binding is an association between two things, such as a name and the thing it names. Janyl Jumadinova Programming Languages September 24, 2020 2 / 17

  5. Name, Scope, and Binding A name is exactly what you think it is – Most names are identifiers – symbols (like ‘+’) can also be names A binding is an association between two things, such as a name and the thing it names. The scope of a binding is the part of the program (textually) in which the binding is active. Janyl Jumadinova Programming Languages September 24, 2020 2 / 17

  6. Binding Binding Time: the point at which a binding is created or, more generally, the point at which any implementation decision is made. Janyl Jumadinova Programming Languages September 24, 2020 3 / 17

  7. Binding Binding Time: the point at which a binding is created or, more generally, the point at which any implementation decision is made. language design time program structure, possible type language implementation time - I/O, arithmetic overflow, type equality (if unspecified in manual) Janyl Jumadinova Programming Languages September 24, 2020 3 / 17

  8. Other Implementation Decisions program writing time – algorithms, names Janyl Jumadinova Programming Languages September 24, 2020 4 / 17

  9. Other Implementation Decisions program writing time – algorithms, names compile time – plan for data layout Janyl Jumadinova Programming Languages September 24, 2020 4 / 17

  10. Other Implementation Decisions program writing time – algorithms, names compile time – plan for data layout link time –layout of whole program in memory Janyl Jumadinova Programming Languages September 24, 2020 4 / 17

  11. Other Implementation Decisions program writing time – algorithms, names compile time – plan for data layout link time –layout of whole program in memory load time Janyl Jumadinova Programming Languages September 24, 2020 4 / 17

  12. More Implementation Decisions run time – value/variable bindings, sizes of strings – NOTE: run time includes program start-up time module entry time elaboration time (point at which a declaration is first “seen”) procedure entry time Janyl Jumadinova Programming Languages September 24, 2020 5 / 17

  13. Binding The terms STATIC and DYNAMIC are generally used to refer to things bound before run time and at run time, respectively. – “static is a coarse term; so is “dynamic” Janyl Jumadinova Programming Languages September 24, 2020 6 / 17

  14. Binding The terms STATIC and DYNAMIC are generally used to refer to things bound before run time and at run time, respectively. – “static is a coarse term; so is “dynamic” Binding Times are very important in programming languages! Janyl Jumadinova Programming Languages September 24, 2020 6 / 17

  15. Binding In general, early binding times are associated with greater efficiency Later binding times are associated with greater flexibility Janyl Jumadinova Programming Languages September 24, 2020 7 / 17

  16. Binding In general, early binding times are associated with greater efficiency Later binding times are associated with greater flexibility Compiled languages tend to have early binding times Interpreted languages tend to have later binding times Janyl Jumadinova Programming Languages September 24, 2020 7 / 17

  17. Scope Rules - Control Bindings Fundamental to all programming languages is the ability to name data - i.e., to refer to data using symbolic identifiers rather than addresses Janyl Jumadinova Programming Languages September 24, 2020 8 / 17

  18. Scope Rules - Control Bindings Fundamental to all programming languages is the ability to name data - i.e., to refer to data using symbolic identifiers rather than addresses Not all data is named! For example, dynamic storage in C or Pascal is referenced by pointers, not names Janyl Jumadinova Programming Languages September 24, 2020 8 / 17

  19. Scope Rules - Control Bindings Fundamental to all programming languages is the ability to name data - i.e., to refer to data using symbolic identifiers rather than addresses Not all data is named! For example, dynamic storage in C or Pascal is referenced by pointers, not names double *d = (double *)malloc(8); *d = 3.14; /* No name is bound to the value 3.14 */ /* The name ‘‘d’’ is bound to the ADDRESS containing 3.14 */ Janyl Jumadinova Programming Languages September 24, 2020 8 / 17

  20. Lifetime and Storage Management The period of time from creation to destruction is called the LIFETIME of a binding. Janyl Jumadinova Programming Languages September 24, 2020 9 / 17

  21. Lifetime and Storage Management The period of time from creation to destruction is called the LIFETIME of a binding. If object outlives binding it’s garbage . If binding outlives object it’s a dangling reference . Janyl Jumadinova Programming Languages September 24, 2020 9 / 17

  22. Lifetime and Storage Management The period of time from creation to destruction is called the LIFETIME of a binding. If object outlives binding it’s garbage . If binding outlives object it’s a dangling reference . The textual region of the program in which the binding is active is its scope . Janyl Jumadinova Programming Languages September 24, 2020 9 / 17

  23. Lifetime and Storage Management Storage Allocation mechanisms Static Stack Heap Janyl Jumadinova Programming Languages September 24, 2020 10 / 17

  24. Lifetime and Storage Management Storage Allocation mechanisms Static Stack Heap Static allocation for code globals static or own variables Janyl Jumadinova Programming Languages September 24, 2020 10 / 17

  25. Static Example In C, variables can be global (visible to any function) Janyl Jumadinova Programming Languages September 24, 2020 11 / 17

  26. Static Example When we compile this, i is stored in a fixed location, while j is allocated on the stack Janyl Jumadinova Programming Languages September 24, 2020 12 / 17

  27. Two Types of Scoping Static scoping (also called “lexical scoping”) most familiar (Java, C) scope of variables known at compile time Janyl Jumadinova Programming Languages September 24, 2020 13 / 17

  28. Two Types of Scoping Static scoping (also called “lexical scoping”) most familiar (Java, C) scope of variables known at compile time Dynamic scoping scope depends on order of function calls at execution time pretty rare nowadays Janyl Jumadinova Programming Languages September 24, 2020 13 / 17

  29. Static Scope Example (Java) Janyl Jumadinova Programming Languages September 24, 2020 14 / 17

  30. What Happens Here? (Java) Janyl Jumadinova Programming Languages September 24, 2020 15 / 17

  31. What Happens in Dynamic Scoping? Janyl Jumadinova Programming Languages September 24, 2020 16 / 17

  32. In-Class Exercise JavaScript Case Study – Pull activity4 in your class activities repository Janyl Jumadinova Programming Languages September 24, 2020 17 / 17

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend