Programming Language Paradigms exam 1

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/76

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

77 Terms

1
New cards

Three Categories of Languages

Natural Human (ambiguous), Constructed Human, Programming (unambiguous).

2
New cards

Lexicon

The vocabulary of a language.

3
New cards

Syntax

The rules that govern how words combine to form phrases, clauses, and sentences.

4
New cards

Grammar

The whole system and structure of a language.

5
New cards

Semantics

The meaning of words, phrases, and sentences.

6
New cards

6 Reasons to Study Programming Language Concepts

  1. Increased ability to express ideas. 2. Better background for choosing appropriate languages. 3. Increased ability to learn new languages. 4. Better understanding of implementation significance. 5. Better use of languages already known. 6. Overall advancement of computing.
7
New cards

Scientific Programming Domain

Focuses on a large number of floating-point computations, often using arrays. (Ex: FORTRAN)

8
New cards

Business Programming Domain

Focuses on producing reports using decimal numbers and characters. (Ex: COBOL)

9
New cards

AI Programming Domain

Focuses on symbol manipulation (often using linked lists) rather than numbers. (Ex: LISP, PROLOG)

10
New cards

Systems Programming Domain

Requires high efficiency for software that is in continuous use. (Ex: C)

11
New cards

Language Evaluation Criteria (4 main)

Readability, Writability, Reliability, and Cost.

12
New cards

Readability

The ease with which a program can be read and understood.

13
New cards

Writability

The ease with which a language can be used to create programs.

14
New cards

Reliability

How well a program conforms to its specifications.

15
New cards

Cost (in language evaluation)

The total cost of a language over its lifecycle, including writing, compiling, executing, maintenance, and portability.

16
New cards

Orthogonality

A small set of primitive constructs can be combined in a small number of ways to build control and data structures. It's a key attribute affecting readability.

17
New cards

Abstraction

Ignoring the details of complex structures or operations to simplify programming. It's a key attribute affecting writability.

18
New cards

Process Abstraction

Using a subprogram (like a function or method) to avoid writing repeated code.

19
New cards

Data Abstraction

Representing complex data structures in a simplified way, such as using two pointers to represent a binary tree node.

20
New cards

Type Checking

Testing for type errors, either at compile time or runtime, to increase reliability.

21
New cards

Exception Handling

A mechanism to intercept runtime errors, take corrective action, and continue execution, thus increasing reliability.

22
New cards

Aliasing

When two or more distinct names or reference methods can be used to access the same memory cell. It is considered dangerous and reduces reliability.

23
New cards

von Neumann Architecture

The prevalent computer architecture that separates the CPU from memory, which heavily influenced the design of imperative languages.

24
New cards

von Neumann Bottleneck

The limited data transfer speed between the CPU and memory in the von Neumann architecture, which constrains the speed of computation.

25
New cards

Imperative Programming Languages

Languages with central features like variables, assignment statements, and iteration. Includes object-oriented, scripting, and visual languages. (Ex: C, Java, Python)

26
New cards

Functional Programming Languages

Languages based on applying mathematical functions to given parameters. Key concepts include avoiding state changes and using lambda calculus. (Ex: LISP, Haskell, F#)

27
New cards

Logic Programming Languages

Rule-based languages where rules are specified in no particular order. (Ex: Prolog)

28
New cards

Compilation

An implementation method where programs are translated into machine code. It features slow translation but fast execution.

29
New cards

Pure Interpretation

An implementation method where an interpreter program reads and executes source statements directly. It features slower execution but easier implementation.

30
New cards

Hybrid Implementation

An implementation method that translates high-level programs into an intermediate language, which is then interpreted. (Ex: Java, Perl)

31
New cards

Just-in-Time (JIT) Implementation

A hybrid method that initially translates programs to an intermediate language, then compiles methods into machine code when they are called.

32
New cards

Phases of Compilation

Lexical analysis, Syntax analysis, Semantics analysis, and Code generation.

33
New cards

Lexical Analysis (Phase 1)

Converts characters from the source program into lexical units (tokens).

34
New cards

Syntax Analysis (Phase 2)

Transforms the stream of tokens into parse trees to check for syntactic correctness according to the grammar.

35
New cards

Semantics Analysis (Phase 3)

Checks for semantic errors (like type mismatches) and generates intermediate code.

36
New cards

Code Generation (Phase 4)

Translates the intermediate code into the final machine code for the target machine.

37
New cards

Preprocessor

A program that processes code before compilation, often to expand macros or include code from other files (e.g., C's #include).

38
New cards

FORTRAN (1957)

The first high-level programming language, designed for scientific and engineering applications.

39
New cards

COBOL (1960)

A widely-used language focused on business applications, known for its verbosity and readability for business logic.

40
New cards

ALGOL 60

Pioneered machine independence and formal syntax definition (BNF), becoming a foundational language for modern imperative languages.

41
New cards

SIMULA 67

The first language to support data abstraction, introducing the core concepts for object-oriented programming.

42
New cards

C (1972)

A powerful and efficient language developed for systems programming at Bell Labs.

43
New cards

Prolog (1972)

The most well-known logic programming language, based on formal logic.

44
New cards

Ada (1983)

A large, complex language sponsored by the U.S. Department of Defense (DoD) for developing reliable, long-lived embedded systems.

45
New cards

Syntax vs. Semantics

Syntax is the form or structure of expressions and statements, while Semantics is their meaning.

46
New cards

Lexeme

The lowest-level syntactic unit of a language, like a variable name, an operator, or a literal value (e.g., sum, +, 10.5).

47
New cards

Token

A category of lexemes, such as identifier, operator, or literal.

48
New cards

Language Generators vs. Recognizers

Generators produce all valid sentences of a language (a top-down approach). Recognizers determine if a given string is a valid sentence in the language (a bottom-up approach).

49
New cards

BNF (Backus-Naur Form)

A formal notation for describing the syntax of a language using rules, non-terminals (abstractions), and terminals (lexemes/tokens).

50
New cards

Left Recursion Problem

A grammar rule like A -> A + B is left-recursive and will cause an infinite loop in a top-down parser. It must be eliminated.

51
New cards

Derivation

The process of repeatedly applying grammar rules, starting from the start symbol, to generate a sentence.

52
New cards

Sentential Form

Any string of symbols (terminals and/or non-terminals) that appears in a derivation.

53
New cards

Sentence (vs. Sentential Form)

A sentential form that contains only terminal symbols.

54
New cards

Leftmost vs. Rightmost Derivation

In a leftmost derivation, the leftmost non-terminal is always the one replaced. In a rightmost derivation, the rightmost non-terminal is replaced.

55
New cards

Ambiguous Grammar

A grammar that can generate two or more distinct parse trees for the same sentence, leading to multiple possible interpretations.

56
New cards

How to Remove Ambiguity

  1. Specify precedence: Ensure operators with lower precedence are further from the leaves (closer to the root) of the parse tree. 2. Specify associativity: Use recursion on only one side of a rule (e.g., expr -> expr + term is left-associative).
57
New cards

EBNF: [ ]

In Extended BNF, square brackets enclose optional parts of a rule.

58
New cards

EBNF: ( ) |

In EBNF, parentheses group elements, and the vertical bar | separates choices within the group.

59
New cards

EBNF: { }

In EBNF, braces denote zero or more repetitions of the enclosed element.

60
New cards

Lexical Analyzer Role

It acts as the "front-end" of the parser. It's a pattern matcher that groups characters into lexemes and passes the corresponding tokens to the syntax analyzer.

61
New cards

Syntax Analyzer (Parser) Role

It checks if the stream of tokens from the lexical analyzer forms a valid sentence according to the language's grammar, typically by building a parse tree.

62
New cards

Top-Down Parsing (LL)

Parsing starts at the root of the parse tree (the start symbol) and grows towards the leaves. It scans the input Left-to-right and produces a Leftmost derivation.

63
New cards

Bottom-Up Parsing (LR)

Parsing starts at the leaves of the parse tree and reduces them up to the root. It scans the input Left-to-right and produces a reverse Rightmost derivation.

64
New cards

Handle

The leftmost simple phrase in a sentential form, which is the part of the string to be reduced in the next step of bottom-up parsing.

65
New cards

Parser Complexity

The runtime complexity for parsers of general unambiguous grammars can be O(n

66
New cards

3

67
New cards

), but parsers for common programming languages are typically in a subset that can be parsed in linear time, O(n).

68
New cards

LR Parser Actions (4)

  1. Shift: Push the next input symbol onto the parser stack. 2. Reduce: Replace a handle on the stack with its corresponding non-terminal. 3. Accept: Parsing is complete and successful. 4. Error: A syntax error was found.
69
New cards

Static Semantics

The semantic rules that can be checked at compile time, such as type compatibility.

70
New cards

Dynamic Semantics

The meaning of expressions, statements, and program units, which can only be determined at runtime.

71
New cards

Attribute Grammar

A formal approach to static semantics where a context-free grammar is augmented with attributes (to hold semantic info), functions (to compute attribute values), and predicates (to check rules).

72
New cards

Synthesized vs. Inherited Attributes

Synthesized attributes pass semantic info up the parse tree (bottom-up). Inherited attributes pass info down the tree (top-down).

73
New cards

Operational Semantics

Defines the meaning of a program by describing its effects on a hypothetical machine (i.e., the sequence of state changes it causes).

74
New cards

Denotational Semantics

A highly rigorous method that defines the meaning of language constructs by mapping them to mathematical objects (like functions).

75
New cards

Axiomatic Semantics

Defines the meaning of statements based on formal logic, using assertions about the program state.

76
New cards

Precondition vs. Postcondition

A precondition is a logical assertion that must be true before a statement executes. A postcondition is an assertion that is true after it executes.

77
New cards

Weakest Precondition

The least restrictive precondition that will guarantee the validity of the associated postcondition.