]]> ]]>

Clarion C7

Версия реализации Clarion C7+ языка программирования Clarion

On April 13, 2009 SoftVelocity released Clarion 7 (aka C7). The new IDE will look familiar to SharpDevelop users, SoftVelocity obtained a commercial license for the SharpDevelop code and integrated Clarion’s code generation and application generation technology, fixed and extended the basic functionality. Major new features (other than the standard modern IDE features lacking in C6) include a build system based on MSBuild and backward compatibility with all releases of Clarion going back to Clarion for Windows 1.5.

Примеры:

Hello, World! - Clarion (574):

   PROGRAM
     MAP
     END
   CODE
     MESSAGE('Hello World!','Clarion')
     RETURN

CamelCase - Clarion (575):

  PROGRAM

  MAP
  END

InitStr              STRING('Some string with any symbols')
Str                  CSTRING(100),AUTO
symbol               STRING(1)

   CODE
      j# = 1 ! implicit variable
      loop i# = 1 to len(InitStr) by 1
         symbol = lower(InitStr[i#]) ! string can be considered as array
         case symbol
         of 'a' to 'z'
            Str[j#] = choose(was_letter#,symbol,upper(symbol))
            j# += 1 ! using of add equals operator for increment
            was_letter# = TRUE
         else 
            was_letter# = FALSE
         end   
      end   
      message(Str,'CamelCase')

Квадратное уравнение - Clarion (576):

минималистическая версия

   PROGRAM

OMIT('***')
 * User: Shur
 * Date: 28.02.2016
 * Time: 14:05
 ***
  MAP
  END

A REAL
B REAL
C REAL

root               CSTRING(64)

   CODE
      
      A=0; B=2; C=3
      !A=1; B=-5; C=3
      !A=1; B=2; C=1
      
      D$ = B * B - 4 * A * C
      if A = 0
         root = 'Not a quadratic equation.'
      elsif D$ = 0
         root = 'x = ' & -B/2/A
      elsif D$ > 0 then
         root = 'x1 = ' & (-B-sqrt(D$))/2/A & '|' & |
                  'x2 = ' & (-B+sqrt(D$))/2/A
      else   
         root = 'x1 = (' & -B/2/A & ', ' &  sqrt(-D$)/2/A & ')' & '|' & | 
                  'x2 = (' & -B/2/A & ', ' & -sqrt(-D$)/2/A & ')'
      end
      message(choose(A=0,'','D='&D$&'|----------|')&root,'Quadratic equation')

Квадратное уравнение - Clarion (577):

максималистичная версия с проверкой найденных корней. попутно реализована арифметика комплексных чисел

   PROGRAM

OMIT('***')
 * User: Shur
 * Date: 28.02.2016
 * Time: 14:05
 ***
complex          GROUP,TYPE
a                       REAL(0)
b                       REAL(0)
                 END

  MAP
cxSum             PROCEDURE(*complex cxA, *complex cxB, *complex cxRes)
cxMul             PROCEDURE(*complex cxA, *complex cxB, *complex cxRes)
cxDiv             PROCEDURE(*complex cxA, *complex cxB, *complex cxRes)
  END

A REAL
B REAL
C REAL

X                   GROUP,PRE(X),DIM(2)
X                       LIKE(complex)
F                       CSTRING(64)
R                       LIKE(complex)
                     END

root               CSTRING(64)
check_               CSTRING(256)

CX1                   LIKE(complex)
CX2                   LIKE(complex)
CX3                   LIKE(complex)

   CODE
      A=1; B=3; C=3
      !A=1; B=-5; C=3
      !A=1; B=2; C=1
      D$ = B * B - 4 * A * C
      if A = 0
         root = 'Not a quadratic equation.'
      elsif D$ = 0
         X[1].X.a = -B/2/A
         root = 'x = ' & X[1].X.a
      elsif D$ > 0 then
         X[1].X.a = (-B-sqrt(D$))/2/A         
         X[2].X.a = (-B+sqrt(D$))/2/A         
         root = 'x1 = ' & X[1].X.a & '|' & |
                  'x2 = ' & X[2].X.a
      else   
         X[1].X.a = -B/2/A; X[1].X.b = sqrt(-D$)/2/A         
         X[2].X.a = -B/2/A; X[2].X.b = -sqrt(-D$)/2/A         
         root = 'x1 = (' & X[1].X.a & ', ' & X[1].X.b & ')' & '|' & | 
                'x2 = (' & X[2].X.a & ', ' & X[2].X.b & ')'
      end
      loop i# = 1 to 2 
         !loop j# = 1 to 2 
            if X[i#].X.a or X[i#].X.b
               if D$ ~< 0
                  X[i#].F = choose(A=0,'',A&'*'&X[i#].X.a&'^2')&choose(B=0,'',choose(B>0,'+','')&B&'*'&X[i#].X.a)&choose(C=0,'',choose(C>0,'+','')&C)
                  X[i#].R.a = round(EVALUATE(X[i#].F),0.0000000000001)
                  check_ = check_ & choose(check_<>'','|','') & X[i#].F&'=' & X[i#].R.a
               else   
                  CX1.a = X[i#].X.a; CX1.b = X[i#].X.b
                  CX2.a = A; CX2.b = 0
                  cxMul(CX1, CX1, CX3) ! x^2
                  cxMul(CX2, CX3, CX3) ! a*x^2
                  X[i#].R = CX3
                  CX2.a = B; CX2.b = 0
                  cxMul(CX1, CX2, CX3) ! b*x
                  CX2 = X[i#].R
                  cxSum(CX2,CX3,CX1) ! a*x^2 + b*x
                  X[i#].R = CX1
                  CX2.a = C; CX2.b = 0
                  cxSum(CX1,CX2,CX3) ! a*x^2 + b*x + c
                  X[i#].R = CX3
                  check_ = check_ & choose(check_<>'','|','') &'= (' & X[i#].R.a & ', ' & X[i#].R.b & ')'
               end   
            end   
         !end   
      end   
      message(choose(A=0,'','D='&D$&'|----------|')&|
         root&|
         choose(A=0,'',choose(check_>'',|
         '|----------|'&|
         check_,'')),'Quadratic equation')

cxSum            PROCEDURE(cxA, cxB, cxRes)
      CODE
         cxRes.a = cxA.a + cxB.a
         cxRes.b = cxA.b + cxB.b

cxMul            PROCEDURE(cxA, cxB, cxRes)
      CODE
         cxRes.a = cxA.a*cxB.a - cxA.b*cxB.b
         cxRes.b = cxA.a*cxB.b + cxB.a*cxA.b

cxDiv            PROCEDURE(cxA, cxB, cxRes)
      CODE
         cxRes.a = (cxA.a*cxB.a + cxA.b*cxB.b) / (cxB.a^2 + cxB.a^2)
         cxRes.b = (cxB.a*cxA.b - cxB.b*cxA.a) / (cxB.a^2 + cxB.a^2)

Комментарии

]]>

blog comments powered by Disqus

]]>

Работа программистам