Conditional expressions
Hi! First of all: Happy New Millennium! :-) Peter and I are discussing the possibility of including some kind of conditional operator, like `foo ? bar : baz' in C. Since GPC uses GCC's backend, this should be easy to do semantically, the main question is about syntax: - ?: like in C -- the symbols wouldn't conflict AFAICS, but it seems to me quite un-Pascalish... - if foo then bar else baz (i.e., the same syntax as conditional statements, just with expressions, e.g. `x := if cond then 42 else 17'). Possible problems: * dangling else (probably not since each conditional operator will be required to have an else clause) * conflicts with `if' statements when nested into them (maybe not either for the same reason) * issues with precedence (compared to other operators) and associativity (i.e., how nested conditional operators will be interpreted) -- C has the same issues and resolves them with some rules, but like all such issues, they can confuse programmers sometimes (think of precedence of `and' and `or')... - if foo then bar else baz endif (or `fi' instead of `endif') -- this would avoid all the problems and make the syntax somewhat clearer I think... - if foo then bar else baz end -- the same, but without introducing a new reserved word (of which there are already way too many), and `end' is unambiguous in this context AFAICS. - Peter seems to remember that other Pascal compilers and related languages have something like this. Does someone know anything about these? Maybe we don't have to reinvent the wheel... - Other suggestions? Frank -- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/ GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html
participants (5)
-
Clive Rodgers -
Frank Heckenbach -
J. David Bryan -
Maurice Lombardi -
Prof. Abimbola Olowofoyeku (The African Chie