Swordfish Language Grammar question
Moderators: David Barker, Jerry Messina
Swordfish Language Grammar question
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
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
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.
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
Hi Johngb,
Regards
Octal
Yes it does compile correctly.johngb wrote:Does it compile correctly?
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 the compiler is seeing it as and End statement and the If as a new If.
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.johngb wrote:I think this is new because I am pretty sure earlier versions insisted of EndIf as a single word.
Regards
Octal
- David Barker
- Swordfish Developer
- Posts: 1214
- Joined: Tue Oct 03, 2006 7:01 pm
- Location: Saltburn by the Sea, UK
- Contact:
"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.
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.
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,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.
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
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 !
Regards
octal
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
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