<> <<>> <> <> <<>> <> <> DIRECTORY Rope USING [ROPE], Lexer USING [Handle], HerculesAlgebra USING [Se] ParseTable USING [Properties, PRec]; HerculesParser: DEFINITIONS = BEGIN OPEN PTab: ParseTable, Alg: HerculesAlgebra; Handle: TYPE = REF HandleRec; HandleRec: TYPE = RECORD [error: Rope.ROPE _ NIL, -- set to error message on lexical error eof: BOOL _ FALSE, -- initially FALSE, set to TRUE on end of input. result: Alg.Se _ NIL, -- contains last thing produced by Parse. openCount: INT _ 0, -- number of unmatched matchfixs or subfixs in last thing parsed in: Lexer.Handle _ NIL, -- Source of lexemes to be parsed. -- WARNING The initial value of in.a is relevant; see "Parse" below defaultIdProps: PTab.Properties _ NIL, -- default properties of identifiers table: PTab.Handle _ NIL]; -- associates operator types with operators. NewHandle: PROC RETURNS [h: Handle]; Parse: PUBLIC PROC[h: Handle]; -- sets h.result to the List representing the longest prefix of -- the lexeme stream h.in that is a valid symbolic expression, -- counting the current value of h.in.a as the first lexeme. Thus -- the way to start the parser is to call Lex[h.in]; Parse[h]. -- This will parse one expression and leave in h.in.a the first lexeme -- not used in the parse tree; thus successive calls will work. -- Sets h.eof if h.in.eof is set -- Sets h.error if h.in.error is set, or if a parse error occurs. -- If h.error AND NOT h.in.error AND NOT h.in.eof then the input can be reconstructed -- by Unparse[h.result]; print h.in.a; print all of h.in, except that -- in the unparse you should skip the NIL that appears at the right-most -- position in h.result. END. <<>> <> <> <>