1 
2 %pure_parser
3 
4 %{
5 #include "Aaa_intern.h"
6 %}
7 
8 %type	<bval>	    box boxes compositebox
9 %type	<pval>	    bothparams oneparams
10 %type	<gval>	    glue opStretch opShrink
11 %type	<lval>	    orientation
12 %type	<eval>	    signedExpr simpleExpr expr
13 
14 %token		    OC CC OA CA OP CP
15 %token	<qval>	    NAME
16 %token	<ival>	    NUMBER
17 %token	<ival>	    INFINITY
18 %token		    VERTICAL HORIZONTAL
19 
20 %token		    EQUAL DOLLAR
21 
22 %left	<oval>	    PLUS MINUS
23 %left	<oval>	    TIMES DIVIDE PERCENTOF
24 %right	<oval>	    PERCENT
25 %nonassoc	    WIDTH HEIGHT
26 %right	<oval>	    UMINUS UPLUS
27 
28 %%
29 layout		:   compositebox
30 		    { *(((LayoutConverterArg)layoutConverterArg)->to) = (LayoutPtr) $1; }
31 		;
32 box		:   NAME bothparams
33 		    {
34 			BoxPtr	box = New(LBoxRec);
35                         MEMMESSAGE(WidgetBox)
36 			box->nextSibling = 0;
37 			box->type = WidgetBox;
38 			box->params = *$2;
39 			Dispose ($2);
40 			box->u.widget.quark = $1;
41 			$$ = box;
42 		    }
43 		|   signedExpr oneparams
44 		    {
45 			BoxPtr	box = New(LBoxRec);
46                         MEMMESSAGE(GlueBox)
47 			box->nextSibling = 0;
48 			box->type = GlueBox;
49 			box->params = *$2;
50 			Dispose ($2);
51 			box->u.glue.expr = $1;
52 			$$ = box;
53 		    }
54 		|   NAME EQUAL signedExpr
55 		    {
56 			BoxPtr	box = New(LBoxRec);
57                         MEMMESSAGE(VariableBox)
58 			box->nextSibling = 0;
59 			box->type = VariableBox;
60 			box->u.variable.quark = $1;
61 			box->u.variable.expr = $3;
62 			ZeroGlue (box->params.stretch[LayoutHorizontal]); /*###jp###*/
63 			ZeroGlue (box->params.shrink[LayoutHorizontal]);  /*###jp###*/
64 			ZeroGlue (box->params.stretch[LayoutVertical]);   /*###jp###*/
65 			ZeroGlue (box->params.shrink[LayoutVertical]);    /*###jp###*/
66 			$$ = box;
67 		    }
68 		|   compositebox
69 		    {
70 			$$ = $1;
71 		    }
72 		;
73 compositebox	:   orientation OC boxes CC
74 		    {
75 			BoxPtr	box = New(LBoxRec);
76 			BoxPtr	child;
77 
78                         MEMMESSAGE(BoxBox)
79 			box->nextSibling = 0;
80 			box->parent = 0;
81 			box->type = BoxBox;
82 			box->u.box.dir = $1;
83 			box->u.box.firstChild = $3;
84 			ZeroGlue (box->params.stretch[LayoutHorizontal]); /*###jp###*/
85 			ZeroGlue (box->params.shrink[LayoutHorizontal]);  /*###jp###*/
86 			ZeroGlue (box->params.stretch[LayoutVertical]);   /*###jp###*/
87 			ZeroGlue (box->params.shrink[LayoutVertical]);    /*###jp###*/
88 
89 			for (child = $3; child; child = child->nextSibling)
90 			{
91 			    if (child->type == GlueBox)
92 			    {
93 				child->params.stretch[!$1].expr = 0;
94 				child->params.shrink[!$1].expr = 0;
95 				child->params.stretch[!$1].order = 100000;
96 				child->params.shrink[!$1].order = 100000;
97 				child->params.stretch[!$1].value = 1;
98 				child->params.shrink[!$1].value = 1;
99 			    }
100 			    child->parent = box;
101 			}
102 			$$ = box;
103 		    }
104 		;
105 boxes		:   box boxes
106 		    {
107 			$1->nextSibling = $2;
108 			$$ = $1;
109 		    }
110 		|   box
111 		    {	$$ = $1; }
112 		;
113 bothparams	:   OA opStretch opShrink TIMES opStretch opShrink CA
114 		    {
115 			BoxParamsPtr	p = New(BoxParamsRec);
116 
117                         MEMMESSAGE(BoxParamsRec)
118 			p->stretch[LayoutHorizontal] = $2;
119 			p->shrink[LayoutHorizontal] = $3;
120 			p->stretch[LayoutVertical] = $5;
121 			p->shrink[LayoutVertical] = $6;
122 			$$ = p;
123 		    }
124 		|
125 		    {
126 			BoxParamsPtr	p = New(BoxParamsRec);
127 
128                         MEMMESSAGE(BoxParamsRec)
129 			ZeroGlue (p->stretch[LayoutHorizontal]);
130 			ZeroGlue (p->shrink[LayoutHorizontal]);
131 			ZeroGlue (p->stretch[LayoutVertical]);
132 			ZeroGlue (p->shrink[LayoutVertical]);
133 			$$ = p;
134 		    }
135 		;
136 oneparams 	:   OA opStretch opShrink CA
137 		    {
138 			BoxParamsPtr	p = New(BoxParamsRec);
139 
140                         MEMMESSAGE(BoxParamsRec)
141 			p->stretch[LayoutHorizontal] = $2;
142 			p->shrink[LayoutHorizontal] = $3;
143 			p->stretch[LayoutVertical] = $2;
144 			p->shrink[LayoutVertical] = $3;
145 			$$ = p;
146 		    }
147 		|
148 		    {
149 			BoxParamsPtr	p = New(BoxParamsRec);
150 
151                         MEMMESSAGE(BoxParamsRec)
152 			ZeroGlue (p->stretch[LayoutHorizontal]);
153 			ZeroGlue (p->shrink[LayoutHorizontal]);
154 			ZeroGlue (p->stretch[LayoutVertical]);
155 			ZeroGlue (p->shrink[LayoutVertical]);
156 			$$ = p;
157 		    }
158 		;
159 opStretch	:   PLUS glue
160 		    { $$ = $2; }
161 		|
162 		    { ZeroGlue ($$); }
163 		;
164 opShrink	:   MINUS glue
165 		    { $$ = $2; }
166 		|
167 		    { ZeroGlue ($$); }
168 		;
169 glue		:   simpleExpr INFINITY
170 		    { $$.order = $2; $$.expr = $1; }
171 		|   simpleExpr
172 		    { $$.order = 0; $$.expr = $1; }
173 		|   INFINITY
174 		    { $$.order = $1; $$.expr = 0; $$.value = 1; }
175 		;
176 signedExpr	:   MINUS simpleExpr	    %prec UMINUS
177 		    {
178 			$$ = New(ExprRec);
179                         MEMMESSAGE(ExprRec)
180 			$$->type = Unary;
181 			$$->u.unary.op = $1;
182 			$$->u.unary.down = $2;
183 		    }
184 		|   PLUS simpleExpr	    %prec UPLUS
185 		    { $$ = $2; }
186 		|   simpleExpr
187 		;
188 simpleExpr    	:   WIDTH NAME
189 		    {	$$ = New(ExprRec);
190                         MEMMESSAGE(Width)
191 			$$->type = Width;
192 			$$->u.width = $2;
193 		    }
194 		|   HEIGHT NAME
195 		    {	$$ = New(ExprRec);
196                         MEMMESSAGE(Height)
197 			$$->type = Height;
198 			$$->u.height = $2;
199 		    }
200 		|   OP expr CP
201 		    { $$ = $2; }
202 		|   simpleExpr PERCENT
203 		    {
204 			$$ = New(ExprRec);
205 			$$->type = Unary;
206 			$$->u.unary.op = $2;
207 			$$->u.unary.down = $1;
208 		    }
209 		|   NUMBER
210 		    {	$$ = New(ExprRec);
211                         MEMMESSAGE(Constant)
212 			$$->type = Constant;
213 			$$->u.constant = $1;
214 		    }
215 		|   DOLLAR NAME
216 		    {	$$ = New(ExprRec);
217                         MEMMESSAGE(Variable)
218 			$$->type = Variable;
219 			$$->u.variable = $2;
220 		    }
221 		;
222 expr		:   expr PLUS expr
223 		    { binary: ;
224 			$$ = New(ExprRec);
225                         MEMMESSAGE(Binary)
226 			$$->type = Binary;
227 			$$->u.binary.op = $2;
228 			$$->u.binary.left = $1;
229 			$$->u.binary.right = $3;
230 		    }
231 		|   expr MINUS expr
232 		    { goto binary; }
233 		|   expr TIMES expr
234 		    { goto binary; }
235 		|   expr DIVIDE expr
236 		    { goto binary; }
237 		|   expr PERCENTOF expr
238 		    { goto binary; }
239 		|   MINUS expr		    %prec UMINUS
240 		    { unary: ;
241 			$$ = New(ExprRec);
242                         MEMMESSAGE(Unary)
243 			$$->type = Unary;
244 			$$->u.unary.op = $1;
245 			$$->u.unary.down = $2;
246 		    }
247 		|   PLUS expr		    %prec UPLUS
248 		    { $$ = $2; }
249 		|   simpleExpr
250 		;
251 orientation	:   VERTICAL
252 		{   $$ = LayoutVertical; }
253 		|   HORIZONTAL
254 		{   $$ = LayoutHorizontal; }
255 		;
256 %%
257