Design Description: Multiparadigm Programming Language 0.9
WORK IN PROGRESS
The goal of this work is
-
to design an abstract grammar for those elements that programming languages
have in common in particular, for abstraction, generalization, and modules
and
-
to integrate the grammar with abstract grammars for a variety of programming
paradigms.
This work is supports ideas developing in Introduction to Programming
Languages where abstraction, generalization and computational models
are used as unifying concepts for understanding programming languages.
See the grammar
Program
A program is a collection of modules. One of which must be named
main. There is a module that is imported into all other modules by default.
The program address space ....
Modules & Blocks
Modules are used to construct libraries, ADTs, classes, interfaces,
and implementations. A module is the compilation unit. A module which
contains only type abstractions is a specification or interface module.
In a module, the only external names visible are those that are explicitly
imported or declared in the module. The only internal names visible
outside the module are those that are explicitly exported.
The extends is used to list modules whose entire definition is
made a part the the module.
The implements is used to list modules whose...
The from-import construct is used to list names imported from
other modules. The imported names can be used as if they were declared
locally.
The interface construct is syntactic sugar for ...
Declarations ... In the context of modules,
-
import
-
export designates a name that is visible wherever the module is
visible
-
private designates a name the is local to the module
-
protected designates a name that is local to the module and all
modules that import the module
-
static designates a name that is common to all objects of the module
-
entry designates an exported name that is an entry point of a monitor
-
initial designates an abstract that is executed when the module
is initially activated.
-
final designates an abstract that is executed when the module is
terminated
Blocks In a block, the names that are visible are those declared
in the block or in any inclosing block. A block may be implemented
using module syntax:
module import enclosing modules export to interior
modules .. initial abstract end
but module syntax requires that qualified names be used.
Abstraction, Generalization & Specialization
Abstraction provides names for abstracts that can be used wherever the
abstract may be used.
Generalization provides a way to parameterize abstracts.
Specialization application of a generalization (or its name) to an argument.
Parameters are declarations. The modifier suggests how the corresponding
argument will be handled.
-
in: values imported into the abstract
-
out: values exported from the abstract
-
in-out: values imported to and exported from the abstract
Arguments define what can be passed to an abstract and returned as a result.
Functional Programming
A functional program is an expression. The expressions
include
The grammar provides no syntactic sugar, it is the lambda calculus.
Constants
Constants include numbers, the boolean values, nil, the arithmetic and
relational operators, and other predefined function symbols.
Variables
Variable are identifiers. If the variable is
the name of an abstract, then its value is the abstract otherwise its value
is undefined.
Function Application
Function application takes the form
( expression1 expression2 )
The result is the reduction of the application to normal form. Reduction
to normal form is function evaluation which if expression1
is a generic then the quantifier is removed from the expression and expression2
is substituted, in the body of expression1,
for the quantified variable. If the resulting expression is reducible,
then it is reduced.
Function Abstraction
A function abstraction is in normal form and stands for its self.
Imperative Programming
An imperative program is a command. The commands
include
Skip Command
The skip command has the form
skip
It does nothing.
Application Command
The application command has the form
name( actual parameters )
The action performed by an application command is determined by its definition.
Assignment Command
The assignment command has the form:
identifer0,..., identifiern := expression0,..., expressionn
For n>=0. The effect is as if the expressions
are evaluated and assigned in parallel with the ith identifieri
assigned the value of the ith expressioni.
The identifier and expression must be type compatible (matching types).
Parallel Command
The parallel command is of the form:
{|| command0,..., commandn }
The programmer may make no assumptions about the degree of parallelism
or relative speeds with which the commands execute.
Sequential Command
The sequential command is of the form:
{; command0,..., commandn }
The programmer may assume that the commands execute in sequence from left
to right with each command terminating before the next begins.
Choice Command
The choice command is nondeterministic and is of the form:
{? guard0 --> command0,
...,
guardn --> commandn
}
The programmer may assume that if no guard evaluates to true, that the
command terminates and that if some guard is true, that exactly one of
the commands corresponding to a guard that evaluates to true is executed.
Iterative Command
The iterative command is nondeterministic and is of the form:
{* guard0 --> command0,
...,
guardn --> commandn
}
The programmer may assume that while some guard is true, exactly one of
the commands corresponding to a guard that evaluates to true is executed
and that if no guard evaluates to true, that the command terminates. The
guards are reevaluated after the execution of a command.
Abstraction
Inline abstractions are restricted to
Invocation
Invocations are restricted to direct recursion within an abstraction,
Logic Programming
The logic programming grammar is pure Prolog.
Communication and Events
Monitor The monitor construct is for communication and synchronization
in a shared memory system.
Send-Receive The send and receive constructs are for communication
and synchronization in message passing systems.
Exceptions
Threads
Type Expressions, Literals and Constants
The goal is to provide a useful range of primitive and structured types
and type definition facilities.
One novel feature is the inclusion of a null (empty) type and
a nil (undefined) value.
Types are either primitive or structured and may be referenced by name.
In addition to the usual primitive types, a null type (empty) is provided.
Singleton types (types with only one element) are called atoms (the type
name and element are the same).
-
atom: a type with exactly one value; implementation - type name
and only element are the same - x isa x
The structured types are the sum, product, function (array) and class (in
the form of a module). The sum type provides an optional tag which
may be used when type information is needed. The sum type is used
to define enumerated and subrange types.
-
sum type: (+ )
-
enumerated types: constructed from sum types using primitive values
and atoms (+ sun, mon, tue, wed, thir, fri, sat)
-
range types: i..j = (+ i..j)
The product type provides for optional field names. Access to the
individual fields is by field name or by pattern matching. The product
type when combined with abstraction and generalization, permits the
definition of recursive and polymorphic types. Product types may
be defined using modules.
-
recursive types: listT is (+ empty, (* item,
listT))
-
Polymorphic Type: BTreePT is \T,node.(+ empty, (*n is a T,
BTreePT T, BTreePT T))
-
Integer Type Binary Tree : BTreeIntegerT is BTreePT integer
-
Variable of an integer type binary tree: MyTree isa BTreeIntegerT
Arrays are provided via a mutable function type
-
array types: map (*0..n) --> (*a0..,an)
Missing are set and file types.
Implementation
The compiler will be in written in Java and generate a Java program as
object code to insure portability.
by Anthony A. Aaby.
Send comments to aabyan@wwc.edu