Home  /  Resources & support  /  Users Group meetings  /  1999 UK Stata Users Group meeting  /  Low-level parsing, revisited

Low-level parsing, revisited

  • gettoken allows token-by-token low-level parsing
  • Useful for two-word commands

    • Pull a subcommand off of the original command line
    • Put the rest of the original command line back in `0' for high-level parsing
              . mycmd6 sum mpg weight if foreign
      
              program define mycmd6              /* `0'      : sum mpg weight if foreign */
                  version 6.0
                  gettoken subcmd 0 : 0          /* `subcmd' : sum                       */
                                                 /* `0'      : mpg weight if foreign     */
                  syntax [varlist] [if] [in]     
                  if "`subcmd'" == "sum" {
                      ...
                  }
                  ...
              end
      
      This is similar to the following in Perl:
              ($subcmd,$zero) = split(/ /,$zero,2) ;