previous next contents
The Depot4 standard library consists of a set of modules that are useful in defining translators. They
offer services, which for efficiency or convenience, may be better implemented in the host language.
Actual implementations may contain additional procedures. The listed interfaces define only the
common core functionality for any Depot4 implementation.
This is the Output on Protocol module. For error and warning messages it is preferable to
use the intrinsic Ml4
procedures
ERROR or WARNING.
- Procedures
- WrStr(SYM)
- Write String - one SYM argument
- WrInt(INTEGER)
- Write Integer - one argument expression of type INTEGER
- WrLn
- Write Line - no argument
- ERROR(INTEGER)
- writes an internal error meassage - one INTEGER argument, which is the error number
error numbers bigger than 999 are assumed to be fatal errors, i.e. computation is aborted,
the actual error message is defined by argument - 1000
- ERROR(SYM)
- writes an error message identified by a key
- ERROR(SYM, SYM)
- writes an error message identified by a key and the additional text
- WARNING(INTEGER)
- issues a warning, argument is the warning number (INTEGER)
- setMessages
- sets the name of a class which extends Dp4Messages,
one SYM argument
- WARNING(SYM)
- writes a warning message identified by a key
- WARNING(SYM, SYM)
- writes a warning message identified by a key and the additional text
- WARNON():BOOLEAN
- returns whether warnings are enabled or not
Therein, all the messages that may displayed to users are managed. By default, this module contains the
system messages. Application specific message texts can be added in different ways.
The most general way is deriving a specific subclass of Dp4Messages, which gives one the full power of the
host language system. Not that flexible but fairly convenient is the definition of key text pairs in the
Ml4
code by means of setErrorTxT
procedure.
Error keys should start with a unique identification to avoid overlapping. All system error keys start
with "dp4."
.
- Interface
- getErrorText(SYM)
- get the error message for the given error key
- setErrorTxt(SYM, SYM)
- assign a message to an error key (any previously assigned
message for this key will be lost)
This module offers a simple symbol management. Together with flexible arrays (FLEX) it supports the
construction of symbol tables in Ml4
(without any pointer handling).
- Interface
- List
- Type for lists
- New(List)
- Initialization, has to be called explicitly
- Extend(List, SYM)
- Append symbol to list
- Unite(List, SYM)
- Append symbol only if not in list
- Idx(List, SYM):INTEGER
- Last index of symbol in list (=0 means symbol is not in list)
- Item(List, INTEGER):TXT
- return symbol with index i as object of type TXT
- len(List): INTEGER
- current number of symbols in list
- Cut(List, INTEGER)
- delete all symbols following the given index; to implement a stack together with len
- Sort(List, INTEGER, INTEGER)
- Sort symbols between both indices
- Exchng(List, INTEGER, INTEGER)
- Exchange symbols with the given indices (to implement own sorting)
The index range of lists starts with one (thus corresponding to FLEX).
This module collects some useful functions which were needed by system itself but may also
be useful in other projects. There may be slight differences among different Depot4
implementations.
At least, this module contains these functions:
- Interface
- Date():SYM
- current date in a default format
- Time():SYM
- current time in a default format
- Date(SYM):SYM
- current date and/or time formatted due to the argument (Java format string)
- PrefixFrom(SYM):SYM
- returns the prefix of a symbol value, i.e.,
if an identifier contains a small letter or
digit followed by a capital letter, all the part before the first such capital is regarded as prefix
(E.g.
Dp4
is the prefix of Dp4ExAmPlE1
.)
if there is none, as in DP4X
, an empty string is returned
- SuffixFrom(SYM):SYM
- returns the symbol value without its prefix,
if there is no prefix the argument is returned
- SplitIdent(SYM): SYM
- separates a String 'AbcdEfgHi' into 'Abcd.EfgHi', e.g. 'Dp4OP' into 'Dp4.OP'
the first part is called the prefix, the second the suffix of this String,
returns the argument String if no pair (small_letter|digit)capital_letter
is found.
- PackageFrom(SYM): SYM
- returns the "package part", i.e., the substring before the last dot,
or the empty string if there is not dot at all or the dot is the first or last character
- UpperCase(SYM):SYM
- converts all letters into their upper case equivalents
- LowerCase(SYM):SYM
- converts all letters into their lower case equivalents
- StartUpperCase(SYM):SYM
- converts the first character into upper case (if it is a letter)
- StartLowerCase(SYM): SYM
- converts the first character into lower case (if it is a letter)
- DbToCamelCase(SYM): SYM
- converts a string containing underscores into camel case, i. e. from ab_cd_ef into abCdEf;
a single underscore will result in an empty string
- CamelToDbCase(SYM): SYM
- reverts camel case into an underscore separated lower case string, e. g. from Abc2DefGg into abc2_def_gg
- IndexOf(s1: SYM, s2: SYM, f:INT): INT
- returns the index of s2 in s1, starting with f, or -1 if no such index exists
- Substring(SYM, f: INT, t: INT):SYM
- returns the substring ranging from f to t; t<0 means until the end; f>length of string will
result in an empty string
- Replace(s: SYM, old: SYM, new: SYM): SYM
- returns the string s, but all occurrences of old are replaced by new. returns s if old is empty or
s does not contain old at all.
- Property(SYM): SYM
- returns the value of the named property or an empty string
- MakeFileDir(SYM)
- creates a file directory as described by the String, if needed all missing directories on the
path are created too, assumes '/' as separator character, throws a RuntimeException if a file with
the name of the directory already exists
This module is heavily dependent from the implementation language and its runtime system, and thus
specified in Appendix D. At least, it contains a procedure to perform a translation.
previous next contents
© J. Lampe 1997-2010