KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > idl > MultExpr


1 package org.jacorb.idl;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import java.io.PrintWriter JavaDoc;
24
25 /**
26  * @author Gerald Brose
27  * @version $Id: MultExpr.java,v 1.14 2004/05/06 12:39:58 nicolas Exp $
28  */

29
30 class MultExpr
31         extends IdlSymbol
32 {
33
34     public String JavaDoc operator;
35     public MultExpr mult_expr = null;
36     public UnaryExpr unary_expr;
37
38     public MultExpr( int num )
39     {
40         super( num );
41     }
42
43     public void print( PrintWriter JavaDoc ps )
44     {
45         if( mult_expr != null )
46         {
47             mult_expr.print( ps );
48             ps.print( operator );
49         }
50         unary_expr.print( ps );
51     }
52
53
54     public void setDeclaration( ConstDecl declared_in )
55     {
56         unary_expr.setDeclaration( declared_in );
57     }
58
59     public void setPackage( String JavaDoc s )
60     {
61         s = parser.pack_replace( s );
62         if( pack_name.length() > 0 )
63             pack_name = s + "." + pack_name;
64         else
65             pack_name = s;
66         if( mult_expr != null )
67         {
68             mult_expr.setPackage( s );
69         }
70         unary_expr.setPackage( s );
71     }
72
73     public void parse()
74     {
75         if( mult_expr != null )
76         {
77             mult_expr.parse();
78         }
79         unary_expr.parse();
80     }
81
82     int pos_int_const()
83     {
84         int y = unary_expr.pos_int_const();
85         if( mult_expr != null )
86         {
87             int z = mult_expr.pos_int_const();
88             if( operator.equals( "*" ) )
89                 y *= z;
90             else if( operator.equals( "/" ) )
91                 y /= z;
92             else if( operator.equals( "%" ) )
93                 y %= z;
94         }
95         return y;
96     }
97
98     public String JavaDoc value()
99     {
100         String JavaDoc x = "";
101         if( mult_expr != null )
102         {
103             x = mult_expr.value() + operator;
104         }
105         return x + unary_expr.value();
106     }
107
108     public String JavaDoc toString()
109     {
110         String JavaDoc x = "";
111         if( mult_expr != null )
112         {
113             x = mult_expr.toString () + ' ' + operator + ' ';
114         }
115         return x + unary_expr.toString();
116     }
117
118     public str_token get_token()
119     {
120         return unary_expr.get_token();
121     }
122
123 }
124
125
Popular Tags