Lecture 2 Flashcards

1
Q

What is a programming paradigm?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is imperative programming?

A

Program is a sequence of statements

Statements updates the state of variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is object-oriented programming?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is functional programming?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is logic programming?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does a kernel language define?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What doe String.strip do?

A

Strips off leading or trailing white spaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does String.split do?

A

Splits string by whitespaces and returns a list of the strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a record?

A

Data structure with a label and a number of named, or numbered, fields

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does String.toAtom do?

A

Convert a string to an atom.
Useful when creating records.

a = “plus”

cmd({String.toAtom a}) = cmd(plus)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a formal language?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is grammar?

A

Rules specifying how to construct a string that is syntactically valid (a string that belongs to the language defined by the grammar)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the components of a formal grammar?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When is a grammar incomplete?

A

When there exist an nonterminal for which there are no rule that defines how it can be constructed by the available symbols.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe the EBNF

A

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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In grammar, what is a sentential form?

A

A sequence of terminals and non-terminals

first sentential form is the start variable

The last is a sequence of only terminals

17
Q

What are the four classes of languages?

A

regular

context-free

context-sensitive

unconstrained

18
Q

What is a regular language?

A

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

19
Q

What is a context free grammar?

A

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.

20
Q

What is context-sensitive grammar?

A

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

21
Q

What is a recursively enumerable language?

A

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

22
Q

How are the different grammars related

A

unrestricted > context sensitive > context free > regular

23
Q

What does regular grammars define?

A

Defines lexemes in a language - sequence of symbols from the alphabet of individual characters

24
Q

What does context free grammars define?

A

Defines programs, sequences ofsymbols from the alphabet of individuallexemes.