Syntax Flashcards
What is the difference between syntax, semantics, and pragmatics?
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
What is a Context Free Grammar (CFG)?
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)
In a CFG what is a derivation sequence for a string?
A sequence of production rules followed to get from the starting nonterminal to the desired string
In a CFG what is a Derivation tree?
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.
What is an unambiguous grammar?
A grammar that for each string, there is only one derivation tree
Name a few examples of well-formedness requirements on programs that can not be captured with CFGs
- An identifier must be declared before its use
- The number of parameters of a call of a function agrees with the number of parameters of its definition
- The type of expression assigned to a variable must be compatible with the variable’s type
- A variable must be assigned before it is used
Compilation is done in a cascade of phases, name those phases:
(Not very important for the exam…)
- Lexical analysis:
break a string down into a sequence of tokens - Syntactical analysis:
build a derivation tree - Semantic analysis
Check that the tree is ok from the contextual perspective - Generation of intermediate forms
- Optimization
- Code generation