Swordfish Language Grammar question

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Swordfish Language Grammar question

Post by octal » Fri Nov 16, 2007 9:17 pm

Hi,
In the help file, some block structures like If/EndIf are defined as

If Expr Then Statement(s) EndIf

The problem is the close tag for this block. EndIf is mentioned as a single word, i.e. NO Space between END and IF.

I also checked all codes by David and they all are written with EndIf as a single word, but the compiler seems to accept "End<Space>If" writen in two words separated by spaces.
1- Is this a side effect or does really the compiler accept such syntax?
2- If the answer is YES the compiler accept such syntax, does this work for ALL such constructs (End Select, End If, ... - all End-Something) ?

Regards
octal

johngb
Registered User
Registered User
Posts: 139
Joined: Tue Oct 03, 2006 10:16 pm

Post by johngb » Sat Nov 17, 2007 9:47 am

Does it compile correctly? - I have noticed this but I think the compiler is seeing it as and End statement and the If as a new If.

Just checked - you are right. I think this is new because I am pretty sure earlier versions insisted of EndIf as a single word.

It makes it more consistent with the other End statements as they are all two word statements.
JohnB

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Sat Nov 17, 2007 10:21 am

Hi Johngb,
johngb wrote:Does it compile correctly?
Yes it does compile correctly.
johngb wrote:I think the compiler is seeing it as and End statement and the If as a new If.
I do not think, since the END closes the main prog. here it compiles correctly and nested structures also compile correctly.
johngb wrote:I think this is new because I am pretty sure earlier versions insisted of EndIf as a single word.
I do not know. I have known SF from version 2.0 and I have loaded very old programs I coded with it, and I have just noticed that I always wrote it as two words (End + If, End+Select). This behaviour is not that new I think.

Regards
Octal

johngb
Registered User
Registered User
Posts: 139
Joined: Tue Oct 03, 2006 10:16 pm

Post by johngb » Sat Nov 17, 2007 10:29 am

Maybe I am confusing it with VB. When there are so many flavour of basic around its easy to mix up dialects.
JohnB

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Sat Nov 17, 2007 10:42 am

"end if" can be used - which keeps the language consistent with other "end" constructs. For example, "end with", "end sub", "end function" etc. However, "endif" is such a common terminator for many other languages that I decided to include it in Swordfish. In summary, "end if" and "endif" are both correct.

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Sat Nov 17, 2007 11:04 am

Thanks David. :cry: I was affraid from this answer.
This means more work on my IDE for folding support :cry:

regards
octal

xor
Posts: 286
Joined: Sun Nov 05, 2006 1:15 pm
Location: NYC
Contact:

Post by xor » Sat Nov 17, 2007 2:33 pm

If you are checking text wouldn't you only have to test the first three characters for a match of "End" in all cases and that be enough? This should remain consistent for all tests I believe. The second half is understood based on its position in the code. Much like how For-Next works, and Next does not have to declare its counter variable.

Maybe all of this is obvious and I probably really don't understand how text searching is done or the amount of work that goes into it.

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Sat Nov 17, 2007 6:40 pm

xor wrote:If you are checking text wouldn't you only have to test the first three characters for a match of "End" in all cases and that be enough? This should remain consistent for all tests I believe. The second half is understood based on its position in the code. Much like how For-Next works, and Next does not have to declare its counter variable.

Maybe all of this is obvious and I probably really don't understand how text searching is done or the amount of work that goes into it.
Hi Xor,
it's not that trivial. Checking only the 3 chars (E.N.D) is not the correct way to procede. I have to check for EndIf or for END+<Identifier> where the <Identifier> is the same that opened the structure (If/End-IF, Structure/End-STRUCTURE, ...).
In fact, I'm using syntaxic rules to create folding regions (regions that can be collapsed/expanded with + and - signs) and to draw vertical lines that shows code structure.
Vertical lines are intended to makes code structure visible in order to avoid to user wrong structures nesting. If I rely only on E.N.D, I will draw wrongly overlapped structures.
For example if the user writes

Code: Select all

IF condition then
  SELECT var
     CASE c1: ...
     CASE c2: ...
  END IF     // Wrongly closed IF
END SELECT  // Wrongly closed SELECT
In this code, If I test only END keyword you can easily see that I'll fold code wrongly. This will make the vertical lines drawing errenous, when it's supposed to help user by spoting out quickly the bad constructs.

Also we can not easily generalize the END <identifier> approach to all SF grammar elements because Functions and Subs, (in contrast to events and interrupts) are problematic, really problematic because of the existance of the wonderfull "compound" keyword. Trust me, (I really think) "compound" is a wonderfull thing in SF for the programmer, but is a damn hell for me as an IDE writer and for my Syntax Rule Engine, and the same for the FORWARD keyword for functions prototype. These two "kind" of func/Sub (compound and Forward) does not have a body, I have to skip them. So simply scanning the END keyword is not a solution :(

Making a nice IDE is becoming a hell for me. I"ll have to thinks things more deeper ! :evil:

Regards
octal

xor
Posts: 286
Joined: Sun Nov 05, 2006 1:15 pm
Location: NYC
Contact:

Post by xor » Sat Nov 17, 2007 7:14 pm

It appears that you are trying to manage errors before the compiler finds them. In that case, I better understand your tribulations.

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Sat Nov 17, 2007 7:20 pm

Hi,
Yes xor, the aim is that the editor provides as much help as possible before the user compiles his program. Syntax highlighting already provides a maximum help, I added to that code folding, vertical code strucutre lines drawing and braces matching highlighting. I think that this already helps a lot at avoiding the most common errors. Code completion and params highlighting in info tooltips, if implemented, will also help a lot (but I'm far from that now :? it's not that easy).

regards
octal

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Sun Nov 18, 2007 12:53 am

Thanks everybody. Now it works fine ;) I support both syntax .

regards
octal

Post Reply