TXL is an actively used programming language created in 1985.

34Years Old 1,020Users 0Jobs

Example code from Linguist:

% Calculator.Txl - simple numerical expression evaluator

% Part I.  Syntax specification
define program
        [expression]
end define

define expression
        [term]
    |   [expression] [addop] [term]
end define

define term
        [primary]
    |   [term] [mulop] [primary]
end define

define primary
        [number]
    |   ( [expression] )
end define

define addop
        '+
    |   '-
end define

define mulop
        '*
    |   '/
end define


% Part 2.  Transformation rules
rule main
    replace [expression]
        E [expression]
    construct NewE [expression]
        E [resolveAddition] [resolveSubtraction] [resolveMultiplication]
          [resolveDivision] [resolveParentheses]
    where not
        NewE [= E]
    by
        NewE
end rule

rule resolveAddition
    replace [expression]
        N1 [number] + N2 [number]
    by
        N1 [+ N2]
end rule

rule resolveSubtraction
    replace [expression]
        N1 [number] - N2 [number]
    by
        N1 [- N2]
end rule

rule resolveMultiplication
    replace [term]
        N1 [number] * N2 [number]
    by
        N1 [* N2]
end rule

rule resolveDivision
    replace [term]
        N1 [number] / N2 [number]
    by
        N1 [/ N2]
end rule

rule resolveParentheses
    replace [primary]
        ( N [number] )
    by
        N
end rule

Example code from Wikipedia:

function fact
   replace [number]
      n [number]
   construct nMinusOne [number]
      n [- 1]
   where 
      n [> 1]
   construct factMinusOne [number]
      nMinusOne [fact]
   by
      n [* factMinusOne]
end function 
      
function fact0
 replace [number]
      0
 by
      1
end function
Edit

Last updated February 11th, 2019