Example 1 - XML DOM Parser
Let's start with a simple example to clarify the vocabulary. A XML DOM
parser written in Java.
The parser is going to parse XML documents. This means that the source
Language is XML. The control language will be DOM, as defined by
W3C. DOM is used to start the parser and to navigate and extract
information from the parse tree built by the parser. DOM is a Language
for the domain of XML processors.
DOM Parser with implemented Languages.
|
As we want the Baseline Language to be Java, we choose the DOM
definition specially designed for Java. This means that our DOM
inherits syntax and semantics from Java. The DOM Parser will also be
written in Java and therefore it depends on the Java Runtime
Environment.
DOM Parser Architecture.
|
Example 2 - ProC Precompiler
The Precompiler for ProC developed by Oracle is a simple GUI
application. It translates programs written in the hybrid Language
ProC into pure C programs. ProC is C with embedded SQL statements. The
precompiler translates the SQL statements into C function calls to the
library SQLLIB.
ProC Precompiler.
|
Example 3 - A Content Management System for the Web
The program that delivers the pages you are reading right now is
developed following the process defined on this site. It serves as a
good example to highlight all the principles behind LISA. It is
written in HTML and PHP4, of which the syntax and semantics should be
easy to understand for a C or Java programmer. It was developed in
three iterations, during which the requirements got more detailed and
the domain language, application and web interface settled. It is the
result of the final iteration that is presented here.
The Requirements
The presentation of LISA on the web required something special,
something new. Just plain old HTML pages was not good enough. It
required something with a more polished look and feel. It required a
Content Management System.
The user requirements for the system is as follows:
- A menu with links to important topics should be displayed at the top
of the screen.
- The majority of the screen should be filled with the text for a
specific topic.
- Each page should have a list with links to related topics. The
list should be sorted.
Architecture
The architect decided that this program should be modelled after the
basic Architectural Pattern End User Application. PHP, HTML and
HTTP was choosen as Baseline Languages.
Logic view of the Architecture.
|
The Language inheritance shows that the Domain Language and the
Application is based on PHP4. The User Interface consists of a code
generator and a HTML page, Page Source.
The User Interface is controlled via HTTP requests, which it has
generated itself and embedded in the Page Source.
The Domain Language Implementation uses two file formats to configure
available links and related topics.
Transition view of the Architecture.
|
The transition view simply states that lisa.php is a composition of
the three Components.
Deployment view of the Architecture.
|
Two nodes, the Server and the Client, are used in the deployment of
the system. Infrastructure needs to be in place to enable the HTTP
communication between the nodes.
The Browser parses the HTML code and uses HTTP to fetch new pages. The
Apache web server implements HTTP and passes parts of the request all
the way up to lisa.php for interpretation.
The user depends both the Browser UI Language and the CMS UI Language.
The Domain Language
The first steps in the process says that a Domain Language should be
defined. First, we define the scope for the language.
Scope: The Domain Language will be a language for writing Content
Management Systems in.
Looking through the user requirements, topic and link
seems to be important terms. A menu is also mentioned, but
there is doubt that this is a term in the Domain Language. The
decision was made to leave it to the Application. It could be included
in the Domain Language in a later iteration, if needed.
There are two relations in the language. A link is related to a page,
and a page is related to many pages. The vocabulary diagram looks
like this:
Domain Language for Content Management Systems.
|
This diagram is translated into the following Language interface in PHP:
// link
function getAllLinks()
function getLinkedTopic($link)
function getLinkReference($link)
// topic
function getTopicName($topic)
function getTopicContents($topic)
function getTopicReference($topic)
function getRelatedTopics($topic)
function sortTopics($topics)
function getTopic($reference)
$link and $topic are new types and their implementation is unknown to
the user of the Domain Language. The $reference is a PHP string coded
reference to a link or topic, to be used by the Application when
referencing links and topics outside of PHP. The use of PHP types,
syntax and semantics means that the Domain Language inherits from PHP.
Do the sortTopics() function belong in the Domain Language? The
Application will at least need a compare($page1, $page2) function, and
as this function is not needed for anything else, the decision was
made that the Domain Language could take care of the entire sorting
process more easily than if the Application handled the sorting.
The Domain Language defined here can be said to be a read-only
repository of links and topics.
Domain Language Design and Implementation
The implementation of the Domain Language uses the filesystem for data
storage. Links are stored in the file links. Topic relations
are stored in the file topicmap and topic content is stored in
separate files in the folder topics/.
The types $topic and $link are represented with strings. All links are
stored in a one dimensional array and topic relations are stored in a
two dimensional array.
Topic and link references are the same as the names, but spaces are
replaced with underscores. Slashes are forbidden in references for
security reasons.
Here is the complete implementation:
/*** DOMAIN LANGUAGE ***/
// DL Constants
define("links", "links");
define("topicmap", "topicmap");
define("separator", "=");
define("topicpath", "./topics/");
// DL Implementation details
$file = fopen (links, "r");
while (!feof ($file)) {
$link = rtrim(fgets($file, 1024));
if (strlen($link) > 0) {
$links[] = $link;
}
}
fclose ($file);
$file = fopen (topicmap, "r");
while (!feof ($file)) {
list ($topic1, $topic2) = explode(separator, rtrim(fgets($file, 1024)));
if (strlen($topic1) > 0 && strlen($topic2) > 0 &&
(sizeof($relatedTopics[$topic2]) == 0 ||
!in_array($topic1, $relatedTopics[$topic2]))) {
$relatedTopics[$topic1][] = $topic2;
$relatedTopics[$topic2][] = $topic1;
}
}
fclose ($file);
// DL Interface
// link
function getAllLinks()
{
global $links;
return $links;
}
function getLinkedTopic($link)
{
return $link;
}
function getLinkReference($link)
{
return str_replace(" ", "_", $link);
}
// topic
function getTopicName($topic)
{
return $topic;
}
function getTopicContents($topic)
{
$contents = "";
$file = @fopen(topicpath . getTopicReference($topic), "r");
while ($file && !feof ($file)) {
$contents = $contents . fgets($file, 1024);
}
@fclose ($file);
return $contents;
}
function getTopicReference($topic)
{
return str_replace(" ", "_", $topic);
}
function getRelatedTopics($topic)
{
global $relatedTopics;
return $relatedTopics[$topic];
}
function sortTopics($topics)
{
if (sizeof($topics) > 0) {
sort($topics);
reset($topics);
}
return $topics;
}
function getTopic($reference)
{
return str_replace("/", " ", str_replace("_", " ", $reference));
}
The User Interface
The design of the User Interface was restricted by the requirements
and the capabilities of plain HTML. The designer decided that links
should have icons to make the page more pleasant to look at. The
related topics was placed in a straight list to the right of the topic
text.
The Application
The Application uses the Domain Language to implement a Language that
satisfies the requirements defined by the User Interface. The
requirements not taken care of by the Domain Language are the
following:
- A menu with links.
- Link images.
- The current topic.
- HTTP encoding and decoding.
- Always sorting related topics.
This basically means that the Application takes care of policy
decisions not related to the Domain Language and HTTP coding.
The application needs to extend the Domain Language with new
vocabulary.
Application Language for LISA Presentation Application.
|
This translates to the following Application Language interface:
function getMenu()
function getTopicURL($topic)
function getLinkImageURL($link)
function getCurrentTopic()
function getRelatedTopicsList($topic)
There is no $menu type, but an array of links are returned immediately
from the getMenu() function. URLs are coded as strings. The related
topics list is a sorted array of $topics.
Application Design and Implementation
Link images are stored in the directory images/ in PNG
format. The filename is derived from the link reference string.
The menu contains all links available in the Domain Language.
Topic URLs are encoded by setting the parameter topic to the
topic reference string. The current topic is retrieved by decoding the
URL parameter and dereferencing it via the Domain Language. The
default topic is decided to be LISA.
Here is the complete implementation:
/*** APPLICATION ***/
// Constants
define("appname", "lisa.php");
define("defaultTopic", "LISA");
define("linkImagepath", "./images/");
define("imageFormat", ".png");
define("topicparam", "topic");
// APP Interface
function getMenu()
{
return getAllLinks();
}
function getTopicURL($topic)
{
return appname . "?" . topicparam . "=" . getTopicReference($topic);
}
function getLinkImageURL($link)
{
return linkImagepath . getLinkReference($link) . imageFormat;
}
function getCurrentTopic($params)
{
if (strlen($params[topicparam]) > 0)
{
return getTopic($params[topicparam]);
}
return getTopic(defaultTopic);
}
function getRelatedTopicsList($topic)
{
$topics = getRelatedTopics($topic);
return sortTopics($topics);
}
User Interface Design and Implementation
The User Interface implementation is straightforward with the use of
the Application Language and HTML.
Extensions
The Domain Language could be extended with edit capabilities.
function saveLink($page)
function deleteLink($link)
function savePage($name, $content)
function deletePage($page)
function saveRelation($page1, $page2)
function deleteRelation($page1, $page2)
How to evolve the Application and the User Interface into a Wiki-like
program is left as an excercise for the reader.
Another possibility is to write a slideshow Application that reuses
the Domain Language.
|