-- JaMScanner.mesa
-- Last changed by Bill Paxton, 22-Jan-82 10:33:08

DIRECTORY
  JaMBasic USING [Object],
  JaMInternal USING [Frame],
  JaMOps USING [Text],
  StreamDefs USING [StreamHandle];

JaMScanner: DEFINITIONS = {

-- Types

StreamHandle: TYPE = StreamDefs.StreamHandle;

Class: TYPE = {
  eos, -- end of source
  crt, -- CR
  dlm, -- delimiter (SP,TAB,LF,comma)
  com, -- %    comment
  lpr, -- (    start of string token
  rpr, -- )    end of string token
  lbr, -- {    start of array token
  rbr, -- }    end of array token
  quo, -- "    start/end of quoted string
  bsl, -- \    escape char in quoted string
  num, -- 0..9 numeric
  sgn, -- + -  sign
  dot, -- .    period
  exp, -- E e  exponent
  oct, -- B b  octal suffix
  oth  -- other
  };

ClassIndex: TYPE = CHARACTER[0C..177C];
ClassArray: TYPE = ARRAY ClassIndex OF Class;

State: TYPE = MACHINE DEPENDENT {
  null, -- end of source, no token found
  name, -- text is a name
  strg, -- text is a string literal, without enclosing parens
  strg2, -- text is a string literal containing \ escapes
  inum, -- text is an integer
  onum, -- text is an octal number, with final "B"
  rnum, -- text is a real number
  abeg, -- text is "{"
  aend, -- text is "}"
  oops, -- text is erroneous, like ")"
  part, -- text is a partial string, up to end of source
  start, -- skipping leading delimiters
  comnt, -- skipping over a comment
  ident, -- scanning an identifier
  msign, -- so far: sgn
  ipart, -- so far: num | msign num | ipart num
  octal, -- so far: ipart B
  point, -- so far: dot | msign dot
  fpart, -- so far: point num | ipart dot | fpart num
  expon, -- so far: ipart E | fpart E
  esign, -- so far: expon + | expon -
  epart, -- so far: esign num | epart num
  qstr, -- inside quoted string
  qstr2, -- inside quoted string with \ escapes
  qstr3, -- inside quoted string immediately after \
  paren, -- inside one level of parentheses
  -- states >paren indicate levels of nested parens
  (LAST[CARDINAL])
  };

FinalState: TYPE = State[null..start);

Action: TYPE = {
  null, -- do nothing (end of source or trailing char)
  skip, -- skip leading character
  take, -- append character to text
  back  -- put character back into source
  };

Text: TYPE = JaMOps.Text;
Object: TYPE = JaMBasic.Object;

-- Globals

overflow: name Object;

-- Procs

RemoveEscapes: PROC [text: Text] RETURNS [Text,BOOLEAN];

MakeOctal: PROC[text: LONG STRING] RETURNS[Object];

MakeInteger: PROC[text: LONG STRING] RETURNS[Object];

MakeReal: PUBLIC PROC[text: LONG STRING] RETURNS[Object];

StringToOctal: PUBLIC PROC[string: string Object] RETURNS[Object];

StringToInteger: PUBLIC PROC[string: string Object] RETURNS[Object];

StringToReal: PUBLIC PROC[string: string Object] RETURNS[Object];

JToken: PUBLIC PROC[frame: JaMInternal.Frame];

}.