SELECT tokType
FROM
tokLParen =>
BEGIN
Exp ::= ( Exp ) -- Parenthesized expression.
Scan[];
tempICExp1 ← ParseExp[];
RequireAndRecoverTo[typeWanted~tokRParen, errMsg~"expecting right paren", recoverProc~RecoverExp];
RETURN[ tempICExp1 ]
END ;
tokKWtuple, tokLTupleBrak, tokLRecTupleBrak =>
BEGIN
Exp ::= tuple Id < BindingSeq > -- Tuple formation.
Exp ::= tuple Id <* BindingSeq *> -- Recursive tuple formation.
localName: ATOM ← NIL;
IF tokType = tokKWtuple
THEN
BEGIN
Scan[];
IF tokType = tokId
THEN BEGIN
localName ← NARROW[ tokVal ];
Scan[];
END
END ;
SELECT tokType
FROM
tokLTupleBrak =>
BEGIN
Scan[];
tempICBinding ← ParseBindings[nameRequired~FALSE];
tempICExp1 ←
NEW[ MkTupleICNode
← [ bindings~tempICBinding, localName~localName]];
RequireAndRecoverTo[typeWanted~tokRTupleBrak, errMsg~"expecting right tuple bracket", recoverProc~RecoverBinding]
END ;
tokLRecTupleBrak =>
BEGIN
Scan[];
tempICBinding ← ParseBindings[nameRequired~TRUE];
tempICExp1 ←
NEW[ MkRecTupleICNode
← [ bindings~tempICBinding, localName~localName]];
RequireAndRecoverTo[typeWanted~tokRRecTupleBrak, errMsg~"expecting right recursive tuple bracket", recoverProc~RecoverBinding];
END ;
ENDCASE =>
BEGIN
LogError[ errMsg~"expecting left tuple bracket"];
tempICExp1 ← NIL
END ;
RETURN[ tempICExp1 ]
END ;
tokKWfunc, tokKWproc =>
BEGIN
Exp ::= func[ Id: Exp -> Exp ] -- Function type.
Exp ::= proc[ Id: Exp -> Exp ] -- Procedure type.
isFunc: BOOL ← (tokType = tokKWfunc);
Scan[];
Mandatory[ typeWanted~tokLBrak, errMsg~"expecting left bracket"];
tempICTyping ← ParseTyping[nameRequired~FALSE];
Mandatory[typeWanted~tokFunctionArrow, errMsg~"expecting arrow"];
tempICExp1 ← ParseExp[];
IF isFunc
THEN tempICExp2 ← NEW[ FuncICNode ← [param~tempICTyping, resultType~tempICExp1]]
ELSE tempICExp2 ← NEW[ ProcICNode ← [param~tempICTyping, resultType~tempICExp1]];
ScanThrough[typeWanted~tokRBrak, errMsg~"expecting right bracket"];
RETURN[ tempICExp2 ]
END ;
tokKWprod, tokLBrak =>
BEGIN
Exp ::= prod Id [ TypingSequence ] -- Product type with local name.
Exp ::= prod [ TypingSequence ] -- Product type without local name.
Exp ::= [ TypingSequence ] -- Product type without local name.
localName: ATOM ← NIL;
IF tokType = tokKWprod
THEN
BEGIN
Scan[];
IF tokType = tokId
THEN BEGIN
localName ← NARROW[ tokVal ];
Scan[]
END
END;
Mandatory[ typeWanted~tokLBrak, errMsg~"expecting left bracket"];
tempICTyping ← ParseTypings[nameRequired~TRUE];
tempICExp1 ← NEW[ ProductICNode ← [components~tempICTyping] ];
RequireAndRecoverTo[typeWanted~tokRBrak, errMsg~"expecting right bracket", recoverProc~RecoverTyping];
RETURN[ tempICExp1 ]
END ;
tokKWunion, tokLUnionBrak =>
BEGIN
Exp ::= union [ TypingSequence ]
Exp ::= union { TypingSequence }
Exp ::= { TypingSequence } -- Union type constructor.
brakTypeWanted: RussellSyntax.TokType;
IF tokType = tokKWunion
THEN
BEGIN
Scan[]
END;
SELECT tokType
FROM
tokLBrak =>
{ brakTypeWanted ← tokRBrak; Scan[] } ;
tokLUnionBrak =>
{ brakTypeWanted ← tokRUnionBrak; Scan[] } ;
ENDCASE =>
{ LogError[ errMsg~"expecting left bracket"]; } ;
tempICTyping ← ParseTypings[nameRequired~TRUE];
tempICExp1 ← NEW[ UnionICNode ← [components~tempICTyping] ];
RequireAndRecoverTo[typeWanted~brakTypeWanted, errMsg~"expecting right bracket", recoverProc~RecoverTyping];
RETURN[ tempICExp1 ]
END ;
tokKWref =>
BEGIN
Exp ::= ref [ Exp ] -- Reference type constructor.
Scan[];
Mandatory[ typeWanted~tokLBrak, errMsg~"expecting left bracket"];
tempICExp1 ← ParseExp[];
tempICExp2 ← NEW[ RefICNode ← [referentType~tempICExp1] ];
RequireAndRecoverTo[typeWanted~tokRBrak, errMsg~"bad ref type", recoverProc~RecoverExp];
RETURN[ tempICExp2 ]
END ;
tokKWif =>
BEGIN
Exp ::= if GuardedExpSeq fi -- Conditional.
Scan[];
tempICGuardedExp ← ParseGuardedExps[];
IF tokType = tokKWelse
THEN
BEGIN
Scan[];
Optional[typeWanted~tokGuardArrow];
tempICExp1 ← ParseExp[]
END
ELSE
BEGIN
tempICExp1 ← NIL
END ;
tempICExp2 ← NEW[ CondICNode ← [thenClauses~tempICGuardedExp, elseExp~tempICExp1]];
RequireAndRecoverTo[typeWanted~tokKWfi, errMsg~"bad guarded exp list in conditional", recoverProc~RecoverGuardedExp];
RETURN[ tempICExp2 ]
END ;
tokKWdo =>
BEGIN
Exp ::= do GuardedExpSeq od -- Loop.
Scan[];
tempICGuardedExp ← ParseGuardedExps[];
tempICExp1 ← NEW[ LoopICNode ← [loopClauses~tempICGuardedExp]];
RequireAndRecoverTo[typeWanted~tokKWod, errMsg~"bad guarded exp list in loop", recoverProc~RecoverGuardedExp];
RETURN[ tempICExp1 ]
END ;
tokKWopen =>
BEGIN
Exp ::= open Exp in Exp ni -- Block.
Scan[];
tempICExp1 ← ParseExp[];
Mandatory[typeWanted~tokKWin, errMsg~"expecting in"];
tempICExp2 ← ParseExp[];
tempICExp2 ← NEW[ OpenICNode ← [tuple~tempICExp1, body~tempICExp2]];
RequireAndRecoverTo[typeWanted~tokKWni, errMsg~"bad open body", recoverProc~RecoverExp];
RETURN[ tempICExp2 ]
END ;
tokKWlambda =>
BEGIN
Scan[];
tempICTyping ← ParseTyping[nameRequired~FALSE];
Mandatory[typeWanted~tokKWin, errMsg~"expecting in"];
tempICExp1 ← ParseExp[];
tempICExp2 ← NEW[ LambdaICNode ← [param~tempICTyping, body~tempICExp1] ];
RequireAndRecoverTo[typeWanted~tokKWni, errMsg~"bad function body", recoverProc~RecoverExp];
RETURN[ tempICExp2 ]
END ;
tokId =>
BEGIN
tempICExp1 ← NEW[ IdICNode ← [name ~ NARROW[tokVal]]];
Scan[];
RETURN[ tempICExp1 ]
END ;
tokKWtype =>
BEGIN
Scan[];
tempICExp1 ← NEW[ PrimConstICNode ← [which~$type]];
RETURN[ tempICExp1 ]
END ;
tokKWsafetype =>
BEGIN
Scan[];
tempICExp1 ← NEW[ PrimConstICNode ← [which~$safetype]];
RETURN[ tempICExp1 ]
END ;
tokCharConst =>
BEGIN
tempICExp1 ← NEW[ CharConstICNode ← [which ~ Convert.CharFromLiteral[r~NARROW[tokVal]]]];
Scan[];
RETURN[ tempICExp1 ]
END ;
tokStringConst =>
BEGIN
tempICExp1 ← NEW[ StringConstICNode ← [which ~ Convert.RopeFromLiteral[r~NARROW[tokVal]]]];
Scan[];
RETURN[ tempICExp1 ]
END ;
tokIntConst =>
BEGIN
tempICExp1 ← NEW[ IntConstICNode ← [which ~ Convert.IntFromRope[r~NARROW[tokVal]]]];
Scan[];
RETURN[ tempICExp1 ]
END ;
ENDCASE =>
BEGIN
LogError[errMsg~"syntax error"];
RETURN[ NIL ]
END ;