Lecture 2 Flashcards
What is a programming paradigm?
The style of programming, how solutions to problems are implemented.
Extensive use of some constructs of a language, an discourages or prohibits the use of others.
What is imperative programming?
Program is a sequence of statements
Statements updates the state of variables
What is object-oriented programming?
Objects are encapsulations of data and methods
Separation of class and instance.
Separation of state: attributes/properties and method/features
Objects send messages to each other (by calling method)
Objects executes operations when they receive messages
What is functional programming?
A program defines a set of functions.
Functions compute values based on input.
Functions can be input values and return values in other functions.
In pure functional programming: no side-effects, variables are immutable
What is logic programming?
A program is a set of logical assertions (facts and rules)
A program may read as a logical expression or as a set of operations to be executed.
An execution of a program follows an inference pattern to prove or disprove a query
What does a kernel language define?
How instructions are processed on an abstract machine.
Extensions are made by defining their translation into the kernel language or modifications to the abstract machine.
What doe String.strip do?
Strips off leading or trailing white spaces
What does String.split do?
Splits string by whitespaces and returns a list of the strings.
What is a record?
Data structure with a label and a number of named, or numbered, fields
What does String.toAtom do?
Convert a string to an atom.
Useful when creating records.
a = “plus”
cmd({String.toAtom a}) = cmd(plus)
What is a formal language?
Formal language L is a set of sequences of symbols from a finite alphabet A:
A = {s1, s2, s3, … ,sn}
L = {n1, n2, n3, …, nm | m >=0, n element A}
nm is a single (multi-)character symbol
A = {a, b}
L = {a, b, aa, ab, aba}
aa is a 2-character symbol
The string “a ab” contains 2 symbols
What is grammar?
Rules specifying how to construct a string that is syntactically valid (a string that belongs to the language defined by the grammar)
What are the components of a formal grammar?
V = {v1, v2, v3, …, vn} set of nonterminals (variables)
S = {s1, s2, s3, …, sn} set of terminals (symbols)
R = {v, t1 t2 … tn | v E V, n >=0, t E V U S}
v_s E V is the start variable (root)
Example:
V = {c}
S = {a, b}
R = {(c, e), (c, a), (c, bcb)}
v_s = c
When is a grammar incomplete?
When there exist an nonterminal for which there are no rule that defines how it can be constructed by the available symbols.
Describe the EBNF
non-terminals are defined using angle brackets <>
terminals are enclosed in quotation marks
Rules are strings containing:
- A non-terminal
- A special symbol ::=
- A sequence of terminals and non-terminals, or the symbol e
Start variable is the variable to the left of the topmost rule
{…}: appears in the string any number of times
{…}+: at least once, and any number above
{…}*: any number of times
<c> ::= e
<c> ::= a<c>a
<c> ::=b<c>b
or
<c> ::= e | a<c>a | b<c>b
variable: c
symbols: a, b
start variable: c
</c></c></c></c></c></c></c></c>