Yes. I would not use ELSE on the same line. Unless someone wants to test the complete range of chips - that is about 10 tests and 10 examination of the ASM
Play safe.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Errors - these errors are issued from the preprocessor, so, if you pass the source direct to the compiler you will get different errors.
#chip 18f25k22,64
if xx=1 then: yy=2
else: yy=0
end if
gives
New.gcb (2): Error: Syntax Error
New.gcb (3): Error: Else outside of If ... End If block
New.gcb (4): Error: End If without If
Next, compiling this code. No errors.
#chip 18f25k22,64
if xx=1 then yy=2
else yy=0
gives totally incorrect ASM... variable called ELSEYY is created.
;Start of the main program
;if xx=1 then yy=2
decf XX,W,BANKED
btfss STATUS, Z,ACCESS
bra ENDIF1
movlw 2
movwf YY,BANKED
ENDIF1
;else yy=0
clrf ELSEYY,BANKED
This ASM is generated because I removed the ELSE preprocessor check at v0.98.01 RC01 but now after this thread I will revert as the ELSE should issue a syntax error. I will sort.
Let us try what is written in the Help.
#chip 18f25k22,64
if xx=1 then
yy=2
else
yy=0
end if
gives no errors and the correct ASM.
;if xx=1 then
decf XX,W,BANKED
btfss STATUS, Z,ACCESS
bra ELSE1_1
;yy=2
movlw 2
movwf YY,BANKED
;else
bra ENDIF1
ELSE1_1
;yy=0
clrf YY,BANKED
;end if
ENDIF1
Look out of a new preprocessor.
Last edit: Anobium 2019-01-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A new preprocessor. Rename (as a backup) and then download and install then attachment to C:\GCB@Syn\G+Stools\preprocess.awk (or, your specific folder structure).
This now prevents the following:
If condition=True Then yy=1
Else xx=2
End If
and,
if xx=1 then if yy=2 then yy=1
and, an improved handler for
else if
and , trapping
if xx=1 then yy=2:else yy=0
It may not be perfect but it will prevent some of these approaches.
Attachment removed
Last edit: Anobium 2019-01-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry but the new preprocessor does not work : try to compile the attachment ... It was copy-pasted from a complete program, with #Chip Mega8515 and variable definitions, and the error messages were the same !
In fact the errors were braces messages ; now it works fine, the only new thing I saw is an error message if I use "Else ' Comment", I have now to put the comment on the next line.
Thanks, please include this script into the next installer version ...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can the following If Statement
If condition Then
Instruction1
Else
Instruction2
End If
be written as :
If condition Then : Instruction1
Else : Instruction2
End If
? Thanks for answer(s)
No.
See https://github.com/Anobium/Great-Cow-BASIC-Help/blob/master/source/if.adoc
This assembles fine
and this
if xx=1 then yy=2:else yy=0
Last edit: stan cartwright 2019-01-27
No
Like it states in the Help URL above. It will compile but the code will not be correct.
OK.
if xx=1 then yy=2 works ...does it?
Yes. I would not use ELSE on the same line. Unless someone wants to test the complete range of chips - that is about 10 tests and 10 examination of the ASM
Play safe.
Examples:
Errors - these errors are issued from the preprocessor, so, if you pass the source direct to the compiler you will get different errors.
gives
Next, compiling this code. No errors.
gives totally incorrect ASM... variable called ELSEYY is created.
This ASM is generated because I removed the ELSE preprocessor check at v0.98.01 RC01 but now after this thread I will revert as the ELSE should issue a syntax error. I will sort.
Let us try what is written in the Help.
gives no errors and the correct ASM.
Look out of a new preprocessor.
Last edit: Anobium 2019-01-27
if xx=1 then if yy=2 then zz=1
seems to work. maybe could be extended
will not work,
A new preprocessor. Rename (as a backup) and then download and install then attachment to C:\GCB@Syn\G+Stools\preprocess.awk (or, your specific folder structure).
This now prevents the following:
and,
and, an improved handler for
and , trapping
It may not be perfect but it will prevent some of these approaches.
Attachment removed
Last edit: Anobium 2019-01-28
Sorry but the new preprocessor does not work : try to compile the attachment ... It was copy-pasted from a complete program, with #Chip Mega8515 and variable definitions, and the error messages were the same !
Last edit: Bertrand BAROTH 2019-01-28
What is/are the error message(s)?
I think the error(s) where braces messages.
A correct script is attached. Please test.
Last edit: Anobium 2019-01-28
In fact the errors were braces messages ; now it works fine, the only new thing I saw is an error message if I use "Else ' Comment", I have now to put the comment on the next line.
Thanks, please include this script into the next installer version ...
I am now running more tests. I will post a final version when I know the tests are ok.
An improved version that addresses the "Else ' Comment" issue. The tests I had run threw up the same issue.
:-)
It works ...
We will move these checks to the main code once I know we have no further improvements.