home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / apps / math / lpsolves / lp.y < prev    next >
Text File  |  1992-08-07  |  3KB  |  167 lines

  1. /* ========================================================================= */
  2. /* NAME  : lp.y                                                              */
  3. /* ========================================================================= */
  4.  
  5.  
  6. %token VAR CONS SIGN AR_M_OP RE_OP END_C COMMA
  7.  
  8.  
  9. %{
  10. #include "defines.h" 
  11. #include "globals.h"
  12.  
  13. /* globals */
  14. char Last_var[NAMELEN];
  15. int Rows;
  16. int Lin_term_count;
  17. double f;
  18. int x;
  19. int Sign;
  20. int isign;     /* internal_sign variable to make sure nothing goes wrong */
  21.         /* with lookahead */
  22. int make_neg;    /* is true after the relational operator is seen in order */
  23.         /* to rember if lin_term stands before or after re_op */
  24. %}
  25.  
  26.  
  27.  
  28. %start inputfile
  29. %%
  30.  
  31. inputfile    :
  32. {
  33.   init_read();
  34.   isign = 0;
  35.   make_neg = 0;
  36.           objective_function
  37.           constraints
  38.                   int_declarations
  39.         ;
  40.  
  41. constraints    : constraint
  42.         | constraints
  43.           constraint
  44.         ;
  45.  
  46. constraint    : x_lineair_sum
  47.           RE_OP
  48. {
  49.   store_re_op();
  50.   make_neg = 1; 
  51. }
  52.           x_lineair_sum
  53.                   END_C
  54. {
  55.   if(Lin_term_count == 0)
  56.     
  57.     {
  58.       fprintf(stderr, "WARNING line %d: constraint contains no variables\n",
  59.           yylineno);
  60.       null_tmp_store();
  61.     }
  62.   if(Lin_term_count  > 1)
  63.     Rows++;
  64.   if(Lin_term_count == 1)
  65.     store_bounds();
  66.   Lin_term_count = 0;
  67.   isign = 0 ; make_neg = 0;
  68. }
  69.         ;
  70.  
  71. int_declarations: /* EMPTY */
  72.                 | real_int_decls
  73.                 ;
  74.  
  75. real_int_decls  : int_declaration
  76.                 | real_int_decls int_declaration
  77.                 ;
  78.  
  79. int_declaration : int_declarator vars END_C
  80.                 ;
  81.  
  82. int_declarator  : VAR {/* check_decl(yytext);*/}/* check it here !! */
  83.                 ;
  84.  
  85. vars            : VAR {add_int_var(yytext);}
  86.                 | vars VAR {add_int_var(yytext);}
  87.                 | vars COMMA VAR {add_int_var(yytext);}
  88.                 ;
  89.  
  90. x_lineair_sum    : x_lineair_term 
  91.         | SIGN
  92. {
  93.   isign = Sign; 
  94. }
  95.           x_lineair_term
  96.         | x_lineair_sum
  97.           SIGN
  98. {
  99.   isign = Sign; 
  100. }
  101.           x_lineair_term
  102.         ;
  103.  
  104. x_lineair_term    : lineair_term
  105.         | CONS
  106. {
  107.   if (isign ^ (!make_neg))
  108.     f = -f;
  109.   rhs_store(f);
  110.   isign = 0;
  111. }
  112.         ;
  113.  
  114. lineair_sum    : lineair_term 
  115.         | SIGN
  116. {
  117.   isign = Sign;
  118. }
  119.           lineair_term
  120.         | lineair_sum
  121.           SIGN
  122. {
  123.   isign = Sign;
  124. }
  125.           lineair_term
  126.         ;
  127.  
  128. lineair_term    : VAR
  129. {
  130.   if (isign ^ make_neg)
  131.     var_store(Last_var, Rows, (double)-1);
  132.   else
  133.     var_store(Last_var, Rows, (double)1);
  134.   isign = 0;
  135. }
  136.         | CONS 
  137.           VAR
  138. {
  139.   if (isign ^ make_neg)
  140.     f = -f;
  141.   var_store(Last_var, Rows, f);
  142.   isign = 0;
  143. }
  144.         | CONS 
  145.           AR_M_OP
  146.           VAR
  147. {
  148.   if (isign ^ make_neg)
  149.     f = -f;
  150.   var_store(Last_var, Rows, f);
  151.   isign = 0;
  152. }
  153.         ;
  154.  
  155. objective_function: lineair_sum
  156.             END_C
  157. {
  158.   Rows++;
  159.   Lin_term_count  =  0;
  160.   isign = 0;
  161.   make_neg = 0;
  162. }
  163.         ;
  164. %%
  165. # include "lexyyx.c"
  166.