October 30, 2025, 11:53:55 AM

News:

IWBasic runs in Windows 11!


Strange compiler errors

Started by Parker, January 22, 2006, 09:21:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Parker

I'm trying to write a class function that skips whitespace (tabs, comments, spaces, the BASIC _\n continuation character) but I'm getting very odd compiler errors.

Lexer::SkipWhitespace()
{
// We can skip any number of -
// - Comments
// - Spaces and tabs
// - 0x0A
// - _\n
byte ch;

wsagain:
switch (*(Lexer)this.lookahead(0))
{
case /*_*/ 95: // We have to allow the 3 types of newlines.
if ((*(Lexer)this.lookahead(1) = 0x0A and *(Lexer)this.lookahead(2) = 0x0D))
{
*(Lexer)this.input();
*(Lexer)this.input();
*(Lexer)this.input();
m_uLine++;
}
else if ((*(Lexer)this.lookahead(1) = 0x0D) or (*(Lexer)this.lookahead(1) = 0x0A))
{
*(Lexer)this.input();
*(Lexer)this.input();
m_uLine++;
}
else
{
return;
}
case /*space*/ 32:
case& /*tab*/ 9:
case& 0x0A:
*(Lexer)this.input();
case /*'*/ 39:
// Go until a 0x0A or 0x0D character.
_cagain:
ch = *(Lexer)this.input();
if (ch = 0x0A or ch = 0x0D or ch = 0) unput();
goto _cagain;
default:
return;
}

goto wsagain;
return;
}


And the output

QuoteCompiling...
Zen.src
Lexer.src
File: C:\dev\ac\Zen\Lexer.src (130) Warning: RETURN value expected.
File: C:\dev\ac\Zen\Lexer.src (163) unknown method -

File: C:\dev\ac\Zen\Lexer.src (164) unknown method -

File: C:\dev\ac\Zen\Lexer.src (165) unknown method -

File: C:\dev\ac\Zen\Lexer.src (167) unknown method -

Error(s) in compiling C:\dev\ac\Zen\Lexer.src

If I hadn't added the *(Lexer)this. part to each input and lookahead function, it gives me "Undefined function - this" errors, so does the assembler. I looked at the output, and it's trying to call $this.

Bruce Peaslee

I'm not sure I would be of any help with this, but I can't match up error line numbers with a code fragment.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

I would check your class definitions carefully, and any include files your using.
Ionic Wind Support Team

Parker

I have looked at my class definition, the function, and the assembly output quite a few times and still can't figure out what's wrong.

This is the class definition, and no includes are being used.
class Lexer
{
unsigned int m_uPos;
unsigned int m_uLen;
unsigned int m_uLine;
string *m_pText;
// Values used by a token getting method
string *m_pVal; // I want this to be a union but they aren't implemented yet :(

declare Lexer();
declare _Lexer();

declare OpenFile(string filename);
declare OpenString(string str);

declare input(),byte; // Reads a char
declare lookahead(int cnt),byte; // Reads a char without incrementing position
declare unput(); // Puts back a char
declare isend(),int;

declare GetToken(),int;
declare GetWord(),int;
/* declare GetString(),int;
declare GetNumber(),int;
declare GetOper(),int;
declare GetNL(),int;
declare GetHTML(),int;*/

// Skips whitespace
// Whitespace is defined as spaces, tabs, line comments and block comments
// Also the _\n character is accepted, but increments the line count.
// Finally, the 0x0A character is discarded. Newlines must contain a 0x0D.
declare SkipWhitespace();
}


Like I said above, it generates lots of call $this instructions. Or at least it used to until I added the *(Lexer)this. lines. Now it generates nothing or at least doesn't attempt an assemble. The lines that give compiler errors are the ones that say "case /*space*/ 32:", "case& /*tab*/ 9:", "case& 0x0A:", and "case /*'*/ 39:".

I'm really sorry if it's just a dumb error on my part, but I can't see anything at all.

Ionic Wind Support Team

Change your switch statement to:

tmp = lookahead(0);
switch(tmp)
{
...
}

Something about using a class method in the switch statment was messing it up.  Also the lookahead(0) would have been executed for each 'case' statement, probably not what you would want anyway.




Ionic Wind Support Team

Ionic Wind Support Team

And the underlying bug has been fixed now.  Still you should use the temporary variable since each case comparison will execute the switch clause.
Ionic Wind Support Team

Parker

Thanks, it's good to know I wasn't missing something obvious. It compiles fine now.