Compiler Week 3
Instead of the manual method described below, there is a productivity extension for controlling video playback rate with keyboard shortcuts:
Video Speed Controller
To set the YouTube video playback rate to some particular number, e.g., , execute the following command in the browser's console; use Command + Option + J
or Control + Shift + J
to access Chrome's console.
What this actually does is setting the playback rate of the first <video>
tag on the page to , which happens to be the main video on any YouTube page.
Many links in this page refer to text fragments which are known to work on Chrome 80 and above.
I can't say about other browsers.
Q&A
Classify the following as front-end or back-end components
- Target code optimizer: back-end
- Parser: front-end
- Scanner: front-end
- IR code generator: front/middle-end
- Type checker: front-end
Classify 1-3 as (a) or (b)
(a) a common back-end compiling system
(b) a retargetable compiler
- HP PA-RISC compiler/optimizer: (a)
- Intel C++ Compiler Classic (ICC): (a) for C/C++ (b) for x86/x64
- According to the developer's guide, ICC actually stands for Intel C++ Compiler Classic.
- x86 refers to IA-32 whereas x64 refers to IA-64
- GNU Compiler Collection (GCC): (b)
How to create the first C compiler on the Itanium machine?
How to create the first C compiler on the new Itanium if no cross-compiler is available?
Incremental bootstrapping.
- Craft a simple assembler, C1, in Itanium machine code, i.e., directly editing a binary file from scratch.
- Craft a more complex assembler, C2, in Itanium assembly with C1.
- Craft a simple C compiler, C3, with C2.
- Craft a more complex C compiler, C4, with C3.
- Continue step 4 for several iterations until a good enough C compiler, C0, is finally produced.
Then, C0 is what we seek for.
Evaluate 1u > -1
in C/C++
Comparing unsigned int
with int
is defined behavior in C/C++: int
is coerced to unsigned int
for comparison.
Since -1 has all bits being 1 in 2's complement, 1u > -1
evaluates to false
in most cases.
In fact, C++20 mandates that all values be represented in 2's complement.
Here are more C++ specific details.
1u
and -1
are integer literals that are of type unsigned int
and int
, respectively.
- Coercion of mismatched operand types of an arithmetic (comparison) operator is called usual arithmetic conversion.
In this case, usual arithmetic conversion is due to the unsigned operand's conversion rank being equal to the conversion rank of the signed operand, thus, requiring the signed operand to be converted to the unsigned operand's type where the conversion rank of any unsigned type is equal to the rank of the corresponding signed type.
- For best practices, consult the Arithmetic section (consists of only 8 points; highly recommended) of C++ Core Guidelines.
Honorable mentions:
- ES.100: Don’t mix signed and unsigned arithmetic.
- ES.101: Use unsigned types for bit manipulation.
- ES.102: Use signed types for arithmetic.
- ES.106: Don’t try to avoid negative values by using
unsigned
.
- In fact, the C++ standard library devoted a whole class –
std::bitset
– to bit manipulation.
- For safer integral comparisons, C++20 provides
std::cmp_{equal,not_equal,less,greater,less_equal,greater_equal}
.
- C++20 also provides safer math constants belonging to the namespace
std::numbers
.
Which of the following are in the language defined by the AC syntax?
What is the associativity of op
given the grammar expr -> expr op primary
? How can the grammar be re-defined so as to invert the associativity of op
?
- Left associative.
expr -> primary op expr
Identify expressions with constant folding potential