LPC.html
MudOSa4DGD/mudlib/dgd/doc/LPC.html · 8.1 KB
From the archive MudOSa4DGD-30.06.98.tar.gz
Download the archive « Back to the archive contents
<HTML>
<HEAD>
<TITLE>
The LPC Reference Manual
</TITLE>
</HEAD>
<BODY>
<H1> The LPC Reference Manual </H1>
Copyright © 1995 - 1997 BeeHive Internet technologies, Inc.
<H2> 1. Introduction </H2>
<H3> 1.1. Purpose </H3>
This document is a formal description of the LPC programming language.
The LPC programming language is derived from C and named after its primary
creator, Lars Pensjö. Several dialects of LPC exist; the programming
language described here is the one used in <I>Dworkin's Generic Driver</I>
(DGD) version 1.1.
<!-- I will use the term LPCd to indicate the DGD dialect of LPC in
particular. -->
<H3> 1.2. History </H3>
<!-- First came LPmud 1, then LPmud 2, etc.
Game driver vs. multipurpose server. -->
<H2> 2. Environment </H2>
<!-- A description of objects, the server and clients.
Compilation of files to objects. Translation phases (preprocessor).
ASCII code used, ISO 8859-1 recommended extension.
Value of newline etc. is fixed.
A description of which functions are called by the server, and when. -->
<H2> 3. Language </H2>
In the syntax notation of this document, syntactic catagories are
indicated by <I>italic</I> type.
<H3> 3.1. Lexical elements </H3>
<H3> 3.1.1. Tokens </H3>
A <I>token</I> is the minimal lexical element of the language. The
categories of tokens are:
<I><A HREF="#identifiers">identifiers</A></I>,
<I><A HREF="#keywords">keywords</A></I>,
<I><A HREF="#constants">constants</A></I>,
<I><A HREF="#operators">operators</A></I> and
<I><A HREF="#punctuators">punctuators</A></I>. Tokens are separated by
white space: blanks, horizontal and vertical tabs, newlines, carriage returns,
formfeeds and comments.
<H3> 3.1.2. Comments </H3>
A comment is a sequence of characters starting with the characters <TT>/*</TT>
and terminated by the characters <TT>*/</TT>. All characters in between are
part of the comment. Comments count as whitespace separating tokens, and
may not be nested. The sequence <TT>/*</TT> does not start a comment if it
is part of a string.
<H3> <A NAME="identifiers"> 3.1.3. Identifiers </A> </H3>
An identifier is an arbitrary long sequence of letters, digits and
underscores. The first character must be a letter or underscore. Upper- and
lower-case letters are different. Only the first 1023 characters of
identifiers are significant.
<H3> <A NAME="keywords"> 3.1.4. Keywords </A> </H3>
The following identifiers are reserved for use as keywords:
<PRE>
atomic do int return void
break else mapping rlimits while
case float mixed static
catch for nomask string
continue if object switch
default inherit private varargs
</PRE>
The keyword <TT>atomic</TT> is reserved, but currently unused.
<H3> <A NAME="constants"> 3.1.5. Constants </A> </H3>
A <I>constant</I> is either an
<I><A HREF="#integer constants">integer constant</A></I>,
<I><A HREF="#floating constants">floating constant</A></I>,
<I><A HREF="#string constants">string constant</A></I> or
<I><A HREF="#character constants">character constant</A></I>.
<H3> <A NAME="integer constants"> 3.1.5.1. Integer Constants </A> </H3>
An <I>integer constant</I> is a <I>decimal constant</I>, <I>octal constant</I>
or <I>hexadecimal constant</I>.
<P>
A sequence of digits is taken to be a <I>decimal constant</I> (base ten)
unless it begins with <TT>0</TT>. A sequence of digits starting with <TT>0</TT>
and not including <TT>8</TT> or <TT>9</TT> is an <I>octal constant</I>
(base 8). A sequence of digits and upper- or lower-case letters in range
<TT>A</TT> through <TT>F</TT>, preceded by <TT>0x</TT> or <TT>0X</TT> is a
<I>hexadecimal constant</I> (base 16, where <TT>A</TT> through <TT>F</TT>
have the decimal values 10 through 15).
<P>
<I>Integer constants</I> are represented by 32 bit 2's complement arithmetic,
and range from -2147483648 through 2147483647. It is an error to specify a
<I>decimal constant</I> that is too large to be represented. <I>Octal
constants</I> and <I>hexadecimal constants</I>, when too large, are
truncated to the lower 32 bits.
<P>
<!-- For instance, the number forty-seven can be written as 47, 057 or 0x2f.
There is a problem particular to LPCd with regard to -2147483648. Since
LPCd, unlike C, has no unsigned type, the decimal version of this number
(which is scanned as - 2147483648) is the negation of a number too large
to be represented. - and 2147483648 cannot be read as a single token,
because then 1-2147483648 would be scanned as two consecutive integers.
This number must be specified by an octal or hexadecimal constant. -->
<H3> <A NAME="floating constants"> 3.1.5.2. Floating constants </A> </H3>
A <I>floating constant</I> consists of an integer part, a decimal point, a
fraction part, and an exponent part, consisting of an <TT>e</TT> or <TT>E</TT>
and an optionally signed integer exponent. Either the integer part or the
fraction part, but not both, may be missing. Either the decimal point and
fraction part, or the exponent part, but not both, may be missing.
<P>
<I>Floating constants</I> represent a floating point number in the range of
-1.79769313485E308 through 1.79769313485E308, the smallest possible number
being -2.22507385851E-308. It is an error to specify a <I>floating constant</I>
that is too large to be represented. Numbers which are too small are
flushed to zero.
<H3> <A NAME="string constants"> 3.1.5.3. String constants </A> </H3>
A <I>string constant</I> is a sequence of zero or more characters enclosed
in double quotes. All characters, with the exception of newline, can be used in
a <I>string constant</I>. A backslash character <TT>\</TT> introduces an
escape sequence, which consists of at least 2 and at most 5 characters
(including the backslash), and which is translated into a single character in
the string. The following escape sequences can be used:
<PRE>
\a = 007 (bell) \o
\b = 010 (backspace) \oo
\f = 014 (form feed) \ooo
\n = 012 (newline) \xh
\r = 015 (carriage return) \xhh
\t = 011 (horizontal tab) \xhhh
\v = 013 (vertical tab) \c
</PRE>
The value of <TT>\a</TT>, <TT>\b</TT>, <TT>\f</TT>, <TT>\n</TT>, <TT>\r</TT>,
<TT>\t</TT> and <TT>\v</TT> is the octal value shown. <TT>\o</TT>,
<TT>\oo</TT> and <TT>\ooo</TT> constitute an integer of at most 3 octal
digits, the octal value of which specifies a single character. <TT>\xh</TT>,
<TT>\xhh</TT> and <TT>\xhhh</TT> constitute an integer of at most 3 hexadecimal
digits, the hexadecimal value of which specifies a single character. All other
escape sequences <TT>\c</TT> specify the character <TT>c</TT> (any character
except <TT>a</TT>, <TT>b</TT>, <TT>f</TT>, <TT>n</TT>, <TT>r</TT>, <TT>t</TT>,
<TT>v</TT>, <TT>x</TT>, or a digit), which itself is not interpreted in any
special way.
<!-- For example, "\"" is the string constant consisting of a double quote
character. "\g\?\0123" is the same as "g?\n3".
The value of \a .. \v is fixed, and identical on all hosts, even on
those which have C compilers with different values for them.
Note that at most three hexadecimal digits can be used, even though all
characters can be expressed with just two. -->
<H3> <A NAME="character constants">3.1.5.4. Character constants </A> </H3>
A <I>character constant</I> consists of a single character or escape sequence,
enclosed in single quotes. All characters except newline can be used.
Escape sequences are handled as with <I><A HREF="#string constants">string
constants</A></I>.
<!-- So-called multiple character constants are not allowed. -->
<H3> <A NAME="operators"> 3.1.6. Operators </A> </H3>
The following are operators:
<PRE>
[ ] ( ) ->
++ -- + - ~ ! ... catch
* / % << >> < > <= >= == != & ^ | && ||
? :
= *= /= %= += -= <<= >>= &= ^= |=
,
</PRE>
<H3> <A NAME="punctuators"> 3.1.7. Punctuators </A> </H3>
<H3> 3.2. Expressions </H3>
<H3> 3.3. Constant expressions </H3>
<H3> 3.4. Declarations </H3>
<H3> 3.5. Statements </H3>
<H3> 3.6. Inheritance </H3>
<H3> 3.7. Preprocessing directives </H3>
</BODY>
</HTML>