001: package org.jacorb.idl;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import java.io.PrintWriter;
024:
025: /**
026: * @author Gerald Brose
027: * @version $Id: MultExpr.java,v 1.15 2006/06/19 10:34:57 alphonse.bendt Exp $
028: */
029:
030: public class MultExpr extends IdlSymbol {
031: public String operator;
032: public MultExpr mult_expr = null;
033: public UnaryExpr unary_expr;
034:
035: public MultExpr(int num) {
036: super (num);
037: }
038:
039: public void print(PrintWriter ps) {
040: if (mult_expr != null) {
041: mult_expr.print(ps);
042: ps.print(operator);
043: }
044: unary_expr.print(ps);
045: }
046:
047: public void setDeclaration(ConstDecl declared_in) {
048: unary_expr.setDeclaration(declared_in);
049: }
050:
051: public void setPackage(String s) {
052: s = parser.pack_replace(s);
053: if (pack_name.length() > 0)
054: pack_name = s + "." + pack_name;
055: else
056: pack_name = s;
057: if (mult_expr != null) {
058: mult_expr.setPackage(s);
059: }
060: unary_expr.setPackage(s);
061: }
062:
063: public void parse() {
064: if (mult_expr != null) {
065: mult_expr.parse();
066: }
067: unary_expr.parse();
068: }
069:
070: int pos_int_const() {
071: int y = unary_expr.pos_int_const();
072: if (mult_expr != null) {
073: int z = mult_expr.pos_int_const();
074: if (operator.equals("*"))
075: y *= z;
076: else if (operator.equals("/"))
077: y /= z;
078: else if (operator.equals("%"))
079: y %= z;
080: }
081: return y;
082: }
083:
084: public String value() {
085: String x = "";
086: if (mult_expr != null) {
087: x = mult_expr.value() + operator;
088: }
089: return x + unary_expr.value();
090: }
091:
092: public String toString() {
093: String x = "";
094: if (mult_expr != null) {
095: x = mult_expr.toString() + ' ' + operator + ' ';
096: }
097: return x + unary_expr.toString();
098: }
099:
100: public str_token get_token() {
101: return unary_expr.get_token();
102: }
103: }
|