DIRECTORY CCTypes USING [CCError], CedarParseSupport USING [], IO USING [STREAM], MPP1 USING [Parse], MPTree USING [Link, Node, NodeName, Null], MPTreeOps USING [Finalize, Initialize, PopTree], Rope USING [Cat, ROPE]; CedarParseSupportImpl: CEDAR MONITOR IMPORTS CCTypes, MPP1, MPTreeOps, Rope EXPORTS CedarParseSupport = BEGIN Tree: TYPE = MPTree.Link; ParseCedarExpression: PUBLIC PROC[expr: Rope.ROPE, errout: IO.STREAM ¬ NIL] RETURNS[Tree] = BEGIN progTree: MPTree.Link; assignment: MPTree.Link; progTree ¬ Parse[Rope.Cat["Expr: PROGRAM = { x _ ", expr, "\n}."], errout]; IF progTree = NIL THEN CCTypes.CCError[syntax, NIL]; assignment ¬ GetFirstAssign[progTree]; IF assignment = NIL THEN CCTypes.CCError[syntax, NIL]; WITH assignment SELECT FROM node: REF MPTree.Node => BEGIN kind: MPTree.NodeName ¬ node.name; nsons: CARDINAL = node.sonLimit - 1; IF kind # assign THEN CCTypes.CCError[syntax, NIL]; RETURN [node[2]]; END; ENDCASE => CCTypes.CCError[syntax, NIL]; END; Parse: ENTRY PROC [program: Rope.ROPE, errout: IO.STREAM] RETURNS [root: Tree ¬ NIL] = TRUSTED { ENABLE UNWIND => NULL; complete: BOOL; nErrors: CARDINAL; MPTreeOps.Initialize[]; [complete, , nErrors] ¬ MPP1.Parse[program, errout]; root ¬ IF complete AND nErrors = 0 THEN MPTreeOps.PopTree[] ELSE MPTree.Null; MPTreeOps.Finalize[]; }; GetFirstAssign: PROC [tree: Tree] RETURNS [Tree] = { WITH tree SELECT FROM node: REF MPTree.Node => { kind: MPTree.NodeName ¬ node.name; nsons: CARDINAL = node.sonLimit - 1; IF kind = assign THEN RETURN [node]; FOR i: CARDINAL IN [1..nsons] DO nt: Tree ¬ GetFirstAssign[node[i]]; IF nt # NIL THEN RETURN [nt] ENDLOOP} ENDCASE; RETURN [NIL] }; END.. z CedarParseSupportImpl.mesa Copyright Σ 1992 by Xerox Corporation. All rights reserved. Sturgis, August 12, 1989 10:46:37 am PDT Willie-s, May 14, 1992 1:11 pm PDT Cedar parsing support These two procedures came from InterpImpl.mesa (existing Cirio code for local d-machine world). following code copied from InterpreterImpl (via InterpImpl.mesa) NOTE: this is an ENTRY procedure to avoid scrambling the poor parser's tiny brains when multiple processes try to interpret at the same time. Don't try to get rid of this protection! returns first assignment in the tree (where "first" is first in the preorder traversal) ΚY•NewlineDelimiter –(cedarcode) style™šœ™Jšœ Οeœ1™