TXL (programming language)

TXL is a special-purpose programming language originally designed by Charles Halpern-Hamu and James Cordy at the University of Toronto in 1985. The acronym "TXL" originally stood for "Turing eXtender Language" after the language's original purpose, the specification and rapid prototyping of variants and extensions of the Turing programming language, but no longer has any meaningful interpretation.

TXL
ParadigmPattern-matching and Term-rewriting
Designed byCharles Halpern-Hamu
James Cordy
DeveloperJames Cordy
Charles Halpern-Hamu
Ian Carmichael
Eric Promislow
Websitewww.txl.ca

Modern TXL is specifically designed for creating, manipulating and rapidly prototyping language-based descriptions, tools and applications using source transformation. It is a hybrid functional / rule-based language using first order functional programming at the higher level and term rewriting at the lower level. The formal semantics and implementation of TXL are based on formal term rewriting, but the term structures are largely hidden from the user due to the example-like style of pattern specification.

Each TXL program has two components: a description of the source structures to be transformed, specified as a (possibly ambiguous) context-free grammar using an extended Backus–Naur Form; and a set of tree transformation rules, specified using pattern / replacement pairs combined using first order functional programming. TXL is designed to allow explicit programmer control over the interpretation, application, order and backtracking of both parsing and rewriting rules, allowing for expression of a wide range of grammar-based techniques such as agile parsing.

The first component parses the input expression into a tree using pattern-matching. The second component uses Term-rewriting in a manner similar to Yacc to produce the transformed output.

TXL is most commonly used in software analysis and reengineering tasks such as design recovery, and in rapid prototyping of new programming languages and dialects.

Examples

BubbleSort

%Syntax specification
define program
   [repeat number]
end define
%Transformation rules
rule main
   replace $ [repeat number]
       N1 [number] N2 [number] Rest [repeat number]
   where 
       N1 [> N2]
   by
       N2 N1 Rest
end rule

Factorial

%Syntax specification
define program
   [number]
end define
%Transformation rules
function main
   replace [program]
       p [number]
   by
       p [fact][fact0]
end function
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
gollark: That might be useful to you.
gollark: Anyway, I have code for having drones do pathfinding, assuming you like OC waypoints.
gollark: Should this really be necessary to use the k.lua API?`-- Somewhat awful k.lua initialization messlocal w = require("w")local r = require("r")local k = require("k")local jua = require("jua")os.loadAPI(fs.exists("json.lua") and "json.lua" or "json")local json = _G.json_G.json = nillocal await = jua.awaitr.init(jua)w.init(jua)k.init(jua, json, w, r)`
gollark: It's a shame; drones with player tracking would be... something?
gollark: Probably not.

See also

References

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.