(A + B + C) ≠ (A + C + B​) and compiler reordering

If the optimiser does such a reordering it is still bound to the C specification, so such a reordering would become: uint64_t u64_z = (uint64_t)u32_x + (uint64_t)u32_y + u64_a; Rationale: We start with uint64_t u64_z = u32_x + u64_a + u32_y; Addition is performed left-to-right. The integer promotion rules state that in the first addition … Read more

What is the difference between LR, SLR, and LALR parsers?

SLR, LALR and LR parsers can all be implemented using exactly the same table-driven machinery. Fundamentally, the parsing algorithm collects the next input token T, and consults the current state S (and associated lookahead, GOTO, and reduction tables) to decide what to do: SHIFT: If the current table says to SHIFT on the token T, … Read more

What is the difference between a token and a lexeme?

Using “Compilers Principles, Techniques, & Tools, 2nd Ed.” (WorldCat) by Aho, Lam, Sethi and Ullman, AKA the Purple Dragon Book, Lexeme pg. 111 A lexeme is a sequence of characters in the source program that matches the pattern for a token and is identified by the lexical analyzer as an instance of that token. Token … Read more

Meaning of Android Studio error: Not annotated parameter overrides @NonNull parameter

It’s an annotation, but the correct name is NonNull: protected void onSaveInstanceState(@NonNull Bundle outState) (And also) import android.support.annotation.NonNull; The purpose is to allow the compiler to warn when certain assumptions are being violated (such as a parameter of a method that should always have a value, as in this particular case, although there are others). … Read more

Where to learn about VS debugger ‘magic names’

These are undocumented implementation details of the compiler, and subject to change at any time. (UPDATE: See GeneratedNames.cs in the C# sources for the current details; the description below is somewhat out-of-date.) However, since I’m a nice guy, here are some of those details: If you have an unused local variable that the optimizer removes, … Read more

What’s the difference between parse trees and abstract syntax trees (ASTs)?

This is based on the Expression Evaluator grammar by Terrence Parr. The grammar for this example: grammar Expr002; options { output=AST; ASTLabelType=CommonTree; // type of $stat.tree ref etc… } prog : ( stat )+ ; stat : expr NEWLINE -> expr | ID ‘=’ expr NEWLINE -> ^(‘=’ ID expr) | NEWLINE -> ; expr … Read more

How to drive C#, C++ or Java compiler to compute 1+2+3+…+1000 at compile time?

Updated Now with improved recursion depth! Works on MSVC10 and GCC without increased depth. 🙂 Simple compile-time recursion + addition: template<unsigned Cur, unsigned Goal> struct adder{ static unsigned const sub_goal = (Cur + Goal) / 2; static unsigned const tmp = adder<Cur, sub_goal>::value; static unsigned const value = tmp + adder<sub_goal+1, Goal>::value; }; template<unsigned Goal> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)