home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / program / language / bob / doc / Ref / Syntax < prev    next >
Encoding:
Text File  |  1994-12-25  |  5.1 KB  |  147 lines

  1. ArmBob v.2.1 Reference                                GCW 29/11/94
  2.  
  3.          ----------------- SYNTAX ---------------
  4.  
  5. Armbob Syntax follows that of C, with some extensions and some omissions.
  6. Every statement returns a value, including assignment statements.
  7. This is one of the features of C that gives it its particular flavour.
  8.  
  9. Comments
  10. --------
  11.  
  12. Armbob has two kinds of comment: single- and multi-line. They have
  13. the same syntax as comments in C++.
  14.  
  15. Single-line comments are introduced by // and are terminated by the
  16. end of the line or file.
  17.  
  18. Multi-line comments start with /* and end with the next */. They are 
  19. not nestable.
  20.  
  21. Names
  22. -----
  23. Blank spaces, tab characters and newlines are ignored in Armbob, except 
  24. in so far as they mark the end of a name. Names must begin with a letter 
  25. of the alphabet, and subsequently must consist of letters of the 
  26. alphabet ('A'-'Z', 'a'-'z'), digits ('0'-'9'), or the underscore
  27. character '_'. ArmBob also permits '@', '$', '£' and '`' in names.
  28.  
  29. It may be useful, but it is not mandatory, to use these extra characters
  30. as prefixes or suffixes on names, to indicate the type of object they
  31. denote, in the following way
  32.  
  33.     @    for addresses of buffers in memory,
  34.     $    for strings,
  35.     £    for integers or 4-byte words,
  36.     `    for bytes or characters.
  37.  
  38. This mnemonic convention fits the names for the storage functions
  39. needed for low-level access. Thus, if s is a string, @(s) denotes
  40. the integer address at which the contents of s are held. If a is
  41. an address, $(a) denotes the string at a, terminated by a control
  42. character, £(a) denotes the word stored at a, and `(a) denotes the
  43. byte stored at a. 
  44.  
  45. Names may be up to 50 characters long. Program lines may be up to 
  46. 200 characters long.
  47.  
  48. Grammar
  49. -------
  50. The grammar is very similar to that of C.
  51.  
  52. Syntactic classes (non-terminal symbols) are written in angle 
  53. brackets. Square brackets denote optional items, while '[' and 
  54. ']' denote actual square brackets (terminal symbols). A solidus
  55. (|) denotes an alternative.
  56.  
  57. Program ::= [ <Defs> ] <Main_def> [ <Defs> ]
  58. Defs ::= <Def> [ <Defs> ]
  59. Def  ::= <Class_def> | <Fun_def>
  60. Class_def ::= class <CName> [ : <CName> ] { <Class_body> }
  61. Fun_def ::= [ <Cname> :: ] <FName> ( [ <FArgs> ] ) { <Fun_body> }
  62. Main_def ::= main() { <Fun_body> }
  63. Class_body ::=  <Member> ; [ <Class_body> ] 
  64. Member ::= [static] <Data> | [static] <FName> ( [ <FArgs> ] )
  65. Data ::= <Variable> [ , <Data> ]
  66. FArgs ::= <Variable> [ , <FArgs> ]
  67. Fun_body ::= [ local <Args> ; ] <Statements>
  68. Statements ::= <Statement> <Statements>
  69. Statement ::= [ <Single> ] ; | { <Statements> } | <Control>
  70. Control ::= if ( <Expr> ) <Statement> [ else <Statement> ]
  71.           | while ( <Expr> ) <Statement>
  72.           | do <Statement> while ( <Expr> ) 
  73.           | repeat <Statement> until ( <Expr> )
  74.           | do <Statement> until ( <Expr> )
  75.           | repeat <Statement> while ( <Expr> )
  76.           | for ( <Expr> ; <Expr> ; <Expr> ) <Statement>
  77.           | switch ( <Expr> ) { <Alternatives> [ default : <Statements> }
  78.           | in <Expr> put { <Items> }
  79. Single ::= break | continue | return <Expr> | <Expr>
  80. Items ::= <Expr> ; <Items>
  81. Alternatives ::= case <Expr> : <Statements> <Alternatives>
  82. Expr ::= <Expr> , <Expr>
  83.        | <Lval> <Assign> <Expr>
  84.        | <Expr> ? <Expr> : <Expr>
  85.        | <Expr> <Binop> <Expr>
  86.        | <Unop> <Expr>
  87.        | ++ <Lvalue>
  88.        | <Lvalue> ++
  89.        | -- <Lvalue>
  90.        | <Lvalue> --
  91.        | new <Cname> ( [ <Expr> ] )
  92.        | <Expr> ( [ <Expr> ] )
  93.        | <Expr> -> <Fname> ( [ <Expr> ] )
  94.        | <Expr> '[' <Expr> ']'
  95.        | vector { <Components> }
  96.        | enum { <Data> }
  97.        | ( <Expr> )
  98.        | <Variable>
  99.        | <Number>
  100.        | "<String>"
  101.        | '<Character>'
  102.        | nil
  103.        | <Constant>
  104. Components = <Expr> ; [<Components>]
  105. Assign ::= = | += | -= | *= | /= | %= | &= | |= | ^= | <<= | >>=
  106. Binop ::= || | && | '|' | ^ | & | == | != | < | <= | >= | >
  107.         | >> | << | + | - | * | % | /
  108. Unop ::= - | ! | ~ 
  109. Lvalue ::= <Variable> | <Expr> '[' <Expr> ']'
  110. Number ::= <Decimal>[.<Decimal>] | &<Hexnumber>
  111. Decimal ::= <Digit><Decimal>
  112. Hexnumber ::= <Hexdigit><Hexnumber>
  113. Digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
  114. Hexdigit ::= a | b | c | d | e | f | <Digit>
  115. Character ::= <Char> | "
  116. String ::= <Char><String>
  117. Char ::= Any ASCII character except ", \ or control codes | \n | \t | \\
  118. Cname ::= <Identifier>
  119. Fname ::= <Identifier>
  120. Variable ::= <Identifier>
  121. Identifier ::= <Alpha><Alphanum>
  122. Alphanum ::= <Alpha> | <Digit>
  123. Alpha ::= [A-Z] | [a-z] | _ | @ | $ | £ | `
  124.  
  125.  
  126. The differences from C are:
  127.  
  128.   No type declarations in Armbob. Use classes instead.
  129.  
  130.   The use of vectors or methods instead of pointers.
  131.  
  132.   Automatic memory allocation and garbage collection for strings
  133.   and vectors.
  134.  
  135.   The 'in b put { x1; ... xn; }' structure.
  136.  
  137.   The synonym 'repeat' for 'do'.
  138.  
  139.   The use of 'nil' as well as zero as a conditional.
  140.  
  141.   The absence of coercion between integer and real numbers in addition 
  142.   and subtraction. 
  143.  
  144.   All datatypes are first-class. For example, functions and instance
  145.   objects can be arguments to functions or returned by functions.
  146.                                             
  147.              --------- END -----------