Source code: org/sablecc/sablecc/RecursiveProductionsDetections.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 java.util.*;
11 import org.sablecc.sablecc.analysis.*;
12 import org.sablecc.sablecc.node.*;
13
14 public class RecursiveProductionsDetections extends DepthFirstAdapter
15 {
16 public LinkedList listOfRecursiveProds = new TypedLinkedList(StringCast.instance);
17 private String currentProd;
18
19 public void caseAProd(AProd node)
20 {
21 currentProd = node.getId().getText();
22 if(!node.getId().getText().startsWith("$"))
23 {
24 Object []alts = node.getAlts().toArray();
25
26 for(int i=0; i<alts.length; i++)
27 {
28 ((PAlt)alts[i]).apply(this);
29 }
30 }
31 else
32 {
33 listOfRecursiveProds.add( ResolveIds.name(currentProd) );
34 }
35 }
36
37 public void caseAParsedAlt(AParsedAlt node)
38 {
39 Object temp[] = node.getElems().toArray();
40 for(int i = 0; i < temp.length; i++)
41 {
42 ((PElem) temp[i]).apply(this);
43 }
44 }
45 /*
46 public void caseAIgnoredAlt(AIgnoredAlt node)
47 {
48 Object temp[] = node.getElems().toArray();
49 for(int i = 0; i < temp.length; i++)
50 {
51 ((PElem) temp[i]).apply(this);
52 }
53 }
54 */
55
56 public void caseAElem(AElem node)
57 {
58 if(node.getId().getText().equals(currentProd))
59 {
60 if(node.getSpecifier() != null && node.getSpecifier() instanceof ATokenSpecifier)
61 {
62 return;
63 }
64 if( !listOfRecursiveProds.contains(ResolveIds.name(currentProd)) )
65 {
66 listOfRecursiveProds.add( ResolveIds.name(currentProd) );
67 }
68 }
69 }
70 }