A NPL Syntax and Reserved Words
This appendix provides the NPL syntax and reserved words.
Table A-1 lists all the NPL methods and the corresponding syntax.
EBNF for NPL
Table A-1 NPL Methods, Operator and Syntax
Method | Operator | Syntax |
---|---|---|
Program |
::= |
( MethodHandlerImportDecl )? ( ConfigDeclaration )? ( VariableDeclaration )+ ( ExposeDeclaration )* ( Statement ) +<EOF> |
MethodHandlerImportDecl |
::= |
"import" <IDENTIFIER> ( "." <IDENTIFIER> )* ";" |
ConfigDeclaration |
::= |
"Config" "{" ( ConfigAttribute )? "}" |
ConfigAttribute |
::= |
<IDENTIFIER> <STRING_LITERAL> ";" |
VariableDeclaration |
::= |
CompositeVariableDecl | SimpleVariableDecl |
CompositeVariableDecl |
::= |
InputRecDecl | OutputRecDecl |
InputRecDecl |
::= |
"InputRec" "{" ( AttributeVariableDecl )+ "}" <IDENTIFIER> ";" |
OutputRecDecl |
::= |
"OutputRec" "{" ( AttributeVariableDecl )+ "}" <IDENTIFIER> ";" |
AttributeVariableDecl |
::= |
AttributeType ( <ATTRIBUTE_NAME> | <IDENTIFIER> | <INTEGER_LITERAL> ) ";" |
SimpleVariableDecl |
::= |
AttributeType <IDENTIFIER> ( SimpleVariableInit )? ";" |
SimpleVariableInit |
::= |
"=" Expression |
AttributeType |
::= |
"String" | "Integer" | "Long" | "TimeInSecs" | "IP" | "TimeInMilliSecs" | "MAC" | "UInt128" | "Byte" | "Short" | "IPv6" | "Float" | "Double" | "Bytes" | "Object" | "List" |
ExposeDeclaration |
::= |
"Expose for" <IDENTIFIER> "{" ( ExposeAttribute )+ "}" |
ExposeAttribute |
::= |
<IDENTIFIER> "." ( <ATTRIBUTE_NAME> | <IDENTIFIER> | <INTEGER_LITERAL> ) ( <STRING_LITERAL> )? ";" |
Statement |
::= |
IfStatement | AssignmentStmt | FunctionStmt | JavaHookStmt |
IfStatement |
::= |
"if" "(" ConditionalExpression ")" IfAction ( "else" "if" "(" ConditionalExpression ")" IfAction )* ( "else" IfAction )? |
ConditionalExpression |
::= |
RelationalExpression ( ConditionalOperator RelationalExpression )* |
ConditionalOperator |
::= |
<OR> | <AND> |
RelationalExpression |
::= |
NestedRelationalExpression | SimpleRelationalExpression | BooleanFunctionExpr |
BooleanFunctionExpr |
::= |
FunctionExpression |
NestedRelationalExpression |
::= |
"(" ConditionalExpression ")" |
SimpleRelationalExpression |
::= |
Expression RelationalOperator Expression |
RelationalOperator |
::= |
<EQ> | <NE> | <LT> | <LE> | <GT> | <GE> |
IfAction |
::= |
StatementBlock | Statement |
StatementBlock |
::= |
"{" ( Statement )* "}" |
AssignmentStmt |
::= |
Variable "=" Expression ";" |
Variable |
::= |
<IDENTIFIER> ( "." ( <ATTRIBUTE_NAME> | <IDENTIFIER> | <INTEGER_LITERAL> ) )? |
Expression |
::= |
AdditiveExpression |
AdditiveExpression |
::= |
SubtractiveExpression ( "+" SubtractiveExpression )* |
SubtractiveExpression |
::= |
MultiplicativeExpression ( "-" MultiplicativeExpression )* |
MultiplicativeExpression |
::= |
DivisionalExpression ( "*" DivisionalExpression )* |
DivisionalExpression |
::= |
UnaryExpression ( "/" UnaryExpression )* |
UnaryExpression |
::= |
( "(" AttributeType ")" )? ( NestedExpression | VariableExpression | IntLiteralExpression | FloatingPointLiteralExpression | StringLiteralExpression | FunctionExpression | JavaHookExpression ) |
NestedExpression |
::= |
( UnaryOperator )? "(" Expression ")" |
VariableExpression |
::= |
( UnaryOperator )? Variable |
IntLiteralExpression |
::= |
( UnaryOperator )? <STRING_LITERAL> |
FloatingPointLiteralExpression |
::= |
( UnaryOperator )? <FLOATING_POINT_LITERAL> |
StringLiteralExpression |
::= |
<STRING_LITERAL> |
FunctionExpression |
::= |
( "byte2bytes" | "byte2str" | "bytes2byte" | "bytes2double" | "bytes2float" | "bytes2hexstr" | "bytes2int" | "bytes2IP" | "bytes2long" | "bytes2short" | "bytes2str" | "bytes2TimeInMilliSecs" | "bytes2TimeInSecs" | "clone" | "convertDateTime" | "copyBits" | "currentTime" | "double2bytes" | "double2str" | "fieldExists" | "float2bytes" | "float2str" | "int2bytes" | "int2str" | "IP2bytes" | "IP2str" | "list2str" | "long2bytes" | "long2str" | "object2str" | "randomInt" | "randomDouble" | "short2bytes" | "short2str" | "strpos" | "str2byte" | "str2bytes" |
- | - |
| "str2double" | "str2float" | "str2int" | "str2IP" | "str2long" | "str2lower" | "str2short" | "str2TimeInMilliSecs" | "str2TimeInSecs" | "str2upper" | "strlen" | "subbytes" | "substr" | "time2bytes" | "time2str" ) "(" ( Expression ( "," Expression )* )? ")" |
UnaryOperator |
::= |
"+" | "-" |
FunctionStmt |
::= |
( "logError" | "logWarning" | "logInfo" | "logTrace" | "write" ) "(" ( Expression ( "," Expression )* )? ")" ";" |
JavaHookStmt |
::= |
JavaHookExpression ";" |
JavaHookExpression |
::= |
"Java" "." <IDENTIFIER> "(" ( Expression ( "," Expression )* )? ")" |
<IDENTIFIER> |
::= |
( <LETTER> | <UNDERSCORE> ) ( <LETTER> | <DIGIT> | <UNDERSCORE>)* |
<ATTRIBUTE_NAME> |
::= |
( <LETTER> | <UNDERSCORE> | <COLON> ) ( <LETTER> | <DIGIT> | <UNDERSCORE> | <COLON> | <HYPHEN> )* |
<FUNCTION_NAME> |
::= |
<LETTER> ( <LETTER> | <DIGIT> )* |
<LETTER> |
::= |
["a"-"z", "A"-"Z"] |
<UNDERSCORE> |
::= |
"_" |
<COLON> |
::= |
":" |
<DIGIT> |
::= |
["0"-"9"] |
<HYPHEN> |
::= |
<MINUS> |
<INTEGER_LITERAL> |
::= |
<DECIMAL_LITERAL> | <HEX_LITERAL> | <OCTAL_LITERAL> |
<DECIMAL_LITERAL> |
::= |
["1"-"9"] (["0"-"9"])* |
<HEX_LITERAL> |
::= |
"0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ |
<OCTAL_LITERAL> |
::= |
"0" (["0"-"7"])* |
<FLOATING_POINT_LITERAL> |
::= |
(["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? |
<EXPONENT> |
::= |
["e","E"] (["+","-"])? (["0"-"9"])+ |
<STRING_LITERAL> |
::= |
"\"" ( (~["\"","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* "\"" |
<OR> |
::= |
"||" |
<AND> |
::= |
"&&" |
<EQ> |
::= |
"==" |
<NE> |
::= |
"!=" |
<LT> |
::= |
"<" |
<LE> |
::= |
"<=" |
<GT> |
::= |
">" |
<GE> |
::= |
">=" |
<MINUS> |
::= |
"-" |
NPL reserved words
-
Byte
-
byte2bytes
-
byte2str
-
Bytes
-
bytes2byte
-
bytes2double
-
bytes2float
-
bytes2hexstr
-
bytes2int
-
bytes2IP
-
bytes2long
-
bytes2short
-
bytes2str
-
bytes2TimeInMilliSecs
-
bytes2TimeInSecs
-
Config
-
convertDateTime
-
copyBits
-
currentTime
-
Double
-
double2bytes
-
double2str
-
else
-
Expose
-
fieldExists
-
Float
-
float2bytes
-
float2str
-
for
-
if
-
import
-
InputRec
-
int2bytesint2str
-
Integer
-
IP
-
IP2bytes
-
IP2str
-
IPv6
-
Java
-
List
-
list2str
-
logError
-
logInfo
-
logTrace
-
logWarning
-
Long
-
long2bytes
-
long2str
-
MAC
-
null
-
Object
-
object2str
-
OutputRec
-
randomInt
-
randomDouble
-
Short
-
short2bytes
-
short2str
-
str2byte
-
str2bytes
-
str2double
-
str2float
-
str2int
-
str2IP
-
str2long
-
str2lower
-
str2short
-
str2TimeInMilliSecs
-
str2TimeInSecs
-
str2upper
-
String
-
strlen
-
strpos
-
subbytes
-
substr
-
time2bytes
-
time2str
-
TimeInMilliSecs
-
TimeInSecs
-
UInt128
-
write