  def tok(s)
    case s[0]
    when ?{ then ['{', s[0,1], s[0,1]]
    when ?} then ['}', s[0,1], s[0,1]]
    when ?: then [':', s[0,1], s[0,1]]
    when ?, then [',', s[0,1], s[0,1]]
    when ?[ then ['[', s[0,1], s[0,1]]
    when ?] then [']', s[0,1], s[0,1]]
    when ?n then nulltok(s)
    when ?t then truetok(s)
    when ?f then falsetok(s)
    when ?" then strtok(s)
    when Spc, ?\t, ?\n, ?\r then [:space, s[0,1], s[0,1]]
    else
      numtok(s)
    end
  end


  def nulltok(s);  s[0,4] == 'null'  ? [:val, 'null',  nil]   : [] end
  def truetok(s);  s[0,4] == 'true'  ? [:val, 'true',  true]  : [] end
  def falsetok(s); s[0,5] == 'false' ? [:val, 'false', false] : [] end


  def numtok(s)
    m = /-?([1-9][0-9]+|[0-9])([.][0-9]+)?([eE][+-]?[0-9]+)?/.match(s)
    if m && m.begin(0) == 0
      if !m[2] && !m[3]
        [:val, m[0], Integer(m[0])]
      elsif m[2]
        [:val, m[0], Float(m[0])]
      else
        # We don't convert scientific notation
        [:val, m[0], m[0]]
      end
    else
      []
    end
  end


  def strtok(s)
    m = /"([^"\\]|\\["\/\\bfnrt]|\\u[0-9a-fA-F]{4})*"/.match(s)
    if ! m
      raise Error, "invalid string literal at #{abbrev(s)}"
    end
    [:str, m[0], unquote(m[0])]
  end
Weaknesses in this category are related to improper management of system resources.