new files from jflex 1.4.3
[fedora-idea.git] / tools / lexer / jflex-1.4 / src / java_cup / runtime / ComplexSymbolFactory.java
blob8f85d7ae2b149647b53ffbb96fc40f7ecbdf943f
1 package java_cup.runtime;
3 /**
4 * Default Implementation for SymbolFactory, creates
5 * plain old Symbols
7 * @version last updated 27-03-2006
8 * @author Michael Petter
9 */
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){
21 this.unit=unit;
22 this.line=line;
23 this.column=column;
25 public Location(int line, int column){
26 this.line=line;
27 this.column=column;
29 public String toString(){
30 return unit+":"+line+"/"+column;
32 public int getColumn(){
33 return column;
35 public int getLine(){
36 return line;
38 public String getUnit(){
39 return unit;
42 /**
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) {
49 super(id);
50 this.name=name;
52 public ComplexSymbol(String name, int id, Object value) {
53 super(id,value);
54 this.name=name;
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) {
61 super(id,state);
62 this.name=name;
64 public ComplexSymbol(String name, int id, Symbol left, Symbol right) {
65 super(id,left,right);
66 this.name=name;
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) {
71 super(id);
72 this.name=name;
73 this.xleft=left;
74 this.xright=right;
76 public ComplexSymbol(String name, int id, Symbol left, Symbol right, Object value) {
77 super(id,value);
78 this.name=name;
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) {
83 super(id,value);
84 this.name=name;
85 this.xleft=left;
86 this.xright=right;
88 public Location getLeft(){
89 return xleft;
91 public Location getRight(){
92 return xright;
97 // Factory methods
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);