Some of the stuff I'm doing in Concepts of Programming is over my dad's head because the next generation is expected to be smarter than the last generation. Regardless, I've been working on a project which I need to get done by December 2nd. It's rather complex. It's supposed to be a Parser and Lexical Analyzer for a basic language known as Eiffel. So far I have fixed all the compile errors with the help of my professor's website and example files (I don't think any books about Ada ever cover how to create a parser or lexical analyzer). I built the exe, ran it, and it turns out that I get an error that reads like this:
raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : failed precondition from lexical_analyzers.ads:20
Specified here in the code in lexical_analyzers.ads inside this zip file:
https://drive.google.com/file/d/0B3ZPyNRv7C3heEN1cnU3dVFOZmM/view?usp=sharing
Line 20, maybe even line 17 above it, is experiencing errors. It may have to do with the way I must have wrote the parser.adb file. This language works very similarly to the C languages in that you need to write a spec file before writing the main body file, sometimes going back and forth as I code. Should I also specify every method I wrote in the parser.adb file in the parser.ads file? I think so, that's how the language works. Do you guys have any other ideas as to why I am getting this error?
The error means pretty much what it says: you have a precondition that failed. The code on line 20 looks like
more_tokens(lex)
is the precondition. This means that if you callget_next_token
, there have to be more tokens, or else the precondition will fail.What this means is that the specification is telling the rest of the program, "Don't call
get_next_token
unless you are sure there are more tokens in the file". So whenever you call it, the caller should have already checkedmore_tokens(lex)
, and taken appropriate action if there no more. It looks like you're not doing that, though, inparsers.adb
. This means that eitherparsers.adb
needs to be modified to make sure it doesn't callget_next_token
without checking first (or somehow else knowing that there are more); orthe precondition shouldn't be there, and
get_next_token
needs to be redefined so that it's allowable to call it when there are no more tokens, perhaps by settingtok
to a special token that indicates "end-of-input".Please tell all your classmates that you had to have a 53-year-old help you. (Take that, Zuckerberg.)