I. XML and the Design of Scheme
A. language design goals
------------------------------------------
LANGUAGE DESIGN GOALS FOR SCHEME
simplicity:
especially ease parsing the input
and implementation
==> regularity
generality:
since it aids simplicity
ability to manipulate programs as data:
to ease construction of interpreters
and compilers
to allow "meta programming"
------------------------------------------
B. XML
------------------------------------------
WHY XML?
A program is a document
- mostly formal,
- structured
- follows some standard grammar (schema)
Processing tools:
Compiler = lexer + parser + code gen.
Interpreter = lexer + parser + evaluator
Lexer: Character* -> Token*
Parser: Token* -> Abstract Syntax Trees
Code Gen.: Abstract Syntax Trees
-> object code
Interpreter: Abstract Syntax Trees
-> effects
How to
focus on interpreter and
ignore lexing and parsing techniques?
Solution: XML
------------------------------------------
------------------------------------------
XML
Extensible Markup Language (XML)
- international standard
- structured
- text-based
Many tools for parsing XML,
XML documents -> internal tree-objects
XML used as syntax for many languages:
- ant (building systems)
- o:XML (an OO language)
- MetaL
...
------------------------------------------
1. XML syntax
------------------------------------------
EXAMPLE: HELLO WORLD IN o:XML
------------------------------------------
What's the advantage of this syntax?
------------------------------------------
XML SYNTAX BASICS (simplified)
Document ::= Prolog Element
Prolog ::=
Element ::= < Name {Attribute}* />
| < Name {Attribute}* >
{Content}*
Name >
Attribute ::= Name = CharData
Content ::= CharData | Element
------------------------------------------
What's the advantage of using the ... syntax?
What's the problem with this kind of syntax?
What's the advantage of the syntax?
2. another example, Water
------------------------------------------
WATER LANGUAGE
From the Water home page (on Jan 9, 2004)
http://waterlanguage.org/index.html:
"Water(TM) is a new language optimized
for rapidly prototyping XML Web services.
It delivers both power and simplicity.
The language is as easy as BASIC
and as powerful as LISP."
x.
x. >
n. 1
else
n. /> />
==> 6
==> 24
------------------------------------------
------------------------------------------
WATER SYNTAX (simplified)
Document ::= Element
Element ::= < Name {Content}* />
| < Name {Attribute}* >
{Content}*
Name >
Attribute ::= Name = CharData
Content ::= CharData | Element | Attribute
------------------------------------------
C. Scheme's Syntax
------------------------------------------
SCHEME SYNTAX (S-EXPRESSIONS)
(define (double x) (+ x x))
(define (factorial n)
(if (= n 0)
1
(* n (factorial (- n 1)))))
(double 3) ==> 6
(factorial 4) ==> 24
------------------------------------------
------------------------------------------
SCHEME SYNTAX (simplified)
Vs. XML:
- use ( and ) instead of < and />
- no long form, , for closing
- the initial Name can be omitted
The initial name is either
- a keyword (special form)
- a procedure name (e.g., +, *)
Program ::= {S-Expression}*
S-List ::= ( {S-Expression}* )
S-Expression ::= Atom | S-Expression
Atom ::= Keyword | Proc-Name | Literal
Literal ::= Number | ...
------------------------------------------
1. comparison to XML-based syntax
------------------------------------------
COMPARISON TO XML SYNTAX
XML SCHEME
Document Program
... (define ...) ...
Element S-List
fact 3 (fact 3)
Content S-Expression
fact fact
------------------------------------------
2. regularity
------------------------------------------
SCHEME SYNTAX IS REGULAR
TO AID PROCESSING BY COMPUTERS
Mathematics Scheme
3 + 4*2 (+ 3 (* 4 2))
(3+4) * 2 (* (+ 3 4) 2)
f(x,y) (f x y)
------------------------------------------
D. conclusion
------------------------------------------
SCHEME SYNTAX SUMMARY
Scheme's syntax, like XML, is designed to:
- be very simple and regular
- ease parsing by computer
- allow programs to be represented
as data
Scheme syntax is a textual representation
of abstract syntax trees, like XML.
It's not designed to be good for humans.
------------------------------------------