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>
In grammar, what is a sentential form?
A sequence of terminals and non-terminals
first sentential form is the start variable
The last is a sequence of only terminals
What are the four classes of languages?
regular
context-free
context-sensitive
unconstrained
What is a regular language?
Language generated by a regular grammar:
Regular grammar, all rules are of the form:
v ::= s w | s | e
v and w: Any non-terminals in V
s: any symbol in S
What is a context free grammar?
All rules have the form:
v ::= y
v: variable in V
y: any sequence of variables and symbols from V and S
All regular grammars are context free, not all context free grammars are regular.
What is context-sensitive grammar?
a v B ::= a y B
v: Any variable in V
a B y: Any sequence of variables and symbols from V and S
All context free are context sensitive, not all sensitive are free
What is a recursively enumerable language?
Generated by unrestricted grammar
a ::= B
a and B are any sequence of non-terminals and terminals from V and A
All context sensitive are unrestricted, not all unrestricted are context sensitice
How are the different grammars related
unrestricted > context sensitive > context free > regular
What does regular grammars define?
Defines lexemes in a language - sequence of symbols from the alphabet of individual characters
What does context free grammars define?
Defines programs, sequences ofsymbols from the alphabet of individuallexemes.