
GemStone Smalltalk Formal Syntax
--------------------------------

This is a complete BNF description of GemStone Smalltalk
$Id: bnf.txt,v 1.6 2008-01-02 23:36:14 otisa Exp $


Here are a few notes about interpreting the grammar:

A = expr	This defines the syntactic production `A' in terms of the 
		expression on the right side of the equals sign.

B = C | D	The vertical bar `|' defines alternatives. In this case, the 
		production "B" is one of either "C" or "D".

C = '<'		A symbol in accents is a literal symbol.

D = F G		A sequence of two or more productions means the 
		productions in the order of their appearance.

E = [ A ]	Brackets indicate optional productions.

F = { B }	Braces indicate zero or more occurrences of the productions 
		contained within.

G = A | (B|C)	Parentheses can be used to remove ambiguity.


GemStone Smalltalk BNF
----------------------
In the syntactic production for Assignment, white space is
required before and after the '_'  character .

Assignment = VariableName '_' Statement


In the following syntactic productions, white space is
allowed between tokens.


AExpression = Primary [ AMessage { ';' ACascadeMessage } ]

ABinaryMessage = ABinarySelector Primary [ UnaryMessages ]

ABinaryMessages = ABinaryMessage { ABinaryMessage }

ACascadeMessage = UnaryMessage | ABinaryMessage | AKeyWordMessage

AKeyWordMessage = AKeyWordPart { AKeyWordPart }

AKeyWordPart = KeyWord Primary UnaryMessages { ABinaryMessage }

AMessage = [UnaryMessages] [ABinaryMessages] [AKeywordMessage]

Array = '(' { ArrayItem } ')'

ArrayBuilder = '#[' [ AExpression { ',' AExpression } ] ']'

ArrayLiteral = '#' Array

CurlyArrayBuilder = '{' [ AExpression { '.' AExpression } ] '}'

ArrayItem = Number | Symbol | SymbolLiteral | StringLiteral |

            CharacterLiteral | Array | ArrayLiteral

Assignment = VariableName ':=' Statement

BinaryMessage = BinarySelector Primary [ UnaryMessages ]

BinaryMessages = BinaryMessage { BinaryMessage }

BinaryPattern = BinarySelector VariableName

Block = '[' [ BlockParameters ] [ Temporaries ] Statements ']'

BlockParameters = { Parameter } '|'

CascadeMessage = UnaryMessage | BinaryMessage | KeyWordMessage

Expression = Primary [ Message { ';' CascadeMessage } ]

KeyWordMessage = KeyWordPart { KeyWordPart }

KeyWordPart = KeyWord Primary UnaryMessages { BinaryMessage }

KeyWordPattern = KeyWord VariableName {KeyWord VariableName}

Literal = Number | NegNumber | StringLiteral | CharacterLiteral |

          SymbolLiteral | ArrayLiteral | SpecialLiteral

Message = [UnaryMessages] [BinaryMessages] [KeyWordMessage]

MessagePattern = UnaryPattern | BinaryPattern | KeyWordPattern

Method = MessagePattern [ Primitive ] MethodBody

MethodBody = [ Pragmas ] [ Temporaries ] [ Statements ]

NegNumber = '-' Number

Operand = Path | Literal | Identifier

Operator = '=' | '==' | '<' | '>' | '<=' | '>=' | '~=' | '~~'

ParenStatement = '(' Statement ')'

Predicate = ( AnyTerm | ParenTerm ) { '&' Term }

Primary = ArrayBuilder | CurlyArrayBuilder | Literal | Path | Block | SelectionBlock |

          ParenStatement | VariableName 

Primitive = '<' [ 'protected' | 'unprotected' ] [ 'primitive:' Digits ] '>'

Pragmas =   Pragma [ Pragma ]

Pragma = '< PragmaBody '>'

PragmaBody =  UnaryPragma | KeywordPragma

UnaryPragma  = SpecialLiteral | UnaryPragmaIdentifier

KeywordPragma = PragmaPair [ PragmaPair ]

PragmaPair =  [ KeywordNotPrimitive | BinarySelector ] PragmaLiteral

KeywordNotPrimitive  is any  Keyword  other than  'primitive:'

UnaryPragmaIdentifier is any  Identifier  except 'protected' , 'unprotected' , 'requiresVc'

PragmaLiteral = Number | NegNumber | StringLiteral | CharacterLiteral |
		SymbolLiteral | SpecialLiteral

SelectionBlock = '{' Parameter } '|' Predicate '}'

Statement = Assignment | Expression

Statements = { [ Pragmas] { Statement '.' } } [ Pragmas] [ ['^'] Statement ['.' [ Pragmas] ]] 

Temporaries = '|' { VariableName } '|'

ParenTerm = '(' AnyTerm ')'

Term = ParenTerm | Operand

AnyTerm = Operand [ Operator Operand ]

UnaryMessage = Identifier

UnaryMessages = { UnaryMessage }

UnaryPattern = Identifier


GemStone Smalltalk Lexical Tokens
---------------------------------
The following are lexical tokens. 
No white space is allowed within lexical tokens.

ABinarySelector = any BinarySelector except comma

BinaryExponent = ( 'e' | 'E' | 'd' | 'D' ) ['-' | '+'] Digits

BinarySelector = ( SelectorCharacter [SelectorCharacter]) |

                 ( '-' [ SelectorCharacter ] )

Character = Any Ascii character with ordinal value 0..255

CharacterLiteral = '$' Character

Comment = '"' { Character } '"'

DecimalExponent = ( 'f' | 'F' ) ['-' | '+'] Digits

Digit = '0' | '1' | '2' | ... | '9'

Digits = Digit {Digit}

Exponent = BinaryExponent | DecimalExponent | ScaledDecimalExponent

FractionalPart = '.' Digits [Exponent]

Identifier =  SingleLetterIdentifier | MultiLetterIdentifier 

KeyWord = Identifier ':'

Letter = 'A' | 'B' | ... | 'Z' | 'a' | 'b' | ... | 'z' | '_'

MultiLetterIdentifier = Letter { Letter | Digit }

Number = RadixedLiteral | NumericLiteral

Numeric = Digit | 'A' | 'B' | ... | 'Z'

NumericLiteral = Digits ( [FractionalPart] | [Exponent] )

Numerics = Numeric { Numeric }

Parameter = ':' VariableName                [NOTE: white space allowed
					     between  :  and variableName ]

Path = Identifier '.' PathIdentifier { '.' PathIdentifier }

PathIdentifier  =  Identifier |  '*'

RadixedLiteral = Digits ( '#' | 'r' ) ['-'] Numerics

ScaledDecimalExponent =  's' ['-' | '+'] Digits

SelectorCharacter = '+' | '\' | '*' | '~' | '<' | '>' | '=' 

            | '|' | '/' | '&' | '@' | '%' | ',' | '?' | '!'

SingleLetter 'A' | 'B' | ... | 'Z' | 'a' | 'b' | ... | 'z' 

SingleLetterIdentifier =  SingleLetter

SpecialLiteral = 'true' | 'false' | 'nil' | '_remoteNil' 

StringLiteral = "'" { Character | "''" } "'"

Symbol = Identifier | BinarySelector | ( Keyword { Keyword } )

SymbolLiteral = '#' ( Symbol | StringLiteral )

VariableName = Identifier
