File: lp.y

package info (click to toggle)
lp-solve 3.0-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 576 kB
  • ctags: 354
  • sloc: ansic: 4,805; yacc: 170; makefile: 136; sh: 59
file content (203 lines) | stat: -rw-r--r-- 3,641 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* ========================================================================= */
/* NAME  : lp.y                                                              */
/* ========================================================================= */


%token VAR CONS SIGN AR_M_OP RE_OP END_C COMMA COLON MINIMISE MAXIMISE


%{
#include "lpkit.h" 
#include "lpglob.h"
#include "read.h"

/* globals */
char Last_var[NAMELEN];
char Constraint_name[NAMELEN];
int Lin_term_count;
REAL f;
int x;
int Sign;
int isign; 	/* internal_sign variable to make sure nothing goes wrong */
		/* with lookahead */
int make_neg;	/* is true after the relational operator is seen in order */
		/* to remember if lin_term stands before or after re_op */
int Within_int_decl = FALSE; /* TRUE when we are within an int declaration */
%}



%start inputfile
%%

inputfile	:
{
  init_read();
  isign = 0;
  make_neg = 0;
  Sign = 0;
} 
		  objective_function
		  constraints
                  int_declarations
		;

constraints	: constraint
		| constraints
		  constraint
		;

constraint      : real_constraint
                | VAR COLON 
{
  add_constraint_name(Last_var, Rows);
}
                  real_constraint
                ;


real_constraint	: x_lineair_sum
		  RE_OP
{
  store_re_op();
  make_neg = 1; 
}
		  x_lineair_sum
                  END_C
{
  if(Lin_term_count == 0) {
    fprintf(stderr, "WARNING line %d: constraint contains no variables\n",
	    yylineno);
    null_tmp_store();
  }

  if(Lin_term_count  > 1)
    Rows++;

  if(Lin_term_count == 1)
    store_bounds();

  Lin_term_count = 0;
  isign = 0 ;
  make_neg = 0;
  Constraint_name[0] = '\0';
}
		;

int_declarations: /* EMPTY */
                | real_int_decls
                ;

real_int_decls  : int_declaration
                | real_int_decls int_declaration
                ;

int_declaration : int_declarator vars END_C
                ;

int_declarator  : VAR {check_decl(Within_int_decl);}
                ;

vars            : VAR {if(!Ignore_decl)add_int_var((char *)yytext);}
                | vars VAR {if(!Ignore_decl)add_int_var((char *)yytext);}
                | vars COMMA VAR {if(!Ignore_decl)add_int_var((char *)yytext);}
                ;

x_lineair_sum	: x_lineair_term 
		| SIGN
{
  isign = Sign; 
}
		  x_lineair_term
		| x_lineair_sum
		  SIGN
{
  isign = Sign; 
}
		  x_lineair_term
		;

x_lineair_term	: lineair_term
		| CONS
{
  if (    (isign || !make_neg)
      && !(isign && !make_neg)) /* but not both! */
    f = -f;
  rhs_store(f);
  isign = 0;
}
		;

lineair_sum	: lineair_term 
		| SIGN
{
  isign = Sign;
}
		  lineair_term
		| lineair_sum
		  SIGN
{
  isign = Sign;
}
		  lineair_term
		;

lineair_term	: VAR
{
  if (    (isign || make_neg)
      && !(isign && make_neg)) /* but not both! */
    var_store(Last_var, Rows, (REAL) -1);
  else
    var_store(Last_var, Rows, (REAL) 1);
  isign = 0;
}
		| CONS 
		  VAR
{
  if (    (isign || make_neg)
      && !(isign && make_neg)) /* but not both! */
    f = -f;
  var_store(Last_var, Rows, f);
  isign = 0;
}
		| CONS 
		  AR_M_OP
		  VAR
{
  if (    (isign || make_neg)
      && !(isign && make_neg)) /* but not both! */
    f = -f;
  var_store(Last_var, Rows, f);
  isign = 0;
}
		;

objective_function:   MAXIMISE real_of
{
  Maximise = TRUE;
}
                    | MINIMISE real_of
{
  Maximise = FALSE;
}
                    | real_of
                ;

real_of:            lineair_sum
		    END_C
{
  Rows++;
  Lin_term_count  =  0;
  isign = 0;
  make_neg = 0;
}
                    | END_C /* allow empty OF */
{
  Rows++;
  Lin_term_count  =  0;
  isign = 0;
  make_neg = 0;
}
		;
%%
#include "lex.c"