KOI: Some solutions to exercise 1
Please note that these are suggested solutions.
There can be other solutions that are also correct.
Question 1
a) ...
b) ...
c)
- lexical analysis ("scanning")
- syntactic analysis ("parsing")
- semantic analysis
- intermediate code generation
- machine-independent optimization
- code generation
- machine-dependent optimization
d) ...
e) the symbol table
f) ...
Question 2
A language is defined as the set of all valid sentences ("programs", "inputs", "sequences of tokens")
that can be written (or said) in the language.
A grammar for a language is a description, typically using some form of rules,
that describes which sentences are valid in the language.
The same language can be described by many different grammars.
A parser is a computer program, or part of a computer program,
that analyzes its input to determine if it is valid in a certain language.
It usually also outputs some representation of the input, for example as a tree structure.
Question 3
Natural languages are usually much larger, much more complex,
much more general (can be used for many purposes)
and have much fuzzier limits between correct and incorrect usage, than computer languages.
Sentences in natural languages can also be much more ambiguous
(the same sentence can be interpreted in different ways)
than computer programs.
Question 4
a) ...
b) ...
c) ...
Question 5
- Scanner
- Parser
- Program execution
- Semantic analysis
- Optimizer or semantic analysis
- Linker
- Semantic analysis
Question 6
- Scanner
- Semantic analysis
- Linker
Question 7
- Scanner
- Semantic analysis
- Semantic analysis (possibly!)
- Parser
- Semantic analysis
Question 8
- Preprocessor
- Scanner
- Parser
- Program execution
- Optimizer or semantic analysis
- Semantic analysis
- Optimizer or semantic analysis
- Semantic analysis
- Linker
Question 9
Linux is free software, or open source, while the others are not.
Linux and macOS are based on, or similar to, Unix, while Windows is not.
Linux and (to a lesser extent) Windows run on many different types of hardware,
while macOS only runs on Apple computers.
Question 10
ls, rm, cp, cd, mkdir, alias, gcc, gdb, make, ...
Thomas Padron-McCarthy
(thomas.padron-mccarthy@oru.se)
October 27, 2022