home *** CD-ROM | disk | FTP | other *** search
- <TITLE>Grammar for ArmBob 2.0</TITLE>
- <H2>Grammar for ArmBob 2.0</H2>
- Armbob <A HREF="#Syntax"> Syntax</A> follows that of C, with some
- extensions and some omissions.
- Every statement returns a value, including
- assignment statements.
- <H4>Comments</H4>
- Armbob has two kinds of comment: single- and multi-line.
- They have the same syntax as comments in C++.
- <UL>
- <LI>Single-line comments are introduced by <CODE> // </CODE>
- and are terminated by the end of the line or file.
- <LI>Multi-line comments start with <CODE> /* </CODE>
- and end with the next <CODE> */ </CODE>. They are
- not nestable.
- </UL>
- <H4>Names</H4>
- Blank spaces, tab characters and newlines are ignored in
- Armbob, except in so far as they mark the end of a name.
- Names must begin with a letter of the alphabet, and
- subsequently must consist of letters of the alphabet,
- digits, or the characters
- <CODE> _ @ $ £ `</CODE> .
- <P>
- It may be useful, but it is not mandatory, to use
- these extra characters as prefixes or suffixes on names,
- to indicate the type of object they denote, in the
- following way:
- <UL>
- <LI><CODE>@ </CODE> for addresses of buffers in memory
- <LI><CODE>$ </CODE> for strings
- <LI><CODE>£ </CODE> for integers or 4-byte words
- <LI><CODE>` </CODE> for bytes or characters
- </UL>
- This mnemonic convention fits the names for the storage
- functions needed for low-level access. Thus, if
- <CODE> s </CODE> is a string, <CODE> @(s) </CODE>
- denotes the integer address at which the contents
- of <CODE> s </CODE> are held. If <CODE> a </CODE> is
- an address <CODE> $(a) </CODE> denotes the string
- at <CODE> a </CODE>, terminated by a control character,
- <CODE> £(a) </CODE> denotes the word stored at
- <CODE> a </CODE>, and <CODE> `(a) </CODE> denotes
- the byte stored at <CODE> a </CODE>.
- <P>
- Names may be up to 50 characters long.
- Program lines may be up to 200 characters long.
- <HR>
- <H4><A NAME="Syntax"> Syntax</A></H4>
-
- <DL>
- <DT><EM>Program</EM> ::=
- <DD>[ Defs ] Main_def [ Defs ]
-
- <DT><EM>Defs</EM> ::=
- <DD>Def [ Defs ]
-
- <DT><EM>Def</EM> ::=
- <DD>Class_Def | Fun_def
-
- <DT><EM>Class_def</EM> ::=
- <DD><CODE>class</CODE> CName
- [ <CODE>:</CODE> CName ]
- <CODE>{</CODE> Class_body <CODE>}</CODE>
-
- <DT><EM>Fun_def</EM> ::=
- <DD>[ CName <CODE>::</CODE> ]
- FName <CODE>(</CODE> [ FArgs ]
- <CODE>) {</CODE> Fun_body <CODE>}</CODE>
-
- <DT><EM>Main_def</EM> ::=
- <DD><CODE>main() {</CODE> Fun_body <CODE>}</CODE>
-
- <DT><EM>Class_body</EM> ::=
- <DD>Member <CODE>;</CODE> [ Class_body ]
-
- <DT><EM>Member</EM> ::=
- <DD>[<CODE>static</CODE>] Data | [<CODE>static</CODE>]
- FName <CODE>(</CODE> [ FArgs ] <CODE>)</CODE>
-
- <DT><EM>Data</EM> ::=
- <DD>Variable [ <CODE>,</CODE> Data ]
-
- <DT><EM>FArgs</EM> ::=
- <DD>Variable [ <CODE>,</CODE> FArgs ]
-
- <DT><EM>Fun_body</EM> ::=
- <DD>[ <CODE>local</CODE> Args <CODE>;</CODE> ]
- Statements
-
- <DT><EM>Statements</EM> ::=
- <DD>Statement Statements
-
- <DT><EM>Statement</EM> ::=
- <DD>[ Single ] <CODE>;</CODE> |
- <CODE>{</CODE> Statements <CODE>}</CODE>
- | Control
-
- <DT><EM>Control</EM> ::=
- <DD><CODE>if (</CODE> Expr <CODE>)</CODE>
- Statement [ <CODE>else</CODE> Statement ]
-
- <DD>| <CODE>while (</CODE> Expr <CODE>)</CODE> Statement
-
- <DD>| <CODE>do</CODE> Statement <CODE> while (</CODE>
- Expr <CODE>)</CODE>
-
- <DD>| <CODE>repeat</CODE> Statement <CODE>until (</CODE>
- Expr <CODE>)</CODE>
-
- <DD>| <CODE>do</CODE> Statement <CODE> until (</CODE>
- Expr <CODE>)</CODE>
-
- <DD>| <CODE>repeat</CODE> Statement <CODE>while (</CODE>
- Expr <CODE>)</CODE>
-
- <DD>| <CODE>for (</CODE> Expr <CODE>;</CODE>
- Expr <CODE>;</CODE> Expr <CODE>)</CODE>
- Statement
-
- <DD>| <CODE>switch (</CODE> Expr <CODE>) {</CODE>
- Alternatives [ <CODE>default :</CODE>
- Statements ] <CODE>}</CODE>
-
- <DD>| <CODE>in</CODE> Expr <CODE>put {</CODE>
- Items <CODE>}</CODE>
-
- <DT><EM>Single</EM> ::=
- <DD><CODE>break</CODE> |
- <CODE>continue</CODE> |
- <CODE>return</CODE> Expr | Expr
-
- <DT><EM>Items</EM> ::=
- <DD>Expr <CODE>;</CODE> Items
-
- <DT><EM>Alternatives</EM> ::=
- <DD><CODE>case</CODE> Expr <CODE>:</CODE>
- Satements Alternatives
-
- <DT><EM>Expr</EM> ::=
- <DD>Expr <CODE>,</CODE> Expr
-
- <DD>| Lvalue Assign Expr
-
- <DD>| Expr <CODE>?</CODE> Expr <CODE>:</CODE> Expr
-
- <DD>| Expr Binop Expr
-
- <DD>| Unop Expr
-
- <DD>| <CODE>++</CODE> Lvalue
-
- <DD>| Lvalue <CODE>++</CODE>
-
- <DD>| <CODE>--</CODE> Lvalue
-
- <DD>| Lvalue <CODE>--</CODE>
-
- <DD>| <CODE>new</CODE> Cname <CODE>(</CODE>
- [ Expr ] <CODE>)</CODE>
-
- <DD>| Expr <CODE>(</CODE> [ Expr ] <CODE>)</CODE>
-
- <DD>| Expr <CODE>-></CODE> Fname <CODE>(</CODE>
- [ Expr ] <CODE>)</CODE>
-
- <DD>| Expr <CODE>[</CODE> Expr <CODE>]</CODE>
-
- <DD>| <CODE>vector {</CODE> Items <CODE>}</CODE>
-
- <DD>| <CODE>enum {</CODE> Data <CODE>}</CODE>
-
- <DD>| <CODE>(</CODE> Expr <CODE>)</CODE>
-
- <DD>| Variable
-
- <DD>| Number
-
- <DD>| <CODE>"</CODE>String<CODE>"</CODE>
-
- <DD>| <CODE>' </CODE>Character<CODE>'</CODE>
-
- <DD>| <CODE>nil</CODE>
-
- <DD>| Constant
-
- <DT><EM>Assign</EM> ::=
- <DD><CODE> = </CODE> |
- <CODE> += </CODE> |
- <CODE> -= </CODE> |
- <CODE> *= </CODE> |
- <CODE> /= </CODE> |
- <CODE> %= </CODE> |
- <CODE> &= </CODE> |
- <CODE> |= </CODE> |
- <CODE> ^= </CODE> |
- <CODE> <<= </CODE> |
- <CODE> >>= </CODE>
-
- <DT><EM>Binop</EM> ::=
- <DD><CODE>|| </CODE> |
- <CODE>| </CODE> |
- <CODE> && </CODE> |
- <CODE> & </CODE> |
- <CODE> ^ </CODE> |
- <CODE> == </CODE> |
- <CODE> != </CODE> |
- <CODE> < </CODE> |
- <CODE> <= </CODE> |
- <CODE> > </CODE> |
- <CODE> >=</CODE> |
- <CODE> >></CODE> |
- <CODE> <<</CODE> |
- <CODE> + </CODE> |
- <CODE> - </CODE> |
- <CODE> * </CODE> |
- <CODE> % </CODE> |
- <CODE> / </CODE>
-
- <DT><EM>Unop</EM> ::=
- <DD><CODE> - </CODE>
- | <CODE> ! </CODE>
- | <CODE> ~ </CODE>
-
- <DT><EM>Lvalue</EM> ::=
- <DD>Variable
- | Expr <CODE>[</CODE> Expr <CODE>]</CODE>
-
- <DT><EM>Number</EM> ::=
- <DD>Decimal[<CODE>.</CODE>decimal]
- | <CODE>&</CODE>Hexnumber
-
- <DT><EM>Decimal</EM> ::=
- <DD>DigitDecimal
-
- <DT><EM>Hexnumber</EM> ::=
- <DD>HexdigitHexnumber
-
- <DT><EM>Digit</EM> ::=
- <DD><CODE>0</CODE>
- | <CODE>1</CODE>
- | <CODE>2</CODE>
- | <CODE>3</CODE>
- | <CODE>4</CODE>
- | <CODE>5</CODE>
- | <CODE>6</CODE>
- | <CODE>7</CODE>
- | <CODE>8</CODE>
- | <CODE>9</CODE>
-
- <DT><EM>Hexdigit></EM> ::=
- <DD>Digit
- | <CODE>a</CODE>
- | <CODE>b</CODE>
- | <CODE>c</CODE>
- | <CODE>d</CODE>
- | <CODE>e</CODE>
- | <CODE>f</CODE>
-
- <DT><EM>Character</EM> ::=
- <DD>Char | <CODE>"</CODE>
-
- <DT><EM>String</EM> ::=
- <DD>CharString
-
- <DT><EM>Char</EM> ::=
- <DD><CODE>\n</CODE>
- | <CODE>\t</CODE>
- | <CODE>\\</CODE>
- | Any ASCII character except ", \ or control code
-
- <DT><EM>Cname</EM> ::=
- <DD>Identifier
-
- <DT><EM>Fname</EM> ::=
- <DD>Identifier
-
- <DT><EM>Variable</EM> ::=
- <DD>Identifier
-
- <DT><EM>Identifier</EM> ::=
- <DD>Alpha | Digit
-
- <DT><EM>Alpha</EM> ::=
- <DD>[<CODE>A-Z</CODE>]
- | [<CODE>a-z</CODE>]
- | <CODE>_</CODE>
- | <CODE>@</CODE>
- | <CODE>$</CODE>
- | <CODE>£</CODE>
- | <CODE>`</CODE>
- </DL>
-
- The non-terminal <EM>Constant</EM> reduces to the terminals listed as
- <A HREF="synonyms"> synonyms</A>.
-
-
-