source: trunk/yao/share/antlr-2.7.7/examples/java/pascal/RealConstant.java @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 887 bytes
Line 
1/** The symbol table representation of CONST PI = 3.141592; You would
2 *  create new RealConstant("PI", 3.141592)
3 */
4import java.io.*;
5
6public class RealConstant extends Constant implements Serializable {
7        protected double value;
8
9        public RealConstant(String name, double value) {
10                super(name);
11                setValue(value);
12                setType(PascalParser.symbolTable.getPredefinedType("real"));
13        }
14
15        public RealConstant(String svalue) {
16                this(null,svalue);
17        }
18
19        public RealConstant(String name, String svalue) {
20                super(name);
21                setType(PascalParser.symbolTable.getPredefinedType("real"));
22                double v = 0;
23                try {
24                        v = Double.parseDouble(svalue);
25                }
26                catch (NumberFormatException nfe) {
27                        ;
28                }
29                setValue(v);
30        }
31
32        public double getValue() {
33                return value;
34        }
35
36        public void setValue(double value) {
37                this.value = value;
38        }
39
40        public String toString() {
41                return super.toString()+"="+value;
42        }
43}
Note: See TracBrowser for help on using the repository browser.