KickJava   Java API By Example, From Geeks To Geeks.

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


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: AddExpr.java,v 1.15 2004/05/06 12:39:58 nicolas Exp $
28  */

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