[flang-commits] [flang] [flang] Implement conditional expressions parser/semantics (F2023) (PR #186489)
Caroline Newcombe via flang-commits
flang-commits at lists.llvm.org
Tue Mar 31 13:50:49 PDT 2026
cenewcombe wrote:
> There was no `bad character ('?') in Fortran token` message. Perhaps the latest implementation that uses tokens changed the behavior, I haven't yet tried it.
@eugeneepshteyn, the `?` is now a valid token in `flang/include/flang/Parser/characters.h`, so we don't trigger this particular error. This isn't affected by today's changes to the `ConditionalExprLookahead()`, so you'll see the same result with today's version of the PR as well.
I think this is okay. The real issue with your example is the incomplete/broken string. Any incorrect use of the `?` will trigger a different error. For example:
```
> cat test_bad_question.f90
program test_bad_question
integer :: a, b, c, x
! Misuse 1: ? without enclosing parentheses
x = a ? b : c
! Misuse 2: ? without the : partner
x = (a ? b)
end program
```
Results in the following errors:
```
error: Could not parse test_bad_question.f90
./test_bad_question.f90:5:9: error: expected end of statement
x = a ? b : c
^
./test_bad_question.f90:5:3: in the context: execution part construct
x = a ? b : c
^
./test_bad_question.f90:1:1: in the context: main program
program test_bad_question
^
./test_bad_question.f90:8:10: error: expected ')'
x = (a ? b)
^
./test_bad_question.f90:8:3: in the context: assignment statement
x = (a ? b)
^
./test_bad_question.f90:5:3: in the context: execution part
x = a ? b : c
^
```
I don't think we can produce a bad token error for `?` now that it has been added a valid fortran token character, but please let me know if there is something else you are expecting to see in the error messages. I'll try checking some more test cases as well.
https://github.com/llvm/llvm-project/pull/186489
More information about the flang-commits
mailing list