Lithe

Lithe is an experimental programming language created in 1982 by David Sandberg at the University of Washington which allows the programmer to freely choose the

Lithe

Lithe is an experimental programming language created in 1982 by David Sandberg at the University of Washington which allows the programmer to freely choose their own syntax. Lithe combines the ideas of syntax-directed translation and classes in a novel manner that results in a remarkably simple yet powerful language.

Overview

The standard class-based programming model does not specify a mechanism by which to manipulate objects: where Smalltalk uses message passing, Lithe uses syntax-directed translation (SDT). SDT is a method of translating a string into a sequence of actions by attaching one such action to each rule of a grammar. Thus, parsing a string of the grammar produces a sequence of rule applications. Lithe merges SDT with the class model by using classes as the non-terminal alphabet of the grammar. Since the grammar class used by Lithe properly contains all context-free grammars, a wide variety of syntax can be described, and SDT provides a simple way to attach semantics to any such syntax.

The package is the unit of program modularity in Lithe. A package is divided into two parts: one that defines classes and another that defines rules. Information hiding is achieved by requiring both export keywords on those rules and classes that are to be seen outside a package and that the source package names be included in the with clause of the consumer package.

Examples

Programming in Lithe consists of defining rule-action pairs and classes. Take the task of computing the absolute value of a number, for example:

rule "|" <i:int> "|" return int;
  {if i<0 then return -i else return i end}

After this rule-action pair has been defined, it can be freely used within Lithe source code, for example, the following expression will thereafter be valid:

|x - y| + 3

The equivalent rule in BNF would be:

<int>  ::=  "|" <int> "|"

Note that the Lithe description swaps the left and right sides of the BNF one, then adds a name to each nonterminal in the BNF right-hand side. These names are used in the action part, which is expressed as a string that is translated into a sequence of actions by using other, previously defined, rule-action pairs (eventually, some of those rule-action pairs will invoke primitive actions).

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.