Menu

A compact form for test statements ?

2019-01-26
2019-01-28
  • Bertrand BAROTH

    Bertrand BAROTH - 2019-01-26

    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)

     
  • stan cartwright

    stan cartwright - 2019-01-27

    This assembles fine

    #chip 18f25k22,64
    if xx=1 then yy=2
    else yy=0
    

    and this
    if xx=1 then yy=2:else yy=0

     

    Last edit: stan cartwright 2019-01-27
  • Anobium

    Anobium - 2019-01-27

    No

    Like it states in the Help URL above. It will compile but the code will not be correct.

     
  • stan cartwright

    stan cartwright - 2019-01-27

    OK.
    if xx=1 then yy=2 works ...does it?

     
  • Anobium

    Anobium - 2019-01-27

    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.

     
    • Anobium

      Anobium - 2019-01-27

      Examples:

      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
  • stan cartwright

    stan cartwright - 2019-01-27

    if xx=1 then if yy=2 then zz=1
    seems to work. maybe could be extended

     
    • Anobium

      Anobium - 2019-01-27

      if xx=1 then if yy=2 then yy=1

      will not work,

       
  • Anobium

    Anobium - 2019-01-27

    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
  • Bertrand BAROTH

    Bertrand BAROTH - 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
    • Anobium

      Anobium - 2019-01-28

      What is/are the error message(s)?

       
  • Anobium

    Anobium - 2019-01-28

    I think the error(s) where braces messages.

    A correct script is attached. Please test.

     

    Last edit: Anobium 2019-01-28
  • Bertrand BAROTH

    Bertrand BAROTH - 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 ...

     
    • Anobium

      Anobium - 2019-01-28

      I am now running more tests. I will post a final version when I know the tests are ok.

       
  • Anobium

    Anobium - 2019-01-28

    An improved version that addresses the "Else ' Comment" issue. The tests I had run threw up the same issue.

    :-)

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2019-01-28

    It works ...

     
  • Anobium

    Anobium - 2019-01-28

    We will move these checks to the main code once I know we have no further improvements.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.