Print.borg

Print.borg


`*-----------------------------------*`
`*          >>>Pico v.1.1<<<         *`
`*            Theo D'Hondt           *`
`*  VUB Programming Technology Lab   *`
`*              (c)1999              *`
`*-----------------------------------*`
`*               printer             *`
`*      (METACIRCULAR VERSION)       *`
`*-----------------------------------*`

{ Print(Exp):
    { print_expression(Exp):
        void;

      select_reference(Inv)::
        Inv[REF_NAM_idx];

      select_application(Inv)::
        Inv[APL_NAM_idx];

      select_tabulation(Inv)::
        Inv[TBL_NAM_idx];

      select_error(Inv)::
        Error('abstract grammar violation');

      select_case: case(REF_tag <> select_reference,
                        APL_tag <> select_application,
                        TBL_tag <> select_tabulation,
                           void <> select_error);

      select_name(Inv)::
        { tag: Inv[TAG_idx];
          cas: select_case(tag);
          cas(Inv) };

      print_name(Msg, Nam)::
        display('<', Msg, ' ', Nam[TXT_VAL_idx], '>');

      print_list(Lst, Ini, Sep, Trm)::
        { display(Ini);
          if(size(Lst) > 0,
            { Print(Lst[1]);
              for(k: 2, k <= size(Lst), k:= k+1,
                { display(Sep);
                  print_expression(Lst[k]) }) });
          display(Trm) };

      print_void(Exp)::
        display('');

      print_native(Exp)::
        { nam: Exp[NAT_NAM_idx];
          print_name('native function', nam) };

      print_fraction(Exp)::
        { val: Exp[FRC_VAL_idx];
          display(val) };

      print_text(Exp)::
        { val: Exp[TXT_VAL_idx];
          display(val) };

      print_table(Exp)::
        display('');

      print_function(Exp)::
        { nam: Exp[FUN_NAM_idx];
          print_name('function', nam) };

      print_reference(Exp)::
        { nam: Exp[REF_NAM_idx];
          print_name('reference', nam) };

      print_application(Exp)::
        { nam: Exp[APL_NAM_idx];
          print_name('application', nam) };

      print_tabulation(Exp)::
        { nam: Exp[TBL_NAM_idx];
          print_name('tabulation', nam) };

      print_message(Exp)::
        { nam: Exp[MES_NAM_idx];
          print_name('message', nam) };

      print_definition(Exp)::
        { inv: Exp[DEF_INV_idx];
          nam: select_name(inv);
          print_name('definition', nam) };

      print_declaration(Exp)::
        { inv: Exp[DCL_INV_idx];
          nam: select_name(inv);
          print_name('declaration', nam) };

      print_assignment(Exp)::
        { inv: Exp[SET_INV_idx];
          nam: select_name(inv);
          print_name('assignment', nam) };

      print_dictionary(Exp)::
        display('');

      print_context(Exp)::
        display('');

      print_number(Exp)::
        { val: Exp[NBR_VAL_idx];
          display(val) };

      print_error(Exp)::
        Error("abstract grammar violation");

      exp_case: case(VOI_tag <> print_void,
                     NAT_tag <> print_native,
                     FRC_tag <> print_fraction,
                     TXT_tag <> print_text,
                     TAB_tag <> print_table,
                     FUN_tag <> print_function,
                     REF_tag <> print_reference,
                     APL_tag <> print_application,
                     TBL_tag <> print_tabulation,
                     MES_tag <> print_message,
                     DEF_tag <> print_definition,
                     DCL_tag <> print_declaration,
                     SET_tag <> print_assignment,
                     VAR_tag <> print_dictionary,
                     CST_tag <> print_dictionary,
                     CTX_tag <> print_context,
                     NBR_tag <> print_number,
                        void <> print_error);

      print_expression(Exp):=
        { tag: Exp[TAG_idx];
          cas: exp_case(tag);
          cas(Exp) };

      Print(Exp):=
        print_expression(Exp);

      Print(Exp) };

  display('printer ...... installed', eoln) }