-->
Page 1 of 1

Spaces!

PostPosted: Fri Mar 24, 2017 1:33 pm
by PhilTilson
As many correspondents do, I would like to thank Mike for his sterling efforts in producing ESPbasic thus far. Given the amount of work it must entail, one is hesitant to criticise, but.... :roll:

One of the recurring problems with the syntax relates to spaces - and whether they should be there or not.

Earlier threads have already pointed out that the space in front of an "=" sign is essential. The space following, however, is not.

Yesterday I was working with file read and write, and it didn't want to play. After some frustration, it seems that write ({filename}, [data$}) does NOT work - however, write({filename}, [data$}) works fine. In other words, in this case you must NOT put a space before the opening parenthesis.

I seem to remember reading about another command recently where it was stated that a space must not be present. All this is very confusing.

I certainly don't have the necessary knowledge to write a compiler, but I have had to implement parsing in many programs in the past. One of the earliest stages was always to remove ALL spaces, except those occurring between quotes - ie strings. That way, whether a space was present or not was irrelevant.

If this is impracticable, then could we at least have some consistency? - either we ALWAYS need a space separating parts of a command or function, or we NEVER need a space in there. This would save me a lot of time!

Phil

Re: Spaces!

PostPosted: Wed Mar 29, 2017 4:20 am
by Oldbod
I agree about consistency being important, or at any rate helpful. But without looking at the source/documentation, i'm not very clear why you would expect a space to be acceptable there? Is it in other eso functions (shows own ignorance)... most languages function name is directly followed by opening bracket....

Re: Spaces!

PostPosted: Thu Mar 30, 2017 12:51 pm
by PhilTilson
most languages function name is directly followed by opening bracket.... - See more at: posting.php?mode=reply&f=42&t=14274#sthash.D8bzPZcc.dpuf

True - but in most languages, x=1 is just as acceptable as x = 1 or even x =1 (both the latter work happily in ESPbasic!)

In fact, in most languages, spaces are irrelevant, and x...=....1 would be quite valid (had to use dots instead of spaces as the forum editor took them all out!!) - that's what I meant about removing all spaces (except those in strings) before parsing the command. In general, spaces should be optional either side of tokens.