options {
  STATIC = false;
  JAVA_UNICODE_ESCAPE = true;
}

PARSER_BEGIN(Parser)
import java.util.*;
import java.io.*;
import edu.neu.ccs.demeter.aplib.*;
import edu.neu.ccs.demeter.aplib.cd.*;
import edu.neu.ccs.demeter.*;
public class Parser { 
  // oit is uugly.  Why isn't there a Character.valueOf(String)? 
  static char unescapifyChar(String s) { 
    char c = s.charAt(0); 
    if (c == '\\') { 
      switch (s.charAt(1)) { 
      case 'n': c = '\n'; break; 
      case 't': c = '\t'; break; 
      case 'b': c = '\b'; break; 
      case 'r': c = '\r'; break; 
      case 'f': c = '\f'; break; 
      case '\\': c = '\\'; break; 
      case '\'': c = '\''; break; 
      case '\"': c = '\"'; break; 
      default: 
       c = (char) Integer.parseInt(s.substring(1, s.length()), 8); 
       break; 
      } 
    } 
    return c; 
  } 
  // Even uglier... 
  static String unescapify(String s) { 
    char str[] = new char[s.length()]; 
    int i = 0, o = 0; 
    while (i < s.length()) { 
      char c = s.charAt(i++); 
      if (c == '\\') { 
       int j = i + 1; 
       while (j < s.length() && 
              Character.digit(s.charAt(j), 8) != -1) { 
         j++; 
       } 
       c = unescapifyChar(s.substring(i-1, j)); 
       i = j; 
      } 
      str[o++] = c; 
    } 
    return String.valueOf(str, 0, o); 
  } 
} 

PARSER_END(Parser)

Main _Main() : {
  Main it = null;
} {
  { it=new Main(); }
  { return it; }
}

StrategyExpression _StrategyExpression() : {
  StrategyExpression it = null;
  Strategy _strategy;
} {
  { it=new StrategyExpression(); }
  _strategy=_Strategy() { it.set_strategy(_strategy); }
  { return it; }
}

Strategy _Strategy() : {
  Strategy it = null;
} {
  ( it=_SimpleStrategy() | it=_StrategyCombination() | it=_StrategyReference() )
  { return it; }
}

void common_Strategy(Strategy it) : {
} {
  { }
}

SimpleStrategy _SimpleStrategy() : {
  SimpleStrategy it = null;
} {
  ( it=_StrategyGraph() | it=_PathDirective() )
  { return it; }
}

void common_SimpleStrategy(SimpleStrategy it) : {
  NameMap _parsedNameMap;
} {
  [  "with"  _parsedNameMap=_NameMap() { it.set_parsedNameMap(_parsedNameMap); }  ]
  common_Strategy(it)
  { }
}

StrategyGraph _StrategyGraph() : {
  StrategyGraph it = null;
  SGEdge_SList _edges;
} {
  { it=new StrategyGraph(); }
  "{"  _edges=_SGEdge_SList() { it.set_edges(_edges); }
  "}"  common_SimpleStrategy(it)
  { return it; }
}

SGEdge _SGEdge() : {
  SGEdge it = null;
  SourceMarker _sourcemarker;
  GlobSpec _source;
  TargetMarker _targetmarker;
  GlobSpec _target;
  NegativeConstraint _constraint;
} {
  { it=new SGEdge(); }
  [  _sourcemarker=_SourceMarker() { it.set_sourcemarker(_sourcemarker); }  ]
  _source=_GlobSpec() { it.set_source(_source); }
  "->"  [  _targetmarker=_TargetMarker() { it.set_targetmarker(_targetmarker); }  ]
  _target=_GlobSpec() { it.set_target(_target); }
  [  _constraint=_NegativeConstraint() { it.set_constraint(_constraint); }  ]
  { return it; }
}

SourceMarker _SourceMarker() : {
  SourceMarker it = null;
} {
  { it=new SourceMarker(); }
  "source:"  { return it; }
}

TargetMarker _TargetMarker() : {
  TargetMarker it = null;
} {
  { it=new TargetMarker(); }
  "target:"  { return it; }
}

PathDirective _PathDirective() : {
  PathDirective it = null;
  SourceDirective _source;
  NegativeConstraint _constraint;
  PathSegment_List _segments;
  TargetDirective _target;
} {
  { it=new PathDirective(); }
  _source=_SourceDirective() { it.set_source(_source); }
  [  _constraint=_NegativeConstraint() { it.set_constraint(_constraint); }  ]
  _segments=_PathSegment_List() { it.set_segments(_segments); }
  _target=_TargetDirective() { it.set_target(_target); }
  common_SimpleStrategy(it)
  { return it; }
}

SourceDirective _SourceDirective() : {
  SourceDirective it = null;
} {
  ( it=_From() )
  { return it; }
}

void common_SourceDirective(SourceDirective it) : {
  ClassGlobSpec _sources;
} {
  _sources=_ClassGlobSpec() { it.set_sources(_sources); }
  { }
}

From _From() : {
  From it = null;
} {
  { it=new From(); }
  "from"  common_SourceDirective(it)
  { return it; }
}

PathSegment _PathSegment() : {
  PathSegment it = null;
  PositiveConstraint _node;
  NegativeConstraint _constraint;
} {
  { it=new PathSegment(); }
  _node=_PositiveConstraint() { it.set_node(_node); }
  [  _constraint=_NegativeConstraint() { it.set_constraint(_constraint); }  ]
  { return it; }
}

Constraint _Constraint() : {
  Constraint it = null;
} {
  ( it=_PositiveConstraint() | it=_NegativeConstraint() )
  { return it; }
}

void common_Constraint(Constraint it) : {
  GlobSpec _glob;
} {
  _glob=_GlobSpec() { it.set_glob(_glob); }
  { }
}

PositiveConstraint _PositiveConstraint() : {
  PositiveConstraint it = null;
} {
  ( it=_Through() | it=_Via() )
  { return it; }
}

void common_PositiveConstraint(PositiveConstraint it) : {
} {
  common_Constraint(it)
  { }
}

Through _Through() : {
  Through it = null;
} {
  { it=new Through(); }
  "through"  common_PositiveConstraint(it)
  { return it; }
}

Via _Via() : {
  Via it = null;
} {
  { it=new Via(); }
  "via"  common_PositiveConstraint(it)
  { return it; }
}

NegativeConstraint _NegativeConstraint() : {
  NegativeConstraint it = null;
} {
  ( it=_Bypassing() | it=_OnlyThrough() )
  { return it; }
}

void common_NegativeConstraint(NegativeConstraint it) : {
} {
  common_Constraint(it)
  { }
}

Bypassing _Bypassing() : {
  Bypassing it = null;
} {
  { it=new Bypassing(); }
  "bypassing"  common_NegativeConstraint(it)
  { return it; }
}

OnlyThrough _OnlyThrough() : {
  OnlyThrough it = null;
} {
  { it=new OnlyThrough(); }
  "only-through"  common_NegativeConstraint(it)
  { return it; }
}

TargetDirective _TargetDirective() : {
  TargetDirective it = null;
} {
  ( it=_To() | it=_ToStop() )
  { return it; }
}

void common_TargetDirective(TargetDirective it) : {
  ClassGlobSpec _targets;
} {
  _targets=_ClassGlobSpec() { it.set_targets(_targets); }
  { }
}

To _To() : {
  To it = null;
} {
  { it=new To(); }
  "to"  common_TargetDirective(it)
  { return it; }
}

ToStop _ToStop() : {
  ToStop it = null;
} {
  { it=new ToStop(); }
  "to-stop"  common_TargetDirective(it)
  { return it; }
}

StrategyCombination _StrategyCombination() : {
  StrategyCombination it = null;
} {
  ( it=_Join() | it=_Merge() | it=_Intersect() )
  { return it; }
}

void common_StrategyCombination(StrategyCombination it) : {
  Strategy _first;
  Strategy_Commalist _rest;
} {
  "("  _first=_Strategy() { it.set_first(_first); }
  ","  _rest=_Strategy_Commalist() { it.set_rest(_rest); }
  ")"  common_Strategy(it)
  { }
}

Join _Join() : {
  Join it = null;
} {
  { it=new Join(); }
  "join"  common_StrategyCombination(it)
  { return it; }
}

Merge _Merge() : {
  Merge it = null;
} {
  { it=new Merge(); }
  "merge"  common_StrategyCombination(it)
  { return it; }
}

Intersect _Intersect() : {
  Intersect it = null;
} {
  { it=new Intersect(); }
  "intersect"  common_StrategyCombination(it)
  { return it; }
}

StrategyReference _StrategyReference() : {
  StrategyReference it = null;
  Ident _ident;
} {
  { it=new StrategyReference(); }
  _ident=_Ident() { it.set_ident(_ident); }
  common_Strategy(it)
  { return it; }
}

SymbolicNameMap _SymbolicNameMap() : {
  SymbolicNameMap it = null;
} {
  ( it=_NameMap() )
  { return it; }
}

void common_SymbolicNameMap(SymbolicNameMap it) : {
} {
  { }
}

NameMap _NameMap() : {
  NameMap it = null;
  NameBinding_Commalist _bindings;
} {
  { it=new NameMap(); }
  "{"  [  _bindings=_NameBinding_Commalist() { it.set_bindings(_bindings); }  ]
  "}"  common_SymbolicNameMap(it)
  { return it; }
}

NameBinding _NameBinding() : {
  NameBinding it = null;
  Name _sgName;
  ClassGlobSpec _cgNames;
} {
  { it=new NameBinding(); }
  _sgName=_Name() { it.set_sgName(_sgName); }
  "="  _cgNames=_ClassGlobSpec() { it.set_cgNames(_cgNames); }
  { return it; }
}

GlobSpec _GlobSpec() : {
  GlobSpec it = null;
} {
  ( it=_OneGlob() | it=_GlobSet() )
  { return it; }
}

void common_GlobSpec(GlobSpec it) : {
} {
  { }
}

OneGlob _OneGlob() : {
  OneGlob it = null;
  Glob _glob;
} {
  { it=new OneGlob(); }
  _glob=_Glob() { it.set_glob(_glob); }
  common_GlobSpec(it)
  { return it; }
}

GlobSet _GlobSet() : {
  GlobSet it = null;
  Glob_Commalist _globs;
} {
  { it=new GlobSet(); }
  "{"  [  _globs=_Glob_Commalist() { it.set_globs(_globs); }  ]
  "}"  common_GlobSpec(it)
  { return it; }
}

Glob _Glob() : {
  Glob it = null;
} {
  ( it=_ClassGlob() | it=_EdgeGlob() )
  { return it; }
}

void common_Glob(Glob it) : {
} {
  { }
}

EdgeGlob _EdgeGlob() : {
  EdgeGlob it = null;
} {
  ( it=_PartGlob() | it=_SubclassGlob() | it=_SuperclassGlob() )
  { return it; }
}

void common_EdgeGlob(EdgeGlob it) : {
} {
  common_Glob(it)
  { }
}

ClassGlob _ClassGlob() : {
  ClassGlob it = null;
  ClassNameGlob _name;
} {
  { it=new ClassGlob(); }
  _name=_ClassNameGlob() { it.set_name(_name); }
  common_Glob(it)
  { return it; }
}

PartGlob _PartGlob() : {
  PartGlob it = null;
  SourceGlob _source;
  PartNameGlob _name;
  TargetGlob _target;
} {
  { it=new PartGlob(); }
  "->"  _source=_SourceGlob() { it.set_source(_source); }
  ","  _name=_PartNameGlob() { it.set_name(_name); }
  ","  _target=_TargetGlob() { it.set_target(_target); }
  common_EdgeGlob(it)
  { return it; }
}

SubclassGlob _SubclassGlob() : {
  SubclassGlob it = null;
  SourceGlob _source;
  TargetGlob _target;
} {
  { it=new SubclassGlob(); }
  "=>"  _source=_SourceGlob() { it.set_source(_source); }
  ","  _target=_TargetGlob() { it.set_target(_target); }
  common_EdgeGlob(it)
  { return it; }
}

SuperclassGlob _SuperclassGlob() : {
  SuperclassGlob it = null;
  SourceGlob _source;
  TargetGlob _target;
} {
  { it=new SuperclassGlob(); }
  ":>"  _source=_SourceGlob() { it.set_source(_source); }
  ","  _target=_TargetGlob() { it.set_target(_target); }
  common_EdgeGlob(it)
  { return it; }
}

SourceGlob _SourceGlob() : {
  SourceGlob it = null;
  ClassNameGlob _name;
} {
  { it=new SourceGlob(); }
  _name=_ClassNameGlob() { it.set_name(_name); }
  { return it; }
}

TargetGlob _TargetGlob() : {
  TargetGlob it = null;
  ClassNameGlob _name;
} {
  { it=new TargetGlob(); }
  _name=_ClassNameGlob() { it.set_name(_name); }
  { return it; }
}

ClassNameGlob _ClassNameGlob() : {
  ClassNameGlob it = null;
} {
  ( it=_ClassNameExact() | it=_AnyClass() )
  { return it; }
}

void common_ClassNameGlob(ClassNameGlob it) : {
} {
  { }
}

ClassNameExact _ClassNameExact() : {
  ClassNameExact it = null;
  ClassName _classname;
} {
  { it=new ClassNameExact(); }
  _classname=_ClassName() { it.set_classname(_classname); }
  common_ClassNameGlob(it)
  { return it; }
}

AnyClass _AnyClass() : {
  AnyClass it = null;
} {
  { it=new AnyClass(); }
  "*"  common_ClassNameGlob(it)
  { return it; }
}

PartNameGlob _PartNameGlob() : {
  PartNameGlob it = null;
} {
  ( it=_PartNameExact() | it=_AnyPart() )
  { return it; }
}

void common_PartNameGlob(PartNameGlob it) : {
} {
  { }
}

PartNameExact _PartNameExact() : {
  PartNameExact it = null;
  PartName _partname;
} {
  { it=new PartNameExact(); }
  _partname=_PartName() { it.set_partname(_partname); }
  common_PartNameGlob(it)
  { return it; }
}

AnyPart _AnyPart() : {
  AnyPart it = null;
} {
  { it=new AnyPart(); }
  "*"  common_PartNameGlob(it)
  { return it; }
}

ClassGlobSpec _ClassGlobSpec() : {
  ClassGlobSpec it = null;
} {
  ( it=_OneClassGlob() | it=_ClassGlobSet() )
  { return it; }
}

void common_ClassGlobSpec(ClassGlobSpec it) : {
} {
  { }
}

OneClassGlob _OneClassGlob() : {
  OneClassGlob it = null;
  ClassGlob _classglob;
} {
  { it=new OneClassGlob(); }
  _classglob=_ClassGlob() { it.set_classglob(_classglob); }
  common_ClassGlobSpec(it)
  { return it; }
}

ClassGlobSet _ClassGlobSet() : {
  ClassGlobSet it = null;
  ClassGlob_Commalist _globs;
} {
  { it=new ClassGlobSet(); }
  "{"  _globs=_ClassGlob_Commalist() { it.set_globs(_globs); }
  "}"  common_ClassGlobSpec(it)
  { return it; }
}

ClassName _ClassName() : {
  ClassName it = null;
  Name _name;
} {
  { it=new ClassName(); }
  _name=_Name() { it.set_name(_name); }
  { return it; }
}

PartName _PartName() : {
  PartName it = null;
  Ident _name;
} {
  { it=new PartName(); }
  _name=_Ident() { it.set_name(_name); }
  { return it; }
}

Name _Name() : {
  Name it = null;
  Nonempty_Name _first;
} {
  { it=new Name(); }
  _first=_Nonempty_Name() { it.set_first(_first); }
  { return it; }
}

XAspect _XAspect() : {
  XAspect it = null;
  XAspectCD _cd;
  XAspectTraversals _trav;
} {
  { it=new XAspect(); }
  _cd=_XAspectCD() { it.set_cd(_cd); }
  _trav=_XAspectTraversals() { it.set_trav(_trav); }
  { return it; }
}

XAspectCD _XAspectCD() : {
  XAspectCD it = null;
  Ident _cdName;
  Text _cdText;
} {
  { it=new XAspectCD(); }
  "aspect"  "("  "ClassDictionary"  ")"  _cdName=_Ident() { it.set_cdName(_cdName); }
  _cdText=_Text() { it.set_cdText(_cdText); }
  { return it; }
}

XAspectTraversals _XAspectTraversals() : {
  XAspectTraversals it = null;
  Ident _travName;
  AspectStrategy_List _strategies;
  AspectNodeSet_List _nodes;
} {
  { it=new XAspectTraversals(); }
  "aspect"  "("  "Traversal"  ")"  _travName=_Ident() { it.set_travName(_travName); }
  "{"  _strategies=_AspectStrategy_List() { it.set_strategies(_strategies); }
  _nodes=_AspectNodeSet_List() { it.set_nodes(_nodes); }
  "}"  { return it; }
}

AspectStrategy _AspectStrategy() : {
  AspectStrategy it = null;
  Ident _strategyName;
  Strategy _strategy;
} {
  { it=new AspectStrategy(); }
  "declare strategy: "  _strategyName=_Ident() { it.set_strategyName(_strategyName); }
  ":"  _strategy=_Strategy() { it.set_strategy(_strategy); }
  ";"  { return it; }
}

AspectNodeSet _AspectNodeSet() : {
  AspectNodeSet it = null;
  Ident _nodesetName;
  Node _node;
} {
  { it=new AspectNodeSet(); }
  "declare node set: "  _nodesetName=_Ident() { it.set_nodesetName(_nodesetName); }
  ":"  _node=_Node() { it.set_node(_node); }
  { return it; }
}

Node _Node() : {
  Node it = null;
} {
  ( it=_Nodes() | it=_NodeRegExp() | it=_NodeExp() | it=_NodeList() )
  { return it; }
}

void common_Node(Node it) : {
} {
  { }
}

Nodes _Nodes() : {
  Nodes it = null;
  Ident _strategyName;
} {
  { it=new Nodes(); }
  "nodes "  _strategyName=_Ident() { it.set_strategyName(_strategyName); }
  ";"  common_Node(it)
  { return it; }
}

NodeList _NodeList() : {
  NodeList it = null;
  NodeClassName_Commalist _nodeclassname_commalist;
} {
  { it=new NodeList(); }
  _nodeclassname_commalist=_NodeClassName_Commalist() { it.set_nodeclassname_commalist(_nodeclassname_commalist); }
  ";"  common_Node(it)
  { return it; }
}

NodeClassName _NodeClassName() : {
  NodeClassName it = null;
  Ident _ident;
} {
  { it=new NodeClassName(); }
  _ident=_Ident() { it.set_ident(_ident); }
  { return it; }
}

NodeRegExp _NodeRegExp() : {
  NodeRegExp it = null;
  Ident _regExp;
} {
  { it=new NodeRegExp(); }
  "regexp"  _regExp=_Ident() { it.set_regExp(_regExp); }
  "*"  ";"  common_Node(it)
  { return it; }
}

NodeExp _NodeExp() : {
  NodeExp it = null;
} {
  ( it=_NodeExpOr() | it=_NodeExpAnd() | it=_NodeExpNot() )
  { return it; }
}

void common_NodeExp(NodeExp it) : {
} {
  common_Node(it)
  { }
}

NodeExpL2 _NodeExpL2() : {
  NodeExpL2 it = null;
} {
  ( it=_NodeExpOrL2() | it=_NodeExpAndL2() | it=_NodeExpNotL2() | it=_NodeExpIdentL2() )
  { return it; }
}

void common_NodeExpL2(NodeExpL2 it) : {
} {
  { }
}

NodeExpOr _NodeExpOr() : {
  NodeExpOr it = null;
  NodeExpL2 _p1;
  NodeExpL2 _p2;
} {
  { it=new NodeExpOr(); }
  "or"  "("  _p1=_NodeExpL2() { it.set_p1(_p1); }
  ","  _p2=_NodeExpL2() { it.set_p2(_p2); }
  ")"  ";"  common_NodeExp(it)
  { return it; }
}

NodeExpAnd _NodeExpAnd() : {
  NodeExpAnd it = null;
  NodeExpL2 _p1;
  NodeExpL2 _p2;
} {
  { it=new NodeExpAnd(); }
  "and"  "("  _p1=_NodeExpL2() { it.set_p1(_p1); }
  ","  _p2=_NodeExpL2() { it.set_p2(_p2); }
  ")"  ";"  common_NodeExp(it)
  { return it; }
}

NodeExpNot _NodeExpNot() : {
  NodeExpNot it = null;
  NodeExpL2 _p1;
} {
  { it=new NodeExpNot(); }
  "!"  _p1=_NodeExpL2() { it.set_p1(_p1); }
  ";"  common_NodeExp(it)
  { return it; }
}

NodeExpOrL2 _NodeExpOrL2() : {
  NodeExpOrL2 it = null;
  NodeExpL2 _p1;
  NodeExpL2 _p2;
} {
  { it=new NodeExpOrL2(); }
  "or"  "("  _p1=_NodeExpL2() { it.set_p1(_p1); }
  ","  _p2=_NodeExpL2() { it.set_p2(_p2); }
  ")"  common_NodeExpL2(it)
  { return it; }
}

NodeExpAndL2 _NodeExpAndL2() : {
  NodeExpAndL2 it = null;
  NodeExpL2 _p1;
  NodeExpL2 _p2;
} {
  { it=new NodeExpAndL2(); }
  "and"  "("  _p1=_NodeExpL2() { it.set_p1(_p1); }
  ","  _p2=_NodeExpL2() { it.set_p2(_p2); }
  ")"  common_NodeExpL2(it)
  { return it; }
}

NodeExpNotL2 _NodeExpNotL2() : {
  NodeExpNotL2 it = null;
  NodeExpL2 _p1;
} {
  { it=new NodeExpNotL2(); }
  "!"  _p1=_NodeExpL2() { it.set_p1(_p1); }
  common_NodeExpL2(it)
  { return it; }
}

NodeExpIdentL2 _NodeExpIdentL2() : {
  NodeExpIdentL2 it = null;
  Ident _nodeSetName;
} {
  { it=new NodeExpIdentL2(); }
  _nodeSetName=_Ident() { it.set_nodeSetName(_nodeSetName); }
  common_NodeExpL2(it)
  { return it; }
}

SGEdge_SList _SGEdge_SList() : {
  SGEdge_SList it = null;
  Nonempty_SGEdge_SList _first;
} {
  { it=new SGEdge_SList(); }
  _first=_Nonempty_SGEdge_SList() { it.set_first(_first); }
  { return it; }
}

PathSegment_List _PathSegment_List() : {
  PathSegment_List it = null;
  Nonempty_PathSegment_List _first;
} {
  { it=new PathSegment_List(); }
  [  _first=_Nonempty_PathSegment_List() { it.set_first(_first); }  ]
  { return it; }
}

Strategy_Commalist _Strategy_Commalist() : {
  Strategy_Commalist it = null;
  Nonempty_Strategy_Commalist _first;
} {
  { it=new Strategy_Commalist(); }
  _first=_Nonempty_Strategy_Commalist() { it.set_first(_first); }
  { return it; }
}

NameBinding_Commalist _NameBinding_Commalist() : {
  NameBinding_Commalist it = null;
  Nonempty_NameBinding_Commalist _first;
} {
  { it=new NameBinding_Commalist(); }
  _first=_Nonempty_NameBinding_Commalist() { it.set_first(_first); }
  { return it; }
}

Glob_Commalist _Glob_Commalist() : {
  Glob_Commalist it = null;
  Nonempty_Glob_Commalist _first;
} {
  { it=new Glob_Commalist(); }
  _first=_Nonempty_Glob_Commalist() { it.set_first(_first); }
  { return it; }
}

ClassGlob_Commalist _ClassGlob_Commalist() : {
  ClassGlob_Commalist it = null;
  Nonempty_ClassGlob_Commalist _first;
} {
  { it=new ClassGlob_Commalist(); }
  _first=_Nonempty_ClassGlob_Commalist() { it.set_first(_first); }
  { return it; }
}

AspectStrategy_List _AspectStrategy_List() : {
  AspectStrategy_List it = null;
  Nonempty_AspectStrategy_List _first;
} {
  { it=new AspectStrategy_List(); }
  [  _first=_Nonempty_AspectStrategy_List() { it.set_first(_first); }  ]
  { return it; }
}

AspectNodeSet_List _AspectNodeSet_List() : {
  AspectNodeSet_List it = null;
  Nonempty_AspectNodeSet_List _first;
} {
  { it=new AspectNodeSet_List(); }
  [  _first=_Nonempty_AspectNodeSet_List() { it.set_first(_first); }  ]
  { return it; }
}

NodeClassName_Commalist _NodeClassName_Commalist() : {
  NodeClassName_Commalist it = null;
  Nonempty_NodeClassName_Commalist _first;
} {
  { it=new NodeClassName_Commalist(); }
  _first=_Nonempty_NodeClassName_Commalist() { it.set_first(_first); }
  { return it; }
}

Nonempty_Name _Nonempty_Name() : {
  Nonempty_Name it = null;
  Ident _it;
  Nonempty_Name _next;
} {
  { it=new Nonempty_Name(); }
  _it=_Ident() { it.set_it(_it); }
  [  "."  _next=_Nonempty_Name() { it.set_next(_next); }  ]
  { return it; }
}

Nonempty_SGEdge_SList _Nonempty_SGEdge_SList() : {
  Nonempty_SGEdge_SList it = null;
  SGEdge _it;
  Nonempty_SGEdge_SList _next;
} {
  { it=new Nonempty_SGEdge_SList(); }
  _it=_SGEdge() { it.set_it(_it); }
  [  _next=_Nonempty_SGEdge_SList() { it.set_next(_next); }  ]
  { return it; }
}

Nonempty_PathSegment_List _Nonempty_PathSegment_List() : {
  Nonempty_PathSegment_List it = null;
  PathSegment _it;
  Nonempty_PathSegment_List _next;
} {
  { it=new Nonempty_PathSegment_List(); }
  _it=_PathSegment() { it.set_it(_it); }
  [  _next=_Nonempty_PathSegment_List() { it.set_next(_next); }  ]
  { return it; }
}

Nonempty_Strategy_Commalist _Nonempty_Strategy_Commalist() : {
  Nonempty_Strategy_Commalist it = null;
  Strategy _it;
  Nonempty_Strategy_Commalist _next;
} {
  { it=new Nonempty_Strategy_Commalist(); }
  _it=_Strategy() { it.set_it(_it); }
  [  ","  _next=_Nonempty_Strategy_Commalist() { it.set_next(_next); }  ]
  { return it; }
}

Nonempty_NameBinding_Commalist _Nonempty_NameBinding_Commalist() : {
  Nonempty_NameBinding_Commalist it = null;
  NameBinding _it;
  Nonempty_NameBinding_Commalist _next;
} {
  { it=new Nonempty_NameBinding_Commalist(); }
  _it=_NameBinding() { it.set_it(_it); }
  [  ","  _next=_Nonempty_NameBinding_Commalist() { it.set_next(_next); }  ]
  { return it; }
}

Nonempty_Glob_Commalist _Nonempty_Glob_Commalist() : {
  Nonempty_Glob_Commalist it = null;
  Glob _it;
  Nonempty_Glob_Commalist _next;
} {
  { it=new Nonempty_Glob_Commalist(); }
  _it=_Glob() { it.set_it(_it); }
  [  ","  _next=_Nonempty_Glob_Commalist() { it.set_next(_next); }  ]
  { return it; }
}

Nonempty_ClassGlob_Commalist _Nonempty_ClassGlob_Commalist() : {
  Nonempty_ClassGlob_Commalist it = null;
  ClassGlob _it;
  Nonempty_ClassGlob_Commalist _next;
} {
  { it=new Nonempty_ClassGlob_Commalist(); }
  _it=_ClassGlob() { it.set_it(_it); }
  [  ","  _next=_Nonempty_ClassGlob_Commalist() { it.set_next(_next); }  ]
  { return it; }
}

Nonempty_AspectStrategy_List _Nonempty_AspectStrategy_List() : {
  Nonempty_AspectStrategy_List it = null;
  AspectStrategy _it;
  Nonempty_AspectStrategy_List _next;
} {
  { it=new Nonempty_AspectStrategy_List(); }
  _it=_AspectStrategy() { it.set_it(_it); }
  [  _next=_Nonempty_AspectStrategy_List() { it.set_next(_next); }  ]
  { return it; }
}

Nonempty_AspectNodeSet_List _Nonempty_AspectNodeSet_List() : {
  Nonempty_AspectNodeSet_List it = null;
  AspectNodeSet _it;
  Nonempty_AspectNodeSet_List _next;
} {
  { it=new Nonempty_AspectNodeSet_List(); }
  _it=_AspectNodeSet() { it.set_it(_it); }
  [  _next=_Nonempty_AspectNodeSet_List() { it.set_next(_next); }  ]
  { return it; }
}

Nonempty_NodeClassName_Commalist _Nonempty_NodeClassName_Commalist() : {
  Nonempty_NodeClassName_Commalist it = null;
  NodeClassName _it;
  Nonempty_NodeClassName_Commalist _next;
} {
  { it=new Nonempty_NodeClassName_Commalist(); }
  _it=_NodeClassName() { it.set_it(_it); }
  [  ","  _next=_Nonempty_NodeClassName_Commalist() { it.set_next(_next); }  ]
  { return it; }
}


boolean _boolean() : { Token t; }{
  ( t=<TRUE> { return true; }
  | t=<FALSE> { return false; }
  )
}

char _char() : { Token t; } {
    t=<CHARACTER_LITERAL> { 
       String s = t.image; 
       return unescapifyChar(s.substring(1, s.length()-1)); 
    } 
} 

byte _byte() : { int i; } 
{ i=_int() { return (byte) i; } } 

short _short() : { int i; } 
{ i=_int() { return (short) i; } } 

int _int() : { Number num; } 
{ num=_Number() { return num.intValue(); } } 

long _long() : { Number num; } 
{ num=_Number() { return num.longValue(); } } 

float _float() : { Number num; } 
{ num=_Number() { return num.floatValue(); } } 

double _double() : { Number num; } 
{ num=_Number() { return num.doubleValue(); } } 

Boolean _Boolean() : { Token t; }{
  ( t=<TRUE> { return Boolean.TRUE; }
  | t=<FALSE> { return Boolean.FALSE; }
  )
}

Character _Character() : { char c; } 
{ c=_char() { return new Character(c); } }

Integer _Integer() : { int i; } 
{ i = _int() { return new Integer(i); } }

Long _Long() : { long l; } 
{ l=_long() { return new Long(l); } } 

Float _Float() : { float f; } 
{ f=_float() { return new Float(f); } } 

Double _Double() : { double d; } 
{ d=_double() { return new Double(d); } } 

Number _Number() : 
{
    Token t; 
    String s = null; 
    int radix = 0; 
    Number num = null; 
} {
  ( 
    ( t=<DECIMAL_LITERAL> { 
       s = t.image; 
       radix = 10; 
      } 
    | t=<HEX_LITERAL> { 
       // Strip off the "0x". 
       s = t.image.substring(2, t.image.length()); 
       radix = 16; 
      } 
    | t=<OCTAL_LITERAL> { 
       s = t.image; 
       radix = 8; 
      } 
    ) { 
       switch (s.charAt(s.length()-1)) { 
       case 'l': case 'L': 
         s = s.substring(0, s.length()-1);
         num = new Long(new java.math.BigInteger(s, radix).longValue());
         break; 
       default: 
         num = new Integer(new java.math.BigInteger(s, radix).intValue());
         break; 
       } 
    } 
  | t=<FLOATING_POINT_LITERAL> { 
       s = t.image; 
       switch (s.charAt(s.length()-1)) { 
       case 'd': case 'D': 
           num = Double.valueOf(s.substring(0, s.length()-1)); 
           break; 
       case 'f': case 'F': 
           num = Float.valueOf(s.substring(0, s.length()-1)); 
           break; 
       default: 
           num = Float.valueOf(s); 
           break; 
       } 
    } 
  ) { return num; } 
} 

String _String() : { Token t; } {
    t=<STRING_LITERAL> { 
       String s = t.image; 
       return unescapify(s.substring(1, s.length()-1)); 
    } 
} 

StringBuffer _StringBuffer() : { String s; } 
{ s=_String() { return new StringBuffer(s); } }

Ident _Ident() : { Token t; } {
    t=<IDENTIFIER> { 
       return new Ident(t.image); 
    } 
} 

Text _Text() : { Token t; } {
    t=<TEXT_LITERAL> { 
       String s = t.image; 
       return new Text(s.substring(2, s.length()-2)); 
    } 
} 

Line _Line() : { Token t; } {
    { token_source.SwitchTo(1); } 
    t=<LINE> { 
       return new Line(t.image); 
    } 
} 

Word _Word() : { Token t; } {
    { token_source.SwitchTo(2); } 
    t=<WORD> { 
       return new Word(t.image); 
    } 
} 

// Lexical specification (largely taken from Java.jack): 

SKIP : {
  " " 
| "\t" 
| "\n" 
| "\r" 
| <"//" (~["\n","\r"])* ("\n"|"\r\n")> 
| <"/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/"> 
} 
 
TOKEN : { /* LITERALS */
  < DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* (["l","L"])? > 
| 
  < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ (["l","L"])? > 
| 
  < OCTAL_LITERAL: "0" (["0"-"7"])* (["l","L"])? > 
| 
  < FLOATING_POINT_LITERAL: 
        (["0"-"9"])+ "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])? 
      | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])? 
      | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])? 
      | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"] 
  > 
| 
  < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > 
| 
  < CHARACTER_LITERAL: 
      "'" 
      (   (~["\'","\\","\n","\r"]) 
        | ("\\" 
            ( ["n","t","b","r","f","\\","\'","\""] 
            | ["0"-"7"] ( ["0"-"7"] )? 
            | ["0"-"3"] ["0"-"7"] ["0"-"7"] 
            ) 
          ) 
      ) 
      "'" 
  >   
| 
  < STRING_LITERAL: 
      "\"" 
      (   (~["\"","\\","\n","\r"]) 
        | ("\\" 
            ( ["n","t","b","r","f","\\","\'","\""] 
            | ["0"-"7"] ( ["0"-"7"] )? 
            | ["0"-"3"] ["0"-"7"] ["0"-"7"] 
            ) 
          ) 
      )* 
      "\"" 
  > 
| 
  < TEXT_LITERAL: 
     ( "(@" 
           (~["@"])* 
           ( "@" ~[")"] 
             (~["@"])* 
           )* 
      "@)" ) 
    | ( "{{" 
           (~["}"])* 
           ( "}" ~["}"] 
             (~["}"])* 
           )* 
      "}}" ) 
  > 
| 
  < TRUE: "true" >
| 
  < FALSE: "false" >
} 

TOKEN : { /* IDENTIFIERS */ 
  < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
|
  < #LETTER:
      [
       "\u0024",
       "\u0041"-"\u005a",
       "\u005f",
       "\u0061"-"\u007a",
       "\u00c0"-"\u00d6",
       "\u00d8"-"\u00f6",
       "\u00f8"-"\u00ff",
       "\u0100"-"\u1fff",
       "\u3040"-"\u318f",
       "\u3300"-"\u337f",
       "\u3400"-"\u3d2d",
       "\u4e00"-"\u9fff",
       "\uf900"-"\ufaff"
      ]
  >
|
  < #DIGIT:
      [
       "\u0030"-"\u0039",
       "\u0660"-"\u0669",
       "\u06f0"-"\u06f9",
       "\u0966"-"\u096f",
       "\u09e6"-"\u09ef",
       "\u0a66"-"\u0a6f",
       "\u0ae6"-"\u0aef",
       "\u0b66"-"\u0b6f",
       "\u0be7"-"\u0bef",
       "\u0c66"-"\u0c6f",
       "\u0ce6"-"\u0cef",
       "\u0d66"-"\u0d6f",
       "\u0e50"-"\u0e59",
       "\u0ed0"-"\u0ed9",
       "\u1040"-"\u1049"
      ]
  >
}

<Line> TOKEN : {
  < LINE: (~["\n","\r"])* > : DEFAULT
}

<Word> SKIP :  { " " | "\t" | "\n" | "\r" }
<Word> TOKEN : {
  < WORD: (~[" ","\t","\n","\r"])* > : DEFAULT
}