adalisp_genesis 1 -- S-expression parser. According to the current spec, any of the
adalisp_genesis 2 -- following objects constitute a S-expr:
adalisp_genesis 3 --
adalisp_genesis 4 -- - atom: a sequence containing any characters except spaces or parens,
adalisp_genesis 5 -- i.e. ( or ); atoms are separated by these characters and may not
adalisp_genesis 6 -- begin with any of (, ), #, . or '; if an atom is composed only of
adalisp_genesis 7 -- numeric decimal characters, then it is parsed as a number; otherwise
adalisp_genesis 8 -- it is parsed as an interned symbol.
adalisp_genesis 9 --
adalisp_genesis 10 -- - hash expression: any expression beginning with #; currently,
adalisp_genesis 11 -- expression beginning with # are the boolean values #t and #f, and
adalisp_genesis 12 -- escaped characters, e.g. #\a (the character corresponding to the
adalisp_genesis 13 -- letter a).
adalisp_genesis 14 --
adalisp_genesis 15 -- - cons expression: cons expressions begin with a (, contain any
adalisp_genesis 16 -- number of space-separated sub-expressions and end with ), e.g. (a b
adalisp_genesis 17 -- c d) denotes the list containing the symbols a, b, c and d, ()
adalisp_genesis 18 -- denotes the empty list, etc.; a cons expression may optionally
adalisp_genesis 19 -- contain a period (.) token before the last element, signifying that
adalisp_genesis 20 -- the last element is set as the cdr of the last cons cell, e.g. (1 2
adalisp_genesis 21 -- . 3) corresponds to (cons 1 (cons 2 3)).
adalisp_genesis 22 --
adalisp_genesis 23 -- - quoted expression: any expression beginning with a single quote (')
adalisp_genesis 24 -- token; 'expr (where expr is an arbitrary S-expression) gets
adalisp_genesis 25 -- translated to (quote expr).
adalisp_genesis 26 with LispM; use LispM;
adalisp_genesis 27
adalisp_genesis 28 package Parser is
adalisp_genesis 29 type TokenID is (Error_Token, Bool_Token, Num_Token, List_Token,
adalisp_genesis 30 Char_Token, Symbol_Token, ListE_Token, ListP_Token,
adalisp_genesis 31 Quoted_Token);
adalisp_genesis 32
adalisp_genesis 33 -- Given a string, check if all its characters are digits.
adalisp_genesis 34 procedure Parse_Integer(Str : in MemPtr;
adalisp_genesis 35 Success : out Boolean;
adalisp_genesis 36 I : out Long_Integer);
adalisp_genesis 37 -- Eat whitespace.
adalisp_genesis 38 procedure Eat_Whitespace;
adalisp_genesis 39
adalisp_genesis 40 -- Parse a list of characters not in the reserved set.
adalisp_genesis 41 procedure Parse_Atom(P : out MemPtr);
adalisp_genesis 42
adalisp_genesis 43 -- Parse a hash-prepended expression.
adalisp_genesis 44 procedure Parse_Hash(P : out MemPtr; TID : out TokenID);
adalisp_genesis 45
adalisp_genesis 46 -- Parse cons objects, i.e. lists and pairs.
adalisp_genesis 47 procedure Parse_Cons(P : out MemPtr);
adalisp_genesis 48
adalisp_genesis 49 -- Parse quoted expression.
adalisp_genesis 50 procedure Parse_Quoted(P : out MemPtr; TID : out TokenID);
adalisp_genesis 51
adalisp_genesis 52 -- Parse an S-expression given as input on the console. Output a
adalisp_genesis 53 -- pointer to the parsed expression and its type, as represented by
adalisp_genesis 54 -- TokenID.
adalisp_genesis 55 procedure Parse(P : out MemPtr; TID : out TokenID);
adalisp_genesis 56 end Parser;