home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / sos3-2.lha / src / scp / scp.y < prev   
Encoding:
Text File  |  1992-01-23  |  8.1 KB  |  362 lines

  1. /* --------------------------------------------------------------------------
  2.  * Copyright 1992 by Forschungszentrum Informatik (FZI)
  3.  *
  4.  * You can use and distribute this software under the terms of the licence
  5.  * you should have received along with this program.
  6.  * If not or if you want additional information, write to
  7.  * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
  8.  * D-7500 Karlsruhe 1, Germany.
  9.  * --------------------------------------------------------------------------
  10.  */
  11. %token white_space_tok
  12. %token l_brc_tok
  13. %token r_brc_tok
  14. %token double_colon_tok
  15. %token semi_colon_tok
  16. %token l_par_tok
  17. %token r_par_tok
  18. %token l_br_tok
  19. %token r_br_tok
  20. %token operator_string_tok
  21. %token name_tok
  22. %token operator_tok
  23. %token string_tok
  24. %token char_tok
  25. %token number_tok
  26. %token special_tok
  27.  
  28. %type <c> white_space_tok
  29. %type <c> l_brc_tok
  30. %type <c> r_brc_tok
  31. %type <c> double_colon_tok
  32. %type <c> semi_colon_tok
  33. %type <c> l_par_tok
  34. %type <c> r_par_tok
  35. %type <c> l_br_tok
  36. %type <c> r_br_tok
  37. %type <c> operator_string_tok
  38. %type <c> name_tok
  39. %type <c> operator_tok
  40. %type <c> string_tok
  41. %type <c> char_tok
  42. %type <c> number_tok
  43. %type <c> special_tok
  44. %type <c> special
  45.  
  46. %type <s> item
  47. %type <s> item_except_white_space
  48. %type <s> item_except_name_stuff
  49. %type <s> name_stuff
  50. %type <s> name_dc
  51. %type <s> name_lp
  52. %type <s> name_stuff_except_call
  53. %type <s> name_or_op
  54. %type <s> name
  55. %type <s> operator
  56. %type <s> operator_string
  57. %type <s> any_except_dclp
  58. %type <s> any_except_dclpsp
  59. %type <s> white_space
  60. %type <s> white_spaces
  61. %type <s> l_brc
  62. %type <s> r_brc
  63.  
  64. %{
  65.  
  66. #include <malloc.h>
  67. #include <string.h>
  68. #include <stream.h>
  69.  
  70. #include "sys.h"
  71. #include "smg.h"
  72. #include "scp_err.h"
  73. #include "mta_use.h"
  74. #include "cci_use.h"
  75. #include "scp_yacc.h"
  76.  
  77. static sos_Bool   global_var_init         = FALSE; // 09.07.91 (bs)
  78. static int        nesting                 = 0;
  79. static char       *in_method_of_sos_class = 0;
  80. sos_Schema_module scp_mdl;
  81.  
  82. class string_elem
  83. {  char *s;
  84.    string_elem *next;
  85.    friend class strings;
  86.    friend ostream& operator<< (ostream&, strings&);
  87. };
  88.  
  89. class strings
  90. {  string_elem *first, *last;
  91.    friend ostream& operator<< (ostream&, strings&);
  92. public:
  93.    static strings make (char*);
  94.    char*& operator[](int);
  95.    strings& operator+ (strings&);
  96. };
  97.  
  98. strings strings::make (char *s1)
  99. {  strings result;
  100.    result.first=new string_elem;
  101.    result.first->s=s1;
  102.    result.first->next=0;
  103.    result.last=result.first;
  104.    return result;
  105. }
  106.  
  107. char*& strings::operator[](int i)
  108. {  string_elem *e = first;
  109.    for (; i; i--) e=e->next;
  110.    return e->s;
  111. }
  112.  
  113. strings& strings::operator+ (strings &s1)
  114. {  last->next=s1.first;
  115.    last=s1.last;
  116.    return *this;
  117. }
  118.  
  119. static ostream& operator<< (ostream& c, strings &s)
  120. {  string_elem *e, *e1;
  121.    e = s.first;
  122.    for (; e; e=e1)
  123.    {  e1 = e->next;
  124.       c << e->s;
  125.       c.flush();
  126.       delete e->s;
  127.       delete e;
  128.    }
  129.    return c;
  130. }
  131.  
  132. typedef union {strings s; char *c;} YYSTYPE;
  133.  
  134. %}
  135.  
  136. %%
  137.  
  138. items :
  139.       | items
  140.     item
  141.         {  cout << $2; }
  142.       ;
  143.  
  144. item : item_except_white_space
  145.      | white_space_tok
  146.        {  $$=strings::make($1); }
  147.      ;
  148.  
  149. item_except_white_space : name_stuff
  150.             | item_except_name_stuff
  151.             ;
  152.  
  153. item_except_name_stuff : l_brc
  154.                | r_brc
  155.                | double_colon_tok
  156.              {  $$=strings::make($1); }
  157.                | l_par_tok
  158.              {  $$=strings::make($1); }
  159.                | r_par_tok
  160.              {  $$=strings::make($1); }
  161.                | string_tok
  162.              {  $$=strings::make($1); }
  163.                | char_tok
  164.              {  $$=strings::make($1); }
  165.                | number_tok
  166.              {  $$=strings::make($1); }
  167.                | special
  168.              {  $$=strings::make($1); }
  169.                ;
  170.  
  171. name_stuff : name_stuff_except_call
  172.        | name_or_op l_par_tok
  173.          {  $$ = $1 + strings::make($2); }
  174.        ;
  175.  
  176. name_dc : name double_colon_tok white_space
  177.       {  $$ = $1 + strings::make($2) + $3; }
  178.     ;
  179.  
  180. name_lp : name_or_op l_par_tok white_space
  181.       {  $$ = $1 + strings::make($2) + $3; }
  182.     ;
  183.  
  184. name_stuff_except_call :
  185.    name_dc name_lp item_except_white_space
  186.    { 
  187.       sos_String cn = smg_String ($1[0]).make_String (TEMP_CONTAINER);
  188.       sos_Schema_type tp = scp_mdl.lookup_type (cn, TRUE);
  189.       cn.destroy();
  190.       sos_Bool is_static;
  191.       sos_Bool is_protected;
  192.       sos_Bool is_sos_method = (sos_Bool)(tp != NO_OBJECT
  193.                       AND tp.has_type (sos_Class_type_type));
  194.       if (streql ($2[0], "operator"))
  195.      is_static = FALSE;
  196.       else if (is_sos_method)
  197.       {  sos_String mn = smg_String ($2[0]).make_String (TEMP_CONTAINER);
  198.      sos_Method_List ml =
  199.         sos_Class_type::make(tp).get_inherited_methods()[mn];
  200.      mn.destroy();
  201.      if (ml == NO_OBJECT)
  202.      {  is_static    = TRUE;
  203.         is_protected = FALSE;
  204.      }
  205.      else
  206.      {  sos_Method m = ml.get_nth(1);
  207.         is_static    = m.get_is_static();
  208.         is_protected = (sos_Bool)(m.get_kind() EQ sos_PROTECTED);
  209.      }
  210.       }
  211.       strings result;
  212.       if (is_sos_method)
  213.       {  if ((is_static AND nesting != 0 AND NOT is_protected)  // 25.8.91 (dt)
  214.          OR global_var_init)                 // 09.07.91 (bs)
  215.         result = $1 + $2;
  216.      else
  217.      {  if (streql ($2[0], "operator"))
  218.         {  delete $2[0];
  219.            $2[0] = strdup ("");
  220.            sos_String mn = smg_String ($2[1]).make_String (TEMP_CONTAINER);
  221.            sos_String on = cci_Method_impl::operator_string (mn);
  222.            $2[1] = on.make_Cstring();
  223.            on.destroy();
  224.            mn.destroy();
  225.         }
  226.         result = strings::make (strdup ("_")) + $1 + $2;
  227.      }
  228.      if (NOT is_static)
  229.      {  if (nesting == 0)
  230.         {  in_method_of_sos_class = strdup ($1[0]);
  231.            result = result +
  232.             strings::make (strdup ("sos_Typed_id &_tpid"));
  233.         }
  234.         else
  235.            result = result + strings::make (strdup ("_tpid"));
  236.         if (NOT streql ($3[0], ")"))
  237.            result = result + strings::make (strdup (","));
  238.      }
  239.      result = result + $3;
  240.       }
  241.       else
  242.      result = $1 + $2 + $3;
  243.       $$ = result;
  244.    }
  245.    | name_dc name_stuff_except_call
  246.      {  $$ = $1 + $2; }
  247.    | name_dc item_except_name_stuff
  248.      {  $$ = $1 + $2; }
  249.    | name_tok white_space any_except_dclp
  250.      {  if (streql ($1, "self") AND in_method_of_sos_class != 0)
  251.     {  delete $1;
  252.        $$ = strings::make (strdup (in_method_of_sos_class)) +
  253.         strings::make (strdup ("::make(_tpid,this)")) + $2 + $3;
  254.     }
  255.         else
  256.        $$ = strings::make($1) + $2 + $3;
  257.      }
  258.    | operator any_except_dclpsp
  259.      {  $$ = $1 + $2; }
  260.    ;
  261.  
  262. name_or_op : name
  263.        | operator
  264.        ;
  265.  
  266. name : name_tok white_space
  267.        {  $$ = strings::make($1) + $2; }
  268.      ;
  269.  
  270. operator : operator_tok operator_string white_space
  271.        {  $$ = strings::make($1) + $2 + $3; }
  272.      ;
  273.  
  274. operator_string :
  275.        white_space   operator_string_tok
  276.        {  $$ = strings::make ($2) + $1; }
  277.          | white_space l_par_tok white_space r_par_tok
  278.        {  $$ = strings::make (strdup ("()")) + $1 + $3;
  279.           delete $2;
  280.           delete $4;
  281.        }
  282.          | white_space l_br_tok white_space r_br_tok
  283.        {  $$ = strings::make (strdup ("[]")) + $1 + $3;
  284.           delete $2;
  285.           delete $4;
  286.        }
  287.          | white_space special_tok
  288.        {  $$ = strings::make ($2) + $1; }
  289.          | white_space name_tok
  290.        {  $$ = strings::make ($2) + $1; }
  291.      ;
  292.  
  293. any_except_dclp : any_except_dclpsp
  294.         | special
  295.           {  $$=strings::make($1); }
  296.         ;
  297.  
  298. any_except_dclpsp : name_stuff
  299.           | l_brc
  300.           | r_brc
  301.           | r_par_tok
  302.             {  $$=strings::make($1); }
  303.           | string_tok
  304.             {  $$=strings::make($1); }
  305.           | char_tok
  306.             {  $$=strings::make($1); }
  307.           | number_tok
  308.             {  $$=strings::make($1); }
  309.           ;
  310.  
  311. special : operator_string_tok
  312.       {  // 09.07.91 (bs)
  313.              if ((nesting == 0) AND ((*$1) == '='))
  314.          global_var_init = TRUE;
  315.       }
  316.         | r_br_tok
  317.         | l_br_tok
  318.         | special_tok
  319.     | semi_colon_tok
  320.       {  // 09.07.91 (bs)
  321.          global_var_init = FALSE;
  322.        }
  323.     ;
  324.  
  325. white_space : {  $$ = strings::make (strdup ("")); }
  326.         | white_spaces
  327.         ;
  328.  
  329. white_spaces : white_space_tok
  330.            {  $$ = strings::make($1); }
  331.          | white_spaces white_space_tok
  332.            {  $$ = $1 + strings::make($2); }
  333.          ;
  334.  
  335. l_brc : l_brc_tok
  336.     {  nesting++;
  337.        $$=strings::make($1);
  338.     }
  339.       ;
  340.  
  341. r_brc : r_brc_tok
  342.     {  nesting--;
  343.        $$=strings::make($1);
  344.        if (nesting == 0)
  345.        {  delete in_method_of_sos_class;
  346.           in_method_of_sos_class = 0;
  347.        }
  348.     }
  349.       ;
  350.  
  351. %%
  352.  
  353. extern yyparse ();
  354.  
  355. void scp_compile ()
  356. {  yyparse ();
  357. }
  358.  
  359. void yyerror (char *s) {  err_raise (err_USE, s);}
  360.  
  361. #include "scp_lex.h"
  362.