Files
harbour-core/harbour/tests/switch.prg
Ryszard Glab dde0793b53 2005-11-14 11:00 UTC+0100 Ryszard Glab <rglab@imid.med.pl>
* include/hbcomp.h
   * include/hberrors.h
   * include/hbexpra.c
   * include/hbexprb.c
   * include/hbexprop.h
   * include/hbhash.h
   * include/hbmacro.h
   * include/hbpcode.h
   * source/common/Makefile
   * source/common/expropt1.c
   * source/common/expropt2.c
   * source/common/hbhash.c
   * source/compiler/expropta.c
   * source/compiler/exproptb.c
   * source/compiler/genc.c
   * source/compiler/harbour.c
   * source/compiler/harbour.l
   * source/compiler/harbour.y
   * source/compiler/hbfix.c
   * source/compiler/hbgenerr.c
   * source/compiler/hbident.c
   * source/compiler/hbpcode.c
   * source/macro/macro.l
   * source/macro/macro.y
   * source/macro/macroa.c
   * source/macro/macrob.c
   * source/rtl/dates.c
   * source/vm/hvm.c
   * source/vm/macro.c
   + source/common/hbdate.c
   + tests/ddate.prg
   + tests/switch.prg
      +added support for DATE type constants in the following format:
         0dYYYYMMDD
      for example (see tests/ddate.prg for more):
      IF( dDate > 0d20051112 )

      +added support for SWITCH command (see tests/switch.prg)
         SWITCH <expr>
         CASE <integer_expression>
            ...
            [EXIT]
         CASE <string_expression>
            ...
            [EXIT]
         [OTHERWISE]
            ...
         END

   Notice:
      - Integer and string expressions can be mixed in a single
        SWITCH command with no runtime errors;
      - CASE expression have to be resolved at compile time and
        the result has to be either an integer or string constant
      - if there is no EXIT statement then next CASE is executed
        (or OTHERWISE for the last CASE)
      For example:
      CASE 1+32+2*4
      CASE CHR(64)
      CASE ASC('A')
      CASE "A"+CHR(13)

   Notice:
      The above changes apply only to FLEX version!
2005-11-14 09:47:46 +00:00

116 lines
1.6 KiB
Plaintext

#ifdef __XHARBOUR__
#define OTHERWISE DEFAULT
#endif
PROCEDURE MAIN
LOCAL a:=1
PRIVATE b:="b"
#ifndef __XHARBOUR__
SWITCH a
END
#endif
?
? "1111111111111111111111111111111"
SWITCH a
CASE 1
? "FOUND: 1"
END
?
? "2222222222222222222222222222222"
SWITCH a
CASE 1
? "FOUND: 1"
EXIT
CASE "2"
? a
END
?
? "3333333333333333333333333333333"
SWITCH a
CASE 1
? "FOUND: 1"
CASE "2"
? "FOUND: 2"
OTHERWISE
? "other"
END
#ifndef __XHARBOUR__
?
? "44444444444444444444444444444444444"
SWITCH a
OTHERWISE
? "OTHERWISE"
END
#endif
?
? "55555555555555555555555555555555555"
a := 'EE'
#ifndef __XHARBOUR__
SWITCH a
CASE 11
? "11"
exit
CASE 'CCCC'+'DDDD'
? a+a
EXIT
CASE "a&b"
CASE 1+1
CASE {11111111,22222222222}[1]
CASE 1+1+1
? "3"
EXIT
CASE 1+1*3
CASE 123+12*4-1*4+2
CASE 1-4
? "4"
EXIT
CASE 123456789
CASE 0
EXIT
CASE 'AAAA'
CASE 'BBBBB'
? a
EXIT
CASE CHR(12)+CHR(15)
? "CHR()"
EXIT
OTHERWISE
? "NOT FOUND: running OTHER"
END
#endif
?
? "666666666666666666666666666666666666666666"
a := "2"
SWITCH a
CASE 1
? "FOUND: 1"
? a
EXIT
CASE "2"
SWITCH a+a
CASE 1
? "Nested FOUND 1"
EXIT
CASE "22"
? "Nested FOUND: 22"
EXIT
OTHERWISE
? "Nested OTHERWISE"
END
?? "In CASE 1"
? a
END
? "========================================="
RETURN