Syntax Flashcards

1
Q

What is the difference between syntax, semantics, and pragmatics?

A

Syntax: What makes correct phrases of different types, Lexicon = what makes correct words, Phrase-level syntax = what makes correct phrases out of words

Semantics: What phrases of different types mean

Pragmatics: What is the force of phrases of different types when used

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

What is a Context Free Grammar (CFG)?

A
A context-free grammar is 
G = (NT, T, R, S) Where:
NT is a finite set of nonterminals
T is a finite set of terminals
R is a finite set of production rules
S is the starting nonterminal. is an element of NT and corresponds to the syntactic category of a full sentence

Another name for a CFG is Backus-Naur form (BNF)

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

In a CFG what is a derivation sequence for a string?

A

A sequence of production rules followed to get from the starting nonterminal to the desired string

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

In a CFG what is a Derivation tree?

A

A tree for a string w where the leaves are labelled with terminals, the root is the start nonterminal and each parent branches according to some production rule.

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

What is an unambiguous grammar?

A

A grammar that for each string, there is only one derivation tree

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

Name a few examples of well-formedness requirements on programs that can not be captured with CFGs

A
  1. An identifier must be declared before its use
  2. The number of parameters of a call of a function agrees with the number of parameters of its definition
  3. The type of expression assigned to a variable must be compatible with the variable’s type
  4. A variable must be assigned before it is used
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Compilation is done in a cascade of phases, name those phases:

(Not very important for the exam…)

A
  1. Lexical analysis:
    break a string down into a sequence of tokens
  2. Syntactical analysis:
    build a derivation tree
  3. Semantic analysis
    Check that the tree is ok from the contextual perspective
  4. Generation of intermediate forms
  5. Optimization
  6. Code generation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly