Brice Stacey home

Nested If/Else Statements Produce Unexpected Behavior using EZproxy 5.1c

I was touching up our EZproxy user authentication and I ran into a problem using If/Else clauses. Essentially, If/Else clauses do not nest properly. Here is an example:

::Common
if (0 == 1) {
  msg "0 == 1 TRUE"
  if (1 == 1) {
    msg "Inner IF"
  } else {
    msg "Inner ELSE"
  }
} else {
  msg "1 == 1 FALSE"
}
/Common

Once executed, I would expect "1 == 1 FALSE" to be output. Here is what I get:

"Inner ELSE"
"1 == 1 FALSE"

I don't exactly know what is going on. From my experiences writing programs that parse highly generic text structures (exercises 1-23 and 1-24 from the K&R come to mind), I'd just like with wish the debugger good luck. And for any developer out there wishing to write your own language and interpreter to embed in your product, don't do it. Instead, use an existing language with all its libraries removed.

Luckily, this can be avoided by rewriting nested If/Else statements as two If statements, one true and the other false. Here is an example:

::Common
if (0 == 1) {
  msg "0 == 1 TRUE"
  if (1 == 1) {
    msg "Inner IF"
  }
  if (1 != 1) {
    msg "Inner ELSE"
  }
} else {
  msg "1 == 1 FALSE"
}
/Common

This gives the appropriate output:

"1 == 1 FALSE"