Hi Marc,
I think I may have found an issue, or at least an ambiguity, with `Continue` inside `Do … Loop` in Mercury.
I tested this minimal example:
Module Program
Sub Main(args As String())
Do
writeLn("test")
Continue Do
Loop
End Sub
End Module
This produces errors like:
- Wrong Continue modifier: can not find Do in the current context
- One of
do,For,Whileexpected, gotEnd
If I change Continue Do to just Continue, it compiles, but of course that creates an infinite loop in this minimal example, which is expected.
What seems more interesting is that in a larger simple example, Continue Do does not seem to bind correctly to the enclosing Do ... Loop. It appears the compiler/parser is not recognizing the immediate surrounding Do, even though the statement is clearly inside that loop and only nested within If ... End If blocks.
Module Program
Sub Main(args As String())
Write("What is your name? ")
Dim name As String = readLn()
If String.IsNullOrWhiteSpace(name) Then
writeLn("Name cannot be empty.")
Return
End If
writeLn($"It is nice to meet you, {name}!")
Dim age As Integer
Do
Write("How old are you? ")
Dim ageInput As String = readLn()
If Not Integer.TryParse(ageInput, age) Then
writeLn("Please enter a valid whole number for age.")
' Continue Do
Continue do
End If
If age < 0 Then
writeLn("Age cannot be negative.")
' Continue Do
Continue
End If
Exit Do
Loop
Dim gpa As Double
Do
Write("What is your GPA? ")
Dim gpaInput As String = readLn()
If Not Double.TryParse(gpaInput, gpa) Then
writeLn("Please enter a valid numeric value for GPA.")
' Continue Do
Continue
End If
If gpa < 0.0 OrElse gpa > 4.0 Then
writeLn("GPA must be between 0.0 and 4.0.")
' Continue Do
Continue
End If
Exit Do
Loop
writeLn($"So, {name}, you are {age} years old and your GPA is {gpa:F2} ... stellar!")
End Sub
End Module
So my question is:
- Is `Continue Do` unsupported in Mercury?
- Or is this a parser/compiler issue with loop association and/or error reporting?
Thanks,
Gary
