Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/sablecc/sablecc/ComputeSimpleTermPosition.java


1   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2    * This file is part of SableCC.                             *
3    * See the file "LICENSE" for copyright information and the  *
4    * terms and conditions for copying, distribution and        *
5    * modification of SableCC.                                  *
6    * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7   
8   package org.sablecc.sablecc;
9   
10  import org.sablecc.sablecc.analysis.*;
11  import org.sablecc.sablecc.node.*;
12  import java.util.*;
13  import java.io.*;
14  
15  public class ComputeSimpleTermPosition extends DepthFirstAdapter
16  {
17    String currentAlt;
18    String currentProd;
19    boolean processingParsedAlt;
20    private ResolveIds ids;
21    private int counter;
22  
23    public final Map positionsMap = new TypedHashMap(
24                                      StringCast.instance,
25                                      StringCast.instance);
26  
27    public final Map elems_position = new TypedHashMap(
28                                        StringCast.instance,
29                                        IntegerCast.instance);
30  
31    public ComputeSimpleTermPosition(ResolveIds ids)
32    {
33      this.ids = ids;
34    }
35  
36    public void inAProd(AProd node)
37    {
38      currentProd = ids.name(node.getId().getText());
39      ids.names.put(node, currentProd);
40    }
41  
42    public void inAParsedAlt(AParsedAlt node)
43    {
44      counter = 0;
45      processingParsedAlt = true;
46  
47      if(node.getAltName() != null)
48      {
49        currentAlt = "A" +
50                     ids.name( node.getAltName().getText() ) +
51                     currentProd;
52      }
53      else
54      {
55        currentAlt = "A" + currentProd;
56      }
57  
58      ids.names.put(node, currentAlt);
59    }
60  
61    public void inAElem(AElem node)
62    {
63      if(processingParsedAlt)
64      {
65        String currentElemName;
66        if(node.getElemName() != null)
67        {
68          currentElemName = currentAlt + "." + node.getElemName().getText();
69        }
70        else
71        {
72          currentElemName = currentAlt + "." + node.getId().getText();
73        }
74  
75        elems_position.put(currentElemName, new Integer(++counter));
76      }
77  
78      if(node.getSpecifier() != null &&
79          node.getSpecifier() instanceof ATokenSpecifier)
80      {
81        return;
82      }
83  
84      String name = ids.name( node.getId().getText() );
85  
86      String elemType = (String)ids.elemTypes.get(node);
87      if(processingParsedAlt && elemType.startsWith("P"))
88      {
89        String elemName;
90        if(node.getElemName() != null)
91        {
92          elemName = node.getElemName().getText();
93        }
94        else
95        {
96          elemName = node.getId().getText();
97        }
98  
99        positionsMap.put(currentAlt+"."+elemName, elemType);
100     }
101   }
102 
103   public void outAParsedAlt(AParsedAlt node)
104   {
105     processingParsedAlt = false;
106   }
107 }