java.lang.Objectorg.nlogo.api.Syntax
public class Syntax
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 ); }
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
|
static int |
TYPE_BRACKETED
|
static int |
TYPE_COMMAND_BLOCK
|
static int |
TYPE_LINK
|
static int |
TYPE_LINKSET
|
static int |
TYPE_LIST
Type constant for list. |
static int |
TYPE_NOBODY
|
static int |
TYPE_NUMBER
Type constant for number (integer or floating point). |
static int |
TYPE_NUMBER_BLOCK
|
static int |
TYPE_OPTIONAL
|
static int |
TYPE_OTHER_BLOCK
|
static int |
TYPE_PATCH
Type constant for set of patch. |
static int |
TYPE_PATCHSET
Type constant for set of patches. |
static int |
TYPE_READABLE
|
static int |
TYPE_REFERENCE
|
static int |
TYPE_REPEATABLE
|
static int |
TYPE_REPORTER_BLOCK
|
static int |
TYPE_STRING
Type constant for string. |
static int |
TYPE_TURTLE
Type constant for set of turtle. |
static int |
TYPE_TURTLESET
Type constant for set of turtles. |
static int |
TYPE_VOID
Unsupported. |
static int |
TYPE_WILDCARD
|
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. |
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 |
---|
public static final int TYPE_VOID
public static final int TYPE_NUMBER
public static final int TYPE_BOOLEAN
public static final int TYPE_STRING
public static final int TYPE_LIST
public static final int TYPE_TURTLESET
public static final int TYPE_PATCHSET
public static final int TYPE_LINKSET
public static final int TYPE_AGENTSET
TYPE_AGENTSET = TYPE_TURTLESET | TYPE_PATCHSET
.
public static final int TYPE_NOBODY
public static final int TYPE_TURTLE
public static final int TYPE_PATCH
public static final int TYPE_LINK
public static final int TYPE_AGENT
TYPE_AGENT = TYPE_TURTLE | TYPE_PATCH
.
public static final int TYPE_READABLE
public static final int TYPE_WILDCARD
public static final int TYPE_REFERENCE
public static final int TYPE_COMMAND_BLOCK
public static final int TYPE_BOOLEAN_BLOCK
public static final int TYPE_NUMBER_BLOCK
public static final int TYPE_OTHER_BLOCK
public static final int TYPE_REPORTER_BLOCK
public static final int TYPE_BRACKETED
public static final int TYPE_REPEATABLE
public static final int TYPE_OPTIONAL
public static final int COMMAND_PRECEDENCE
public static final int NORMAL_PRECEDENCE
Method Detail |
---|
public int[] getRight()
public int getLeft()
public int getRet()
public int getPrecedence()
public int getDfault()
public static Syntax commandSyntax()
EMPTY_SYNTAX
Object for commands with no arguments.
public static Syntax commandSyntax(int[] right)
Syntax
for commands with one or more right arguments.
right
- an array of TYPE flags that are to be to the right of the Primitivepublic static Syntax commandSyntax(int[] right, int dfault)
Syntax
for commands with a variable number of arguments.
right
- an array of TYPE flags that are to be to the right of the primitivedfault
- the default number of arguments if no parenthesis are used.public static Syntax reporterSyntax(int ret)
Syntax
for reporters with no arguments
ret
- the return typepublic static Syntax reporterSyntax(int left, int[] right, int ret, int precedence)
Syntax
for reporters with infix arguments.
left
- right
- ret
- the return typeprecedence
- public static Syntax reporterSyntax(int[] right, int ret)
Syntax
for reporters with one or more right arguments
right
- an array of TYPE flags that are to the be right of the Primitiveret
- the return typepublic static Syntax reporterSyntax(int[] right, int ret, int dfault)
Syntax
for reporters with a variable number of
arguments.
right
- an array of TYPE flags that are to the be right of the primitiveret
- the return typedfault
- the default number of arguments if no parenthesis are used.