pj
Class PJ.IdInfo

java.lang.Object
  extended by pj.PJ.Info
      extended by pj.PJ.IdInfo
All Implemented Interfaces:
Dump.Helper, Leaf
Enclosing class:
PJ

protected class PJ.IdInfo
extends PJ.Info

represents a jay terminal or non-terminal. This would be less convoluted if there were declare before use.

If token is false and PJ.Info.type is null, this nonterminal has been used but not defined; if PJ.Info.type is null after all rules have been parsed, this identifier will be defaulted as a typed(!) token.

See Also:
setup(), PJ.Token, PJ.Rule(java.lang.String, java.lang.String, java.util.ArrayList)

Field Summary
protected  PJ.Info input
          representation, if any.
protected  boolean many
          flags to indicate if identifier is a token or used iteratively.
protected  String manyName
          names for iterations, generated after all rules have been parsed.
protected  boolean opt
          flags to indicate if identifier is a token or used iteratively.
protected  String optName
          names for iterations, generated after all rules have been parsed.
protected  ArrayList sepNames
          names for delimeted iterations, generated after all rules have been parsed.
protected  ArrayList seps
          contains (unique) PJ.Info for delimeted iterations.
protected  boolean some
          flags to indicate if identifier is a token or used iteratively.
protected  String someName
          names for iterations, generated after all rules have been parsed.
protected  boolean token
          flags to indicate if identifier is a token or used iteratively.
 
Fields inherited from class pj.PJ.Info
id, represented, type
 
Constructor Summary
protected PJ.IdInfo(String id)
          constructs a name which evolves into a nonterminal or a defaulted token.
protected PJ.IdInfo(String optType, String id, Leaf optInput)
          constructs a token, i.e., a category of inputs.
 
Method Summary
 boolean collect()
          nonterminals and typed terminals are collected.
 void dump(Dump sender, Class c, Object o)
           
 PJ.Info input()
           
 void lex(int n, PrintWriter out)
          delegate to n'th separator.
 boolean many()
           
 String manyName()
           
protected  String name(boolean impossible, String prefer, String alt, Object[] args)
          create a name for an iterative use.
 boolean opt()
           
 String optName()
           
 void prolog(ArrayList out)
          create %token or %type statements.
 void rules(PrintWriter out, boolean recover)
          generate rules for iterative constructs.
 boolean sep()
          true if used iteratively with delimeters.
 String sepName(int n)
           
 void setInput(Leaf optInput)
           
 void setMany()
          remember iterative use.
 void setOpt()
          remember optional use.
 int setSep(Leaf operator)
          remember iterative use.
 void setSome()
          remember iterative use.
 void setType(String type)
          overwritten to inform input, if any.
 void setup()
          default an unknown id as a (unrepresentable) terminal; define names for iterative uses if any.
 boolean some()
           
 String someName()
           
 boolean token()
           
 
Methods inherited from class pj.PJ.Info
comment, lex, name, setName, type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

input

protected PJ.Info input
representation, if any.


token

protected boolean token
flags to indicate if identifier is a token or used iteratively.


opt

protected boolean opt
flags to indicate if identifier is a token or used iteratively.


some

protected boolean some
flags to indicate if identifier is a token or used iteratively.


many

protected boolean many
flags to indicate if identifier is a token or used iteratively.


seps

protected final ArrayList seps
contains (unique) PJ.Info for delimeted iterations.


optName

protected String optName
names for iterations, generated after all rules have been parsed.


someName

protected String someName
names for iterations, generated after all rules have been parsed.


manyName

protected String manyName
names for iterations, generated after all rules have been parsed.


sepNames

protected final ArrayList sepNames
names for delimeted iterations, generated after all rules have been parsed.

See Also:
setup()
Constructor Detail

PJ.IdInfo

protected PJ.IdInfo(String optType,
                    String id,
                    Leaf optInput)
constructs a token, i.e., a category of inputs.

Parameters:
optType - can be null: a token without a type does not get collected.
See Also:
PJ.Name(java.lang.String), PJ.IdDef(java.lang.String, pj.Leaf)

PJ.IdInfo

protected PJ.IdInfo(String id)
constructs a name which evolves into a nonterminal or a defaulted token.

See Also:
PJ.IdRef(java.lang.String)
Method Detail

setType

public void setType(String type)
overwritten to inform input, if any.

Overrides:
setType in class PJ.Info
See Also:
PJ.Info.type

collect

public boolean collect()
nonterminals and typed terminals are collected.

Specified by:
collect in interface Leaf
Overrides:
collect in class PJ.Info

input

public PJ.Info input()
See Also:
input

setInput

public void setInput(Leaf optInput)
See Also:
input, PJ.IdDef(java.lang.String, pj.Leaf)

token

public boolean token()
See Also:
token

opt

public boolean opt()
See Also:
opt

setOpt

public void setOpt()
remember optional use.


optName

public String optName()
See Also:
optName, setup()

some

public boolean some()
See Also:
some

setSome

public void setSome()
remember iterative use.


someName

public String someName()
See Also:
someName, setup()

many

public boolean many()
See Also:
many

setMany

public void setMany()
remember iterative use.


manyName

public String manyName()
See Also:
manyName, setup()

sep

public boolean sep()
true if used iteratively with delimeters.

See Also:
seps

setSep

public int setSep(Leaf operator)
remember iterative use.

Returns:
unique index into seps.

sepName

public String sepName(int n)
See Also:
sepNames, setup()

setup

public void setup()
default an unknown id as a (unrepresentable) terminal; define names for iterative uses if any.


name

protected String name(boolean impossible,
                      String prefer,
                      String alt,
                      Object[] args)
create a name for an iterative use.

Parameters:
impossible - if true, only use alt as a key.
prefer - preferred key for PJ.templates.
alt - alternate key for PJ.templates.
args - formatting parameters.

lex

public void lex(int n,
                PrintWriter out)
delegate to n'th separator.


prolog

public void prolog(ArrayList out)
create %token or %type statements.


rules

public void rules(PrintWriter out,
                  boolean recover)
generate rules for iterative constructs.

Parameters:
recover - set to generate robust error recovery -- likely to result in some more shift/reduce conflicts.

dump

public void dump(Dump sender,
                 Class c,
                 Object o)