Error: expected "="

General FreeBASIC programming questions.
Post Reply
PIBasic
Posts: 2
Joined: Jul 29, 2018 1:14

Error: expected "="

Post by PIBasic »

Hello. I was trying to compile a BASIC program that let users create a custom tecxt loop with the newest version of FreeBASIC. When I compiled it, I got this error.

Code: Select all

pi@raspberrypi: ~/Desktop/FreeBASIC $ fbc -lang deprecated customloop.bas
customloop.bas(14) error 10: Expected '='
140 pause
    ^
customloop.bas(19) error 10: Expected '='
190 pause
    ^
Here is the BASIC code:

Code: Select all

10 cls
20 print "How many times to show?"
30 input "", a%
40 print "What will the phrase be?"
50 input "", b$
60 print "Show number? (y/n)"
70 input "", c$
80 cls
90 if c$="y" then
100 for d=1 to a%
110 print b$;
120 print " ";
130 print d%
140 pause
150 next d
160 else
170 for d=1 to a%
180 print b$
190 pause
200 next d
210 end if
220 e$=STRING$(10,45)
230 print e$;
240 print "Press enter to end.";
250 print e$
260 end
Can someone please help diagnose and fix the issue?
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: Error: expected "="

Post by speedfixer »

Hi, PIBasic, Welcome to FreeBASIC.

Simply: there is no FB 'pause' command

Perhaps you wanted: sleep?


David
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Error: expected "="

Post by Tourist Trap »

If I'm allowed, I would express this with slightly more detail just in case. There is not such a thing as PAUSE predefined routine or command in FB (and you neither defined one yourself in the program). So FB interprets it as a variable name. And no variable can stand alone like this being like a sitting duck in FB. A routine, a procedure, or said differently, a function could. But not a variable.

For this reason FB compiler's warns you that it won't compile that. And it tries to guess where you are mistaken. Granted that you are writing a variable name and not a command (routine ..etc..), the compilers think that you certainly want to assign a value to it. Said differently again, FBC is waiting for something like that:

Code: Select all

pause = 123
As a matter of comment from my part. It's a current thing that the compiler is not guessing well when it comes to your real intentions. So you do well asking here what other people think ;)

Hum, I maybe am going long now. But once again to complete the answer of the respected precedent answerer, you can use SLEEP or GETKEY.
Getkey differs from sleep because if you press a key Getkey will eat it. Sleep is leaving the key you press (at keyboard) pass over, and said once again differently, this key pressed will still be in the buffer for the following of the program (if it doesn't terminate just here). Simple detail but very important sometimes!
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Error: expected "="

Post by counting_pine »

This error can also be seen in the default FB dialect, but only if the variable is declared:

Code: Select all

test1 '' Variable not declared
dim test2 as integer
test2 '' Expected '='
At a guess, I would say that when FB sees a single variable on a line, it tries (and fails) to parse it as many kinds of statement - including a sub/function call - which presumably fails because there are no subs/functions with that name.

Then, as a final catch-all, it parses it as an assignment ('lhs = rhs').
(It does assignments last, I think, because they're harder to detect in the parser - particularly when the lhs (left hand side) is a complex expression (potentially involving pointers/arrays/function calls). So it tries other kinds of statement first to rule them out, ensuring that by the time it parses it as an assignment, it knows it isn't anything else.)

At this point it finds the variable (the 'lhs' of the assignment) is undeclared. At this point in the default dialect (or Option Explicit), it gives an error that it's undeclared. But in other dialects, it implicitly declares the variable first.
After that, with the variable declared, it then continues parsing the line as an assignment, which quickly fails due to the lack of '='.
PIBasic
Posts: 2
Joined: Jul 29, 2018 1:14

Re: Error: expected "="

Post by PIBasic »

Working fine now! Thanks!
Post Reply