I actually miss a general discussion section on this forum, so I will put this topic here (don't accuse me of putting it in the wrong place).
Ever since I started programming with Pascal I wondered about the IF construct, specifically the absence of a combined ELSE IF for elseif blocks. There are languages that use one keyword for it (VisualBASIC, Python, PHP), usually something like ELSEIF or ELSIF.
When Wirth designed the language he probably figured that backtracking or two-pass techniques, as most compilers do today, would not be an option. However, there is a way to combine the ELSE IF keywords (which would prevent the inevitable nesting of IF statements) without back tracking or doing multiple passes.
As soon as the parser finds the ELSE keyword, a fixed branch-out label can be set. It doesn't matter how many ELSE IF's will follow; they either jump to the next ELSE IF (if the condition is false) or they branch out to the fixed label. The only price to pay is a redundant label if the final ELSE IF block is not followed by a ELSE block.
To illustrate this design, here is a code snippet (not programmed in Pascal):
lex.getoken()
ep_evalbool()
l1 = newlabel() ' L0
emitln("JE " + l1)
st_block(el)
expectoken(tkKeyword.nEnd)
ln = l1 ' L0
if (lex.cutoken.id = tkKeyword.nElse) then
l1 = newlabel() ' L1 (fixed)
do
emitln("JMP " + l1)
postlabel(ln) ' L0, L2, L3, ...
lex.getoken()
if lex.cutoken.id = tkKeyword.nIf then
lex.getoken()
ep_evalbool()
ln = newlabel()
emitln("JE " + ln)
st_block(el)
expectoken(tkKeyword.nEnd)
if lex.cutoken.id <> tkKeyword.nElse then
postlabel(ln)
exit do
end if
elseif lex.cutoken.id = tkKeyword.nDo then
st_block(el)
expectoken(tkKeyword.nEnd)
exit do
end if
loop
end if
expectoken(tkSymbol.nSemicolon)
postlabel(l1)
While slightly more complex than Pascal's IF .. THEN .. ELSE, it would still make among the fastest compilers today.