-
Notifications
You must be signed in to change notification settings - Fork 0
Defining constants
amomra edited this page Apr 20, 2015
·
2 revisions
Parser constants can either be values of type double
or string
. Constness refers to the bytecode. Constants will be stored by their value in the bytecode, not by a reference to their address. Thus accessing them is faster. They may be optimized away if this is possible. Defining new constants or changing old ones will reset the parser to string parsing mode thus resetting the bytecode.
The Names of user defined constants may contain only the following characters: 0-9, a-z, A-Z, _
, and they may not start with a number. Violating this rule will raise a parser error.
// Define value constant _pi
parser.DefineConst("_pi", 3.14);
// Define a string constant named strBuf
parser.DefineStrConst("strBuf", "hello world");
Querying parser constants is similar to querying variables.
// Get the map with the constants
var constants = p.Consts;
// Get the number of constants
Console.WriteLine(constants.Count);
// Query one constant
double v = constants["varName"];
// Query the constants
foreach(var constant in constants)
Console.WriteLine("Name: {0} | Value: {1}", constant.Key, constant.Value);
Removing constants can only be done all at once using ClearConst
.
// Remove all constants
parser.ClearConst();
- Getting started
- Setting and evaluating an expression
- Setting the expression
- Single return expression evaluation
- Multiple return expression evaluation
- Bulk mode evaluations
- Error handling
- Defining identifier charsets
- Defining parser variables
- Explicitely defining variables
- Implicit creation of new variables
- Querying parser variables
- Removing variables
- Defining constants
- Defining parser constants
- Querying parser constants
- Removing constants
- Setting custom value recognition callbacks
- Defining functions
- Defining parser functions
- Bulk mode functions
- Defining parser operators
- Unary operators
- Binary operators
- Disable built-in operators
- Localization