1 package java_cup
.runtime
;
4 * Default Implementation for SymbolFactory, creates
7 * @version last updated 27-03-2006
8 * @author Michael Petter
11 /* *************************************************
12 class DefaultSymbolFactory
14 interface for creating new symbols
15 ***************************************************/
16 public class ComplexSymbolFactory
implements SymbolFactory
{
17 public static class Location
{
18 private String unit
="unknown";
19 private int line
, column
;
20 public Location(String unit
, int line
, int column
){
25 public Location(int line
, int column
){
29 public String
toString(){
30 return unit
+":"+line
+"/"+column
;
32 public int getColumn(){
38 public String
getUnit(){
43 * ComplexSymbol with detailed Location Informations and a Name
45 public static class ComplexSymbol
extends Symbol
{
46 protected String name
;
47 protected Location xleft
,xright
;
48 public ComplexSymbol(String name
, int id
) {
52 public ComplexSymbol(String name
, int id
, Object value
) {
56 public String
toString(){
57 if (xleft
==null || xright
==null) return "Symbol: "+name
;
58 return "Symbol: "+name
+" ("+xleft
+" - "+xright
+")";
60 public ComplexSymbol(String name
, int id
, int state
) {
64 public ComplexSymbol(String name
, int id
, Symbol left
, Symbol right
) {
67 if (left
!=null) this.xleft
= ((ComplexSymbol
)left
).xleft
;
68 if (right
!=null) this.xright
= ((ComplexSymbol
)right
).xright
;
70 public ComplexSymbol(String name
, int id
, Location left
, Location right
) {
76 public ComplexSymbol(String name
, int id
, Symbol left
, Symbol right
, Object value
) {
79 if (left
!=null) this.xleft
= ((ComplexSymbol
)left
).xleft
;
80 if (right
!=null) this.xright
= ((ComplexSymbol
)right
).xright
;
82 public ComplexSymbol(String name
, int id
, Location left
, Location right
, Object value
) {
88 public Location
getLeft(){
91 public Location
getRight(){
98 public Symbol
newSymbol(String name
, int id
, Location left
, Location right
, Object value
){
99 return new ComplexSymbol(name
,id
,left
,right
,value
);
101 public Symbol
newSymbol(String name
, int id
, Location left
, Location right
){
102 return new ComplexSymbol(name
,id
,left
,right
);
104 public Symbol
newSymbol(String name
, int id
, Symbol left
, Symbol right
, Object value
){
105 return new ComplexSymbol(name
,id
,left
,right
,value
);
107 public Symbol
newSymbol(String name
, int id
, Symbol left
, Symbol right
){
108 return new ComplexSymbol(name
,id
,left
,right
);
110 public Symbol
newSymbol(String name
, int id
){
111 return new ComplexSymbol(name
,id
);
113 public Symbol
newSymbol(String name
, int id
, Object value
){
114 return new ComplexSymbol(name
,id
,value
);
116 public Symbol
startSymbol(String name
, int id
, int state
){
117 return new ComplexSymbol(name
,id
,state
);