Computer Wiki
Advertisement

This article describes how to make an extensible meta programming language, herein called Ameba. It is a macro functional language, in which macro-functions have arbitrary syntax arguments. This implementation does not rely on preprogrammed productions, because the syntax extensions are done with a 3rd generation, structured language.

There are many languages, including Fortran, assembler, Lisp and Java--each having strengths and weaknesses. Sometimes an existing language is not suitable for a given project. Consequently, the idea of creating a Domain Specific Language (DSL) for various projects has become a line of research and development. Designing and developing a language can be simplified, but it will never be trivial.

Another research venue is to make extensible languages. This technology makes a standard language applicable to a larger problem domain. The degree to which a language may be extended depends on features within the language. Note, however, people can morph spoken languages, such as Latin, into a completely different language, such as Italian. Moreover, no computer language is as extensible as a spoken language.

Ameba is based on characters and strings of characters that compose programs and nonsense strings. Ameba passes nonsense strings from input to output without changing them. Ameba processes programs that it recognizes within its input, and outputs the program result. Thus, the output of Ameba is composed of nonsense and results. This combined output can be anything, but will often be a program.

We extend Ameba syntax as macro-functions are written, because macro-function arguments are processed character by character, using the built-in function get-arg-char. However, a built-in library of functions helps us process arguments as words and expressions. The design of this built-in library is novel, and its description characterizes the paradigm. This library contains two additional functions named get-arg-word and get-arg-expression. Ameba does not exclusively use a context free syntax grammar to identify words. Words are mainly identified by searching a dictionary. However, when a string of characters does not exist in the dictionary, a scanner divides the argument string into words with a default Context Free Grammar (CFG).

Dictionary entries consist of the word being defined and one or more definitions. Words in the dictionary may be any string of characters, including strings that contain spaces. For example, The Statue of Liberty, 3.14, U2, 3/4 and ++ can be in the dictionary. Words can be arbitrarily long, but an implementation of Ameba may establish a limit for a given implementation--the larger the better. Sometimes several words in a dictionary will begin with the same characters, for example open and open database. In this case, input scanning finds the longest possible word in the dictionary to match successive characters in the argument string.

The default CFG has rules that identify literals, comments, and other syntax. Literals include numbers and quoted strings, and they are self defining. In other words, a number such as 3.14 is both a word and a definition. The default CFG also contains rules that identify program comments, for example /* comment */. Finally, the default CFG contain rules to identify other undefined words, by making substrings consisting of characters from one of four subsets--all alphabetic, all numeric, all special characters, or spaces.

A macro-function may overload the current CFG with a user-defined CFG for the duration of that macro-function call, but upon exit the CFG overload ends and the previously used CFG is used again. CFG overloads may be stacked whenever a macro-function (e.g., MF-p) overloads the current CFG and subsequently calls another macro-function (e.g., MF-q) that overloads the current CFG again. User code may overload current CFG many times as macro-function calls occur. Upon return from each macro-function, the previous CFG is restored.

One way to implement a default CFG is to define each character as a macro-function, for example quote (i.e., "), Whenever a quote occurs in the input program it gets the next character (e.g., ?) and checks the dictionary to see if one or more entries exist with that two character sequence beginning with quote (i.e., "?) or does not exist. If it does not exist, then the quote macro-function continues scanning the input until it finds a closing quote, another terminating character, or end. All syntax forms (i.e., literals, comments, alphabetics, etc.) can be scanned similarly.

Expression syntax is defined in a macro-function named open parenthesis, that is '('. As with all other Ameba macro-functions that define syntax, open parenthesis may be overloaded.

All syntax is defined within various macro-functions. Any word, including the words having only one character, may have several definitions, and each definition may define a different syntax. Consequently, programmers may enhance Ameba to have whatever domain specific syntax and semantics are required.

The function get-arg-word first attempts to find a word from the argument string in the dictionary. If it fails, then it relies on the current CFG to get a word.

The function get-arg-expression calls get-arg-word which returns a word, W. Then, it evaluates W, which may also get arguments, in which case, additional words and characters will be scanned as W is evaluated. Words such as W may have several definitions. When the get-arg-expression is called, it will try each definition of the word. It may find that several definitions will work, in which case evaluation forks until all forks either fail or complete. If more than one completes, then an ambiguity exists that must be resolved by a person. If only one fork completes, it is the solution.

That concludes the discussion of the new paradigm. Otherwise, Ameba is unremarkable, it shall be a 3gl with the ability to do calculations, conditions and loops. Ameba macro-functions are are first class objects. Therefore, Ameba shall do partial evaluation of input programs, whenever necessary. Ameba is not object oriented, but macro-function extensions can make it so. One may extend Ameba with any domain specific syntax. Only semantics limit Ameba capabilities. For example, without a MIDI interface, Ameba will not be capable of communicating with a MIDI device.

See also: "Ameba, a Calculator and Metalanguage" on this wikia.


--Edearl 04:01, 6 August 2009 (UTC) Edwin E. Ross

Advertisement