-- S-expression parser. According to the current spec, any of the -- following objects constitute a S-expr: -- -- - atom: a sequence containing any characters except spaces or parens, -- i.e. ( or ); atoms are separated by these characters and may not -- begin with any of (, ), #, . or '; if an atom is composed only of -- numeric decimal characters, then it is parsed as a number; otherwise -- it is parsed as an interned symbol. -- -- - hash expression: any expression beginning with #; currently, -- expression beginning with # are the boolean values #t and #f, and -- escaped characters, e.g. #\a (the character corresponding to the -- letter a). -- -- - cons expression: cons expressions begin with a (, contain any -- number of space-separated sub-expressions and end with ), e.g. (a b -- c d) denotes the list containing the symbols a, b, c and d, () -- denotes the empty list, etc.; a cons expression may optionally -- contain a period (.) token before the last element, signifying that -- the last element is set as the cdr of the last cons cell, e.g. (1 2 -- . 3) corresponds to (cons 1 (cons 2 3)). -- -- - quoted expression: any expression beginning with a single quote (') -- token; 'expr (where expr is an arbitrary S-expression) gets -- translated to (quote expr). with LispM; use LispM; package Parser is type TokenID is (Error_Token, Bool_Token, Num_Token, List_Token, Char_Token, Symbol_Token, ListE_Token, ListP_Token, Quoted_Token); -- Given a string, check if all its characters are digits. procedure Parse_Integer(Str : in MemPtr; Success : out Boolean; I : out Long_Integer); -- Eat whitespace. procedure Eat_Whitespace; -- Parse a list of characters not in the reserved set. procedure Parse_Atom(P : out MemPtr); -- Parse a hash-prepended expression. procedure Parse_Hash(P : out MemPtr; TID : out TokenID); -- Parse cons objects, i.e. lists and pairs. procedure Parse_Cons(P : out MemPtr); -- Parse quoted expression. procedure Parse_Quoted(P : out MemPtr; TID : out TokenID); -- Parse an S-expression given as input on the console. Output a -- pointer to the parsed expression and its type, as represented by -- TokenID. procedure Parse(P : out MemPtr; TID : out TokenID); end Parser;