RussellSyntax.mesa
Last Edited by: Demers, March 5, 1984 9:53:31 am PST
This module is concrete syntax definitions for Russell84. The following productions describe the concrete syntax:
exp ::= id
Identifier reference.
exp ::= type
exp ::= safetype
Built-in type constant.
exp ::= exp1 exp2
Application of a function or procedure to an argument. All functions are one-argument.
exp ::= exp1 ; exp2
Sequential execution. The value of exp1 is discarded, and the value of exp2 is produced as the value of the sequence.
exp ::= exp1 | exp2
Concatenation of tuples. What is the meaning when there are selector name clashes?
exp ::= exp . id
Selection of field from a tuple.
exp ::= if guardedExpSeq fi
exp ::= if guardedExpSeq else exp fi
exp ::= if guardedExpSeq else => exp fi
Conditional expression. Guards are evaluated sequentially, so the optional else clause is equivalent to adding a final guard guaranteed to succeed. What if the else clause is omitted?
exp ::= do guardedExpSeq od
Loop expression. The value produced on termination is <>.
exp ::= tuple id < BindingSeq >
Nonrecursive tuple formation.
exp ::= tuple id <* BindingSeq *>
Recursive tuple formation.
exp ::= open exp1 in exp2 ni
Binding. This is equivalent to a more conventional let construct when exp1 is tuple-valued, and meaningless otherwise.
exp ::= lambda typing in exp2 ni
Lambda abstraction. Note there is only one parameter.
exp ::= lambda [ TypingSeq ] in exp ni
Sugared lambda abstraction. There is only one parameter; it has the indicated product type. The sugared function is equivalent to an ordinary one with an immediate open of its parameter.
exp ::= func [ typing -> exp ]
Function type, safe.
exp ::= proc [ typing -> exp ]
Procedure type, unsafe.
exp ::= prod id [ TypingSeq ]
exp ::= [ TypingSeq ]
Product type.
exp ::= union [ TypingSeq ]
exp ::= union { TypingSeq }
exp ::= { TypingSeq }
Union type.
exp ::= ref [ exp ]
Reference (variable) type constructor.
GuardedExp ::= exp1 ? id => exp2
Guarded expression. The guard is enabled if exp1 evaluates to a tuple with a defined component of the given name.
GuardedExpSeq ::= guardedExp # ...
Sequence of guarded expressions.
Typing ::= id : exp
Typing (or, in old terminology, signature association).
TypingSeq ::= typing , ...
Sequence of typings.
Binding ::= id : exp1 ~ exp2
Binding ::= id ~ exp2
Binding ::= exp2
Binding of identifier to value. The type information is optional. In certain contexts the identifier can be inferred, and it too is optional.
BindingSeq ::= binding , ...
Sequence of bindings.
exp ::= charConst
exp ::= stringConst
exp ::= integerConst
Sugared built-in constants.
DIRECTORY
IO USING[ STREAM ] ;
RussellSyntax: CEDAR DEFINITIONS
= BEGIN
TokType: TYPE = {
tokId, -- identifier.
tokLParen, tokRParen, -- parentheses for grouping: ( )
tokKWtuple, -- keyword for tuple formation with local name
tokLTupleBrak, tokRTupleBrak, -- brackets for tuple formation: < >
tokLRecTupleBrak, tokRRecTupleBrak, -- brackets for recursive tuple formation: <* *>
tokLBrak, tokRBrak, -- general brackets for type formation: [ ]
tokKWfunc, -- for function type formation
tokKWproc, -- for procedure type formation
tokKWref, -- for reference (variable) type formation
tokKWprod, -- for product type formation
tokKWunion, -- for union type formation
tokLUnionBrak, tokRUnionBrak, -- alternative brackets for union type formation: { }
tokListSep, -- separator for list of typings/bindings: ,
tokStmtSep, -- separator for statement sequence: ;
tokGuardedExpSep, -- separator for guarded expression list: #
tokHasType, -- identifier-has-type glue: :
tokSelect, -- component selection infix operator: .
tokConcat, -- tuple concatentation operator: |
tokQuery, -- component-query glue for guarded expression: ?
tokIsBoundTo, -- identifier-is-bound-to glue: ~
tokGuardArrow, -- arrow for guarded list: =>
tokFunctionArrow, -- parameter-to-result-type arrow for function type: ->
tokKWif, tokKWelse, tokKWfi, -- conditional expression
tokKWdo, tokKWod, -- loop
tokKWopen, tokKWin, tokKWni, -- scope
tokKWlambda, -- function constructor
tokKWtype, tokKWsafetype, -- builtin constants
tokCharConst, -- single-character constant: as in Mesa
tokStringConst, -- character string constant: as in Mesa
tokIntConst, -- (nonnegative) integer constant: as in Mesa
tokError, -- syntax error in token
tokEOF
};
GetRussellToken: PROCEDURE [source: IO.STREAM, buffer: REF TEXT] RETURNS [tokType: TokType, tokVal: REF ANY, charsRead: INT] ;
Get next Russell token from the source STREAM, using the supplied mutable buffer for working text storage. Return the token type in tokType, and the total number of characters read (including the token itself) in charsRead. The significance of tokVal depends on tokType:
tokType = tokId => tokVal: ATOM has print name equal to the name of the identifier.
tokType = tokCharConst, tokStringConst or tokIntConst => tokVal: Rope.ROPE is equal to the literal text of the token, suitable for passing to the xxxxFromLiteral routines in the Convert interface.
otherwise => tokVal = NIL.
The scanner will return tokType = tokEOF repeatedly on end of stream.
! anything raised by source.GetChar[] except IO.EndOfStream.
END .