org.nlogo.api
Class Syntax

java.lang.Object
  extended by org.nlogo.api.Syntax

public final class Syntax
extends Object

Specifies the arguments accepted by a primitive. Used by the compiler for type-checking.

You cannot instantiate this class directly. Instead, use the static construction methods Syntax.commandSyntax(...) or Syntax.reporterSyntax(...).

For example, in a Reporter that takes two number arguments and returns a boolean, implement Primitive.getSyntax() as follows:

 Syntax getSyntax() {
   int[] right = new int[] { Syntax.TYPE_NUMBER, Syntax.TYPE_NUMBER };
   int ret = Syntax.TYPE_BOOLEAN;
   return Syntax.reporterSyntax( right, ret );
 }
 

An input can be made variadic, meaning that the it can be repeated any number of times when enclosed in parentheses, if you add the TYPE_REPEATABLE flag. When using variadic inputs you should also define the default number of inputs, that is, the number of inputs expect if the user does not use parentheses. For example:

  Syntax getSyntax() {
    return Syntax.reporterSyntax
      ( new int[] { Syntax.TYPE_WILDCARD | Syntax.TYPE_REPEATABLE }, Syntax.TYPE_LIST , 2 ) ;
  }
 

See Also:
Primitive.getSyntax()

Field Summary
static int COMMAND_PRECEDENCE
           
static int NORMAL_PRECEDENCE
           
static int TYPE_AGENT
          Type constant for set of agents.
static int TYPE_AGENTSET
          Type constant for set of agents.
static int TYPE_BOOLEAN
          Type constant for boolean.
static int TYPE_BOOLEAN_BLOCK
          Type constant for boolean reporter blocks
static int TYPE_BRACKETED
           
static int TYPE_COMMAND_BLOCK
          Type constant for command blocks
static int TYPE_LINK
          Type constant for links.
static int TYPE_LINKSET
          Type constant for agentset of links.
static int TYPE_LIST
          Type constant for list.
static int TYPE_NOBODY
          Type constant for nobody.
static int TYPE_NUMBER
          Type constant for number (integer or floating point).
static int TYPE_NUMBER_BLOCK
          Type constant for number reporter blocks
static int TYPE_OPTIONAL
          Type constant for optional arguments.
static int TYPE_OTHER_BLOCK
          Type constant for non-boolean, non-number reporter blocks
static int TYPE_PATCH
          Type constant for patches.
static int TYPE_PATCHSET
          Type constant for agentset of patches.
static int TYPE_READABLE
          Type constant for readables.
static int TYPE_REFERENCE
           
static int TYPE_REPEATABLE
          Type constant to indicate that an input is variadic it should be used with another type desgination, for example: TYPE_NUMBER | TYPE_REPEATABLE indicates that this input is a number and is variadic
static int TYPE_REPORTER_BLOCK
          Type constant for reporter blocks TYPE_REPORTER_BLOCK = TYPE_BOOLEAN_BLOCK | TYPE_NUMBER_BLOCK | TYPE_OTHER_BLOCK
static int TYPE_STRING
          Type constant for string.
static int TYPE_TURTLE
          Type constant for turtles.
static int TYPE_TURTLESET
          Type constant for agentset of turtles.
static int TYPE_VOID
          Unsupported.
static int TYPE_WILDCARD
          Type constant for wildcard (any input) TYPE_WILDCARD = TYPE_NUMBER | TYPE_BOOLEAN | TYPE_STRING | TYPE_LIST | TYPE_AGENT | TYPE_AGENTSET | TYPE_NOBODY this type is also used to identify extension types
 
Method Summary
static Syntax commandSyntax()
          Returns an EMPTY_SYNTAX Object for commands with no arguments.
static Syntax commandSyntax(int[] right)
          Returns a Syntax for commands with one or more right arguments.
static Syntax commandSyntax(int[] right, int dfault)
          Returns a Syntax for commands with a variable number of arguments.
static String convertOldStyleAgentClassString(String oldStyle)
           
 int getDfault()
           
 int getLeft()
           
 int getPrecedence()
           
 int getRet()
           
 int[] getRight()
           
static Syntax reporterSyntax(int ret)
          Returns a Syntax for reporters with no arguments
static Syntax reporterSyntax(int[] right, int ret)
          Returns a Syntax for reporters with one or more right arguments
static Syntax reporterSyntax(int[] right, int ret, int dfault)
          Returns a Syntax for reporters with a variable number of arguments.
static Syntax reporterSyntax(int left, int[] right, int ret, int precedence)
          Returns a Syntax for reporters with infix arguments.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_VOID

public static final int TYPE_VOID
Unsupported. Do not use.

See Also:
Constant Field Values

TYPE_NUMBER

public static final int TYPE_NUMBER
Type constant for number (integer or floating point).

See Also:
Constant Field Values

TYPE_BOOLEAN

public static final int TYPE_BOOLEAN
Type constant for boolean.

See Also:
Constant Field Values

TYPE_STRING

public static final int TYPE_STRING
Type constant for string.

See Also:
Constant Field Values

TYPE_LIST

public static final int TYPE_LIST
Type constant for list.

See Also:
Constant Field Values

TYPE_TURTLESET

public static final int TYPE_TURTLESET
Type constant for agentset of turtles.

See Also:
Constant Field Values

TYPE_PATCHSET

public static final int TYPE_PATCHSET
Type constant for agentset of patches.

See Also:
Constant Field Values

TYPE_LINKSET

public static final int TYPE_LINKSET
Type constant for agentset of links.

See Also:
Constant Field Values

TYPE_AGENTSET

public static final int TYPE_AGENTSET
Type constant for set of agents. TYPE_AGENTSET = TYPE_TURTLESET | TYPE_PATCHSET | TYPE_LINKSET.

See Also:
Constant Field Values

TYPE_NOBODY

public static final int TYPE_NOBODY
Type constant for nobody.

See Also:
Constant Field Values

TYPE_TURTLE

public static final int TYPE_TURTLE
Type constant for turtles.

See Also:
Constant Field Values

TYPE_PATCH

public static final int TYPE_PATCH
Type constant for patches.

See Also:
Constant Field Values

TYPE_LINK

public static final int TYPE_LINK
Type constant for links.

See Also:
Constant Field Values

TYPE_AGENT

public static final int TYPE_AGENT
Type constant for set of agents. TYPE_AGENT = TYPE_TURTLE | TYPE_PATCH | TYPE_LINK.

See Also:
Constant Field Values

TYPE_READABLE

public static final int TYPE_READABLE
Type constant for readables. TYPE_READABLE = TYPE_NUMBER | TYPE_BOOLEAN | TYPE_STRING | TYPE_LIST | TYPE_NOBODY

See Also:
Constant Field Values

TYPE_WILDCARD

public static final int TYPE_WILDCARD
Type constant for wildcard (any input) TYPE_WILDCARD = TYPE_NUMBER | TYPE_BOOLEAN | TYPE_STRING | TYPE_LIST | TYPE_AGENT | TYPE_AGENTSET | TYPE_NOBODY this type is also used to identify extension types

See Also:
Constant Field Values

TYPE_REFERENCE

public static final int TYPE_REFERENCE
See Also:
Constant Field Values

TYPE_COMMAND_BLOCK

public static final int TYPE_COMMAND_BLOCK
Type constant for command blocks

See Also:
Constant Field Values

TYPE_BOOLEAN_BLOCK

public static final int TYPE_BOOLEAN_BLOCK
Type constant for boolean reporter blocks

See Also:
Constant Field Values

TYPE_NUMBER_BLOCK

public static final int TYPE_NUMBER_BLOCK
Type constant for number reporter blocks

See Also:
Constant Field Values

TYPE_OTHER_BLOCK

public static final int TYPE_OTHER_BLOCK
Type constant for non-boolean, non-number reporter blocks

See Also:
Constant Field Values

TYPE_REPORTER_BLOCK

public static final int TYPE_REPORTER_BLOCK
Type constant for reporter blocks TYPE_REPORTER_BLOCK = TYPE_BOOLEAN_BLOCK | TYPE_NUMBER_BLOCK | TYPE_OTHER_BLOCK

See Also:
Constant Field Values

TYPE_BRACKETED

public static final int TYPE_BRACKETED
See Also:
Constant Field Values

TYPE_REPEATABLE

public static final int TYPE_REPEATABLE
Type constant to indicate that an input is variadic it should be used with another type desgination, for example: TYPE_NUMBER | TYPE_REPEATABLE indicates that this input is a number and is variadic

See Also:
Constant Field Values

TYPE_OPTIONAL

public static final int TYPE_OPTIONAL
Type constant for optional arguments. At present, TYPE_OPTIONAL is implemented only in combination with TYPE_COMMAND_BLOCK as the last argument - ST 5/25/06

See Also:
Constant Field Values

COMMAND_PRECEDENCE

public static final int COMMAND_PRECEDENCE
See Also:
Constant Field Values

NORMAL_PRECEDENCE

public static final int NORMAL_PRECEDENCE
See Also:
Constant Field Values
Method Detail

getRight

public int[] getRight()

getLeft

public int getLeft()

getRet

public int getRet()

getPrecedence

public int getPrecedence()

getDfault

public int getDfault()

commandSyntax

public static Syntax commandSyntax()
Returns an EMPTY_SYNTAX Object for commands with no arguments.


commandSyntax

public static Syntax commandSyntax(int[] right)
Returns a Syntax for commands with one or more right arguments.

Parameters:
right - an array of TYPE flags that are to be to the right of the Primitive

commandSyntax

public static Syntax commandSyntax(int[] right,
                                   int dfault)
Returns a Syntax for commands with a variable number of arguments.

Parameters:
right - an array of TYPE flags that are to be to the right of the primitive
dfault - the default number of arguments if no parenthesis are used.

reporterSyntax

public static Syntax reporterSyntax(int ret)
Returns a Syntax for reporters with no arguments

Parameters:
ret - the return type

reporterSyntax

public static Syntax reporterSyntax(int left,
                                    int[] right,
                                    int ret,
                                    int precedence)
Returns a Syntax for reporters with infix arguments.

Parameters:
left -
right -
ret - the return type
precedence -

reporterSyntax

public static Syntax reporterSyntax(int[] right,
                                    int ret)
Returns a Syntax for reporters with one or more right arguments

Parameters:
right - an array of TYPE flags that are to the be right of the Primitive
ret - the return type

reporterSyntax

public static Syntax reporterSyntax(int[] right,
                                    int ret,
                                    int dfault)
Returns a Syntax for reporters with a variable number of arguments.

Parameters:
right - an array of TYPE flags that are to the be right of the primitive
ret - the return type
dfault - the default number of arguments if no parenthesis are used.

convertOldStyleAgentClassString

public static String convertOldStyleAgentClassString(String oldStyle)