home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_06 / 1n06038b < prev    next >
Text File  |  1990-09-30  |  838b  |  59 lines

  1.  
  2. Listing 3
  3.  
  4. uses
  5.     scan;
  6.  
  7. var
  8.     tc : token_code;
  9.  
  10. function expr(var e : integer) : boolean;
  11.     var
  12.         op : token_code;
  13.     begin
  14.     expr := FALSE;
  15.     if tc <> TC_INT then
  16.         exit;
  17.     e := int_value;
  18.     tc := get_token;
  19.     while tc in [TC_ADD, TC_SUB, TC_MUL, TC_DIV] do
  20.         begin
  21.         op := tc;
  22.         tc := get_token;
  23.         if tc <> TC_INT then
  24.             exit;
  25.         case op of
  26.             TC_ADD:
  27.                 e := e + int_value;
  28.             TC_SUB:
  29.                 e := e - int_value;
  30.             TC_MUL:
  31.                 e := e * int_value;
  32.             TC_DIV:
  33.                 e := e div int_value;
  34.             end;
  35.         tc := get_token;
  36.         end;
  37.     expr := TRUE;
  38.     end;
  39.  
  40. var
  41.     result : integer;
  42.  
  43. begin
  44. start_scan;
  45. tc := get_token;
  46. while tc <> TC_EOF do
  47.     begin
  48.     if expr(result) and (tc = TC_EOL) then
  49.         writeln('= ', result)
  50.     else
  51.         begin
  52.         writeln('*** ERROR ***');
  53.         restart_scan;
  54.         end;
  55.     tc := get_token;
  56.     end;
  57. end.
  58.  
  59.