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