Theme index -- Keyboard shortcut: 'u'  Previous theme in this lecture -- Keyboard shortcut: 'p'  Next slide in this lecture -- Keyboard shortcut: 'n'Linguistic abstraction
23.  Language embedding

In Chapter 22 we discussed how to establish languages, especially in Lisp.

In this chapter we will discuss how to combine two (or more) existing languages. More specifically, we will look at ways to embed one language into another.

23.1 Embedded languages23.3 Course home page embedding in Scheme
23.2 Examples of language embedding in HTML
 

23.1.  Embedded languages
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

We start with a definition of language embedding.

A new language N is an embedded language in an existing language E if an expression in N can be used as a subexpression of a construct in E.

As a possible practical organization of the embedding of a new language into another language, the interpreter of the new language N is made available as a function in the existing language E.

In the web domain there are many examples of language embeddings. Below we mention some of them.

  • There are many examples of embedding web languages and programming languages

    • Embedding of CSS in HTML, SVG and other XML languages

    • Embedding of Javascript in HTML for client dynamics

    • Embedding of a programming language in HTML at the server-side

      • ASP: HTML embedding of Visual Basic fragments

      • JSP: HTML embedding of Java fragments

      • PHP: HTML embedding of C-like fragments

      • BRL: HTML embedding of Scheme fragments

 

23.2.  Examples of language embedding in HTML
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

In this section we will illustrate some examples of language embedding from the web domain. More specifically, we will see how fragments in various programming languages can be embedded into HTML. Such language embedding is widely used at the server side of the World Wide Web.

Concrete illustrations of JSP, ASP, and BRL documents

The ASP and JSP examples are available via the slide and the annotated slide view of this material. (The examples are too large to warrant inclusion at this location of the material). Please take a look at the web material for the details.

The BRL [Lewis00] example is included here, because it is relatively small. In some sense it also covers the essence of the two others. We see Scheme fragments (emphasized with red color) within a conventional HTML document. When the web document is delivered by the server, the program fragments are executed. The functional results of the program execution become part of the web document. In a nutshell, this is a very common way to deal with dynamic web contents.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html>
 <head>
 [
  (inputs word) ; HTML input.  Will be null if no such input.
  (define newword
    (if (null? word)
        "something"
        word))
 ]
  <title>Backwards</title>
 </head>
 
 <body>
  <form>
  Type a word: <input name="word">
  <input type="Submit">
  </form>
  
  <p>[newword] spelled backwards is
     [(list->string (reverse (string->list newword)))]
  </p>
  
  <p>This message brought to you by [(cgi SERVER_NAME)] as a public
  service.</p>
  
 </body>
</html>
Program 23.1    An example of a BRL document.

 

23.3.  Course home page embedding in Scheme
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

We will illustrate embedded languages with an embedded list-based language in Scheme. This is done as a direct continuation of the course home page example from Section 22.4.

The simple course home page language is an embedded list language in Scheme

In Program 23.2 we see the course home page expression, emphasized with red color. This is a list structure, formed in its own language: A simple course home page language. The language is list-based, and the non-constant parst of the language are brought in via quasiquotation (also known as backquoting). Thus, the course home page subdocument makes use of variables and expressions from the surrounding Scheme program. Notice, however, that a special interpreter is needed to process the backquoted course-home-page expression.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(let ((ttl "Programming Paradigms")
      (max 5)
      (current 3)
     )

 `(course-home-page

   (name ,ttl)

   (number-of-lectures ,max)

   ,(cons 
     'lecture-names
     (map downcase-string  
       (list "intr" "scheme" "HIGHER-ORDER-FN" 
       "eval-order" "lisp-languages")))

   (current-lecture ,current)

   (links
     "schemers.org" "http://www.schemers.org/"
     "LAML" "http://www.cs.auc.dk/~normark/laml/"
     "Haskell" "http://haskell.org/"
   )
  )   
)
Program 23.2    A sample embedding of a course home document in a Scheme program.

 

23.4.  References
[Lewis00]Bruce R. Lewis, "BRL---A database-oriented language to embed in HTML and other markup", October 2000.

Generated: Tuesday July 2, 2013, 09:15:56
Theme index -- Keyboard shortcut: 'u'  Previous theme in this lecture -- Keyboard shortcut: 'p'  Next slide in this lecture -- Keyboard shortcut: 'n'