Opened 13 years ago

Closed 4 years ago

#1686 closed defect (wontfix)

Unclear parse error message when missing equation

Reported by: Peter Aronsson Owned by: Peter Aronsson
Priority: high Milestone: Future
Component: Parser Version:
Keywords: Cc: Peter Aronsson

Description

When you forget to add the equation keyword for an equation section you get a strange parse error message.

model Test

Real x;

x = 1;

end Test;

Gives:
No viable alternative near token 'x'

It would be nice if the error message gave a hint that perhaps 'equation' was missing.

Change History (6)

comment:2 by Martin Sjölund, 13 years ago

I'll see if we can do something about this, but it probably won't say that equation was missing since this looks more like it should be corrected to:
x var = 1; or ty x = 1;

Maybe one could try to add equation keyword in an extra backtracking phase, but I fear that would slow down the parser quite a bit or make it ambiguous

comment:3 by Peter Aronsson, 13 years ago

Some other examples:

model test "Missing 'equation'"

Pin p,n;

connect(p,n);
end test;

model test2 "Missing 'algorithm'"

Real x;

x := x+1;
end test2;

model test3 "Missing 'algorithm'"

Real x;

Modelica.Utilities.Streams.print(String(x));
end test3;

comment:4 by Martin Sjölund, 13 years ago

[MissingEquation.mo:5:3-5:9:writable] Error: Parse error: Found the start of a connect equation but expected an element (are you missing the equation keyword?)

But the others require backtracking and I think we should accept the error ANTLR chooses for us.

comment:5 by Dietmar Winkler, 9 years ago

Cc: petar, → petar
Milestone: Future

comment:6 by Per Östlund, 4 years ago

Resolution: wontfix
Status: newclosed

Closing this since it doesn't seems like something that will ever be fixed. Syntax errors are hard to give good errors for since you don't know what the user intended. In this case it could be a missing equation or algorithm, but it could also be a missing type before x or something else entirely.

Note: See TracTickets for help on using tickets.