Lecture 3 Flashcards
What does a lexical analyser do?
Reads sequence of characters and outputs sequence of tokens
What does a parser do?
Reads sequence of tokens and outputs a structured internal representation of the program. A syntax tree
What is interpretation?
Execution according to language semantics
What is compilation?
Code generation according to language semantics
What is a leftmost derivation?
A derivation where the leftmost non-terminal in each step is replaced
When is a syntax unambiguous?
When sequences of tokens only have one possible syntax tree.
How can we avoid ambiguity?
precedence for operators
Associativity of operators: left- or right associative.
<expression> ::= <int> | <expression> <op> <int>
Enforce parentheses around expressions.
<expression> ::= (<expression> <op> <expression>)
</expression></op></expression></expression></int></op></expression></int></expression>
What is scanning?
Translating a process from sequence of characters to sequence of tokens.
characters -> lexemizer -> sequence of lexems -> tokenizer -> sequence of tokens
What is a model of computation?
Programming language with a formally defined syntax and semantics
What is a declarative model?
All computations are independent of any external state and are themselves stateless and deterministic.
What is the syntax of variable-value, and variable-variable unification?
<statement> ::= <id> = <value>
<statement> ::= <id> = <id>
</id></id></statement></value></id></statement>
What is the syntax of records?
<record> ::= <literal> | <literal> ( {<feature>:<id>}+ )
<literal> ::= <atom> | <name>
<feature> ::= <atom> | <bool> | <int>
features in a record must be unique
</int></bool></atom></feature></name></atom></literal></id></feature></literal></literal></record>