programming language
A formal language which comprises a set of instructions that produce various kinds of output. Consists of instruction for computers
Program
instructions for a computer to execute
high-level language
Language that allows you to write precise instructions in a human-readable form
Program Design
Design of a language driven to fix a problem
Program Philosophy/Paradigm
Imperative (Procedual)
Declarative (Functional)
Logical/Constrained-based (OOP)
Computer Architecture
Language must be made to work how the hardware architecture works
Language Implementation Technology:
Compilers, Interpreters, Virtual Machines
Compiler:
Translates source code into executable machine code run directly by the hardware
Interpreter:
Reads and executes each line of code as it reads it during run time.
Virtual Machine
Executes a compiled intermediate level code, byte code, which is interpreted by the virtual machine
Desirable design features of a language:
Simplicity
Orthogonality
Level of Abstraction
Portability
Cost *Expressiveness
simplicity
Feature set is short and to the point
Orthogonality:
Different factors combine to produce something meaningful
level of abstraction:
The amount of complexity by which a system is viewed or programmed. Higher level, less detail. Lower level, more detail.
Portability
Ability to move program from one system to another
Expressivity
The amount of ways that the same problem can be solved.
Memory Allocation
Static Allocation
Dynamic Allocation
Static Allocation:
Memory is allocated at compilation time (predetermined) PROS: *Faster CONS: *Needs to know amount of memory in advance *Prone to memory waste
Dynamic Allocation:
memory space is only allocated when required at runtime. PROS: *Do not need to know amount of memory in advance *Use only what is needed CONS: *Slower
Memory Allocation Implementation:
Compiler: Static and Dynamic
Interpreter: Dynamic
Virtual Machine: Static and Dynamic
Names:
User generated ID's (function names, class names, variable names)
case sensitive:
Distinguishing upper- and lowercase characters. Easier to implement.
case-insensitive:
Both the uppercase and lowercase forms of a character are considered by a computer program to be the same
reserved words
Words that have predefined meanings that cannot be changed. *Keywords: private, void, static, etc. 25. Identifiers: names given to entities, such as variables, functions, structures, etc.
Variable:
Location in memory that is subject to destructive update which is bound to a name. Value can change overtime.
L-Value:
address location of variable in memory
R-value:
Actual value that is stored in the memory address location
Aliasing
One part of memory has multiple names leading to it
Symbol Table
A data structure that links names to information about the objects denoted by the names. Keeps track of binding between name and memory locations.
Storage
*Statically Allocated Variables *Dynamically Allocated Variables
Binding
the association of a name with a variable or value. Also, the time when it happens
Types of binding
*Static binding *Dynamic binding
Static Binding:
Binding performs before program runs
Dynamic Binding:
Binding performs while program is running
Static Typing:
Types are checked before program runs PROS: *Faster Execution time *Readability in increased CONS: *No flexibility *More initial overhead
Dynamic Typing:
Types are checked while program is running PROS: *Flexibility (no need to explicitly write type annotation) *Less initial overhead before deployment CONS: *Slower Execution Time *Decreased Readability
Type annotation:
*Explicit *Implicit
Explicit Typing:
Language demands the programmer explicitly state type
Implicit Typing:
Language does no demand explicit denotation of data
Destructive Updates
Any change to a memory location that replaces the current value
Scope
Region in program in which the lifetime of a name is defined. Lexical region in which a name is visible/usable *Nested functions *Blocks *Order of declaration *Global variables
Static Scope
Region is defined using lexical features, delimiters. *A region in a text of the program *Implemented using "blocks"
Dynamic Scope
: Value is determined by the identifier associated with the most recent environment
Scope Blocks:
Lexical region in program where a name is visible
Constants:
Value can not be changed
Data Types:
Primitive Data Types *Integral numbers *Floating point numbers *Boolean types *Character
Integral Numbers:
Int: 32 bits = 4 bytes Byte: 8 bits = 1 byte Short: 16 bits = 2 bytes Long: 64 bits= 8 bytes
floating point numbers:
Float: 32 bits = 4 bytes Double: 64 bits = 8 bytes
Boolean type
Boolean: 8 bits = 1 byte bool: 8 bits = 1 byte
Character:
character: 8 bits = 1 byte char: 8 bits = 1 byte
string type:
-a string is a sequence of characters -the String type is used to declare variables that store strings -is not a primitive type: it is known as a class or reference type -one or more characters in double quotes -strings as character arrays
Types of strings:
-Dynamic size up to a bound (array) -Constant size (immutable)
Pointer
Special variables that allow access to l-values of memory locations
Syntax
the rules for combining words into grammatically sensible sentences in a given language
Semantics:
the set of rules by which we derive meaning from morphemes, words, and sentences in a given language; also, the study of meaning
lexicon:
Valid words of the language. A dictionary; a specialized vocabulary used in a particular field or place
grammar:
a set of rules that specify how the units of language can be combined to produce meaningful messages and sentences.