Programming Languages 1 - 5
Lack of uniformity
Different things look the same Example: using assignment to return a value Pascal uses the function name in an assignment Looks confusingly like a standard assignment statement Other languages use a return
FORTRAN
FORmula TRANslation language Developed by John Backus in the early 1950s Reflected the architecture of a particular type of machine Lacked the structured control statements and data structures of later high - level languages Popular with scientists and engineers for its support for algebraic notation and floating - point numbers
Basic data abstraction
Hides internal representation of common data values the programmer cannot normally access the component parts or bits of the internal representation
Input devices
Keypunch machine, Card reader
Procedure
Or Subprogram or subroutine groups a sequence of actions into a single action that can be called or invoked from other points in the program
Tokens
The language's words Includes keywords identifiers symbols for operations special punctuation symbols etc.
Abstract syntax tree
a condensed view of the parse tree
Extensible language
a language that allows the user to add features to it Example: the ability to define new data types and new operations functions or procedures Very few languages allow additions to the syntax and semantics Lisp allows new syntax and semantics via a macro Macro : specifies the syntax of a piece of code that expands to other standard code when compiled
Syntactic sugar
a mechanism that allows you to replace a complex notation with a simpler shorthand notation Example: x += 10 instead of x = x + 10
Recursion
a mechanism that further exploits the abstraction mechanism
Predictive parser
a parser that commits itself to a particular action based only on the lookahead
Translator
a program that accepts other programs and either directly executes them or transforms them into a form suitable for execution
Parser generator
a program that automates top - down or bottom - up parsing
Loader
a program that loads the machine code into computer memory
Assembler
a program that translates the symbolic assembly language code to binary machine code
Text file
a sequence of characters for transfer to and from an external storage device
Assembly language
a set of mnemonic symbols for instruction codes and memory locations Example: LD R1 FIRST
TinyAda
a small language that illustrates the syntactic features of many high - level languages TinyAda includes several kinds of declarations statements and expressions Rules for declarations statements and expressions are indirectly recursive allowed for nested declarations statements and expressions
Unit
a stand - alone collection of procedures providing logically related services to other parts of a program Allows a program to be understood as a whole without needing to know the details of the services provided by the unit
Recognizer
accepts or rejects strings based on whether they are legal strings in the language Bottom - up parser : constructs derivations and parse trees from the leaves to the roots Matches an input with right side of a rule and reduces it to the nonterminal on the left
Generality
achieved by avoiding special cases in the availability or use of constructs and by combining closely related constructs into a single more general one
Iterator
an object associated with a collection such as array list set or tree Open an iterator on a collection then visit all the values Syntactic sugar for iterator in Java: enhanced for loop
Productions
another name for grammar rules Typically there are as many productions in a context - free grammar as there are nonterminals Backus - Naur form : uses only the metasymbols "->"(or "::=") and | Start symbol : a nonterminal representing the entire top - level phrase being defined Language of the grammar : defined by a context - free grammar
Parsing shell
applies the grammar rules to check whether tokens are of the correct types
Reliability
can be viewed as an efficiency issue -Unreliable programs require programmer time to diagnose and correct
Function
closely related to a procedure Returns a value or result to its caller Can be written to correspond more closely to mathematical abstractions
Security
closely related to reliability A language designed with security in mind: Discourages programming errors Allows errors to be discovered and reported Types type - checking and variable declarations resulted from a concern for security Exclusive focus on security can compromise the expressiveness and conciseness of a language Typically forces the programmer to laboriously specify as many things as possible in the code
Structured abstractions
collect intermediate information about the structure of a program
Unit abstractions
collect large - scale information in a program
Basic abstractions
collect the most localized machine information
Data structure
collects related data values into a single unit Hides component parts but can be constructed from parts and parts can be accessed and modified Examples: Employee record contains name address phone salary different data types
Lambda calculus
computational model developed by mathematician Alonzo Church Based on the theory of recursive functions
free grammar
consists of a series of grammar rules Each rule has a single phrase structure name on the left then a metasymbol followed by a sequence of symbols or other phrase structure names on the right
Orthogonal design
constructs can be combined in any meaningful way with no unexpected restrictions or behaviors
Information hiding
defining new data types data and operations that hide information
Structured control abstractions
divide a program into groups of instructions nested within tests that govern their execution Help to express the logic of primary control structures of sequencing selection and iteration
Interpreter
executes a program directly a type of translator
Top down parser
expands nonterminals to match incoming tokens and directly construct a derivation
Grammar
formal definition of the language's syntax
Token delimiters
formatting that affects the way tokens are recognized
Higher order functions
functions that can accept other functions as arguments and return functions as values Example: map function Expects another function and a collection as arguments Applies the argument function to each element in the argument collection and returns a list of results
API
gives information about the resources components
Parse tree
graphical depiction of the replacement process in a derivation
Expressiveness
how easy is it to express complex processes and structures? Conciseness of the syntax also contributes to programmer efficiency Example: Pascal has BEGIN END C/Java have { }
Programmer efficiency
how quickly and easily can a person read and write in the programming language
Predefined identifiers
identifiers that have been given an initial meaning for all programs in the language but are capable of redirection
Syntax diagram
indicates the sequence of terminals and nonterminals encountered in the right - hand side of the rule
Branch instructions
instructions that support selection and iteration to memory locations other than the next one
Implementation
internal representation of data values and operations
Bottom up parsing
is the preferred method for parser generators also called compiler compilers
Pascal
language for teaching programming in the 1970's Ada for embedded applications of U.S. Dept. of Defense
Semantically safe
languages that prevents a programmer from compiling or executing any statements or expressions that violate the language definition Example: array out of bounds exception or lack of it in e.g. C language Examples: Python Lisp Java
Semantics
meaning of a language Describes the effects of executing the code Difficult to provide a comprehensive description of meaning in all contexts Example: if statement in C No generally accepted formal method for describing semantics
Procedure declaration
names a procedure and associates it with the actions to be performed
Nonterminals
names for phrase structures since they are broken down into further phrase structures
Data types
names given to kinds of data values
Unit abstraction
often associated with the concept of an abstract data type A set of data values and the operations on those values Separates the interface from the implementation
Free-format language
one in which format has no effect on program structure other than satisfying the principle of longest substring
Processes
other programs executing outside the Java system
Efficiency of execution
primary design criterion Early FORTRAN code more or less directly mapped to machine code minimizing the amount of translation required by the compiler
Principle of longest substring
process of collecting the longest possible string of nonblank characters
Compiler
produces an equivalent program in a form suitable for execution a type of translator requires at least two steps -Source program is input to the compiler -Target program is output from the compiler
Lisp
programming language that uses the functional model of computation
John von Neumann
proposed that computers should be permanently hardwired with a small set of general - purpose operations Would allow the operator to input a series of binary codes to organize the basic hardware operations to solve more specific problems Operators could flip switches to enter these codes called machine language into memory
Regularity
refers to how well the features of a language are integrated Greater regularity implies: Fewer restrictions on the use of particular constructs Fewer strange interactions between constructs Fewer surprises in the way the language features behave Languages that satisfy the criterion of regularity are said to adhere to the principle of least astonishment Human languages including English have many irregularities
Uniformity
refers to the consistency of appearance and behavior of language constructs a design in which similar things look similar and have similar meanings while different things look different Example: extra semicolon C++ requires a semicolon after a class definition but forbids its use after a function definition
Threads
separately executed control paths within the Java system
Array
sequence of individually indexed items with the same data type
Interface
set of operations available to the user
Language syntax
similar to the grammar of a natural language
Control abstractions
simplify properties of the transfer of control Examples: loops conditional statements procedure calls
Data abstractions
simplify the behavior and attributes of data for humans Examples: numbers character strings search trees
Basic control abstractions
statements that combine a few machine instructions into an abstract statement that is easier to understand
Lexical structure
structure of language's words Similar to spelling in natural languages
Metasymbols
symbols used to describe the grammar rules Some notations use angle brackets and pure text
Invocation or procedure activation
the act of calling the procedure
Opcode
the first 4 bits of a line of code Indicates the type of operation to be performed
Leftmost derivation
the leftmost remaining nonterminal is singled out for replacement at each step Each parse tree has a unique leftmost derivation Ambiguity of a grammar can be tested by searching for two different leftmost derivations
Lexics
the lexical structure of a programming language
Scanning phase
the phase in which a translator collects sequences of characters from the input program and forms them into tokens
Parsing phase
the phase in which the translator processes the tokens, determining the program's syntactic structure
Derivation
the process of building in a language by beginning with the start symbol and replacing left - hand sides by choices of right - hand sides in the rules
Declaration
the process of giving a variable a name and a data type
Writability
the quality of a language that enables a programmer to use it to express computation clearly correctly concisely and quickly
Lexical structure
the structure of the tokens or words of a language Related to but different than the syntactic structure
Runtime environment
the system implementation of the program Stores information about the condition of the program and the way procedures operate
Compiler
translates programming language statements into machine code ALGOL was the first language to receive a formal specification or definition Included a grammar that defined its features for both programmers and for compiler writers
Recursive descent parsing
turns nonterminals into a group of mutually recursive procedures based on the right-hand sides of the BNFs
Variables
use of symbolic names to hide computer memory locations containing data values
Single symbol lookahead
using a single token to direct a parse
Efficiency
usually thought of as efficiency of the target code Example: strong data typing enforced at compile time means that the run time does not need to check the data types before executing operations
Arguments or actual parameters
values supplied by the caller for the parameters
Parameters
values that can change from call to call
Terminals
words or token symbols that cannot be broken down further
Virtual machine
written differently for different hardware architectures Byte code is machine - independent Examples: Java Python
ALGOL
ALGOrithmic Language released in 1960 Provided a standard notation for computer scientists to publish algorithms in journals Included structured control statements for sequencing begin - end blocks loops for loop and selection if and if - else statements Supported different numeric types Introduced the array structure Supported procedures including recursive procedures
