Specifications
The language is case insensitive. To see more detailed examples of how to use commands, see https://github.com/Algodal/Parser-Generator-Tool-PR/tree/main/samples
TOKENPHASE
@token:
Identify tokenphase actions.
SYNTAXPHASE
@syntax:
Identify tokenphase actions.
CONFIG
@config {}
Contains all config information.
TOKENIZER
@tokenizer []
Assign tokenphase actions or strings that will be a tokenizer.
ENTRYPOINT
@entrypoint []
Assign syntaxphase actions that will begin analyzation.
OBJECTPOINT
@objectpoint []
List of tokenizers or syntaxphase action to save in the abstract syntax tree.
TOKENPHASE_INITIAL_ACTION_CALL
@tokenphase_initial_action_call {.action : ACTION }
Assign an action (from the tokenphase) to be called once before parsing begins.
TOKENPHASE_POP_TOKEN_CREATION
@tokenphase_pop_token_creation {.label : LABEL, .stop: NUMBER }
Assign a label (from an action in the tokenphase) create tokens for each pop from the stack. The stop attribute tells when to stop popping based on how many items are remaining on the stack. This process occurs at the end of parsing at the tokenization phase.
TOKENPHASE_POP_ALL
@tokenphase_pop_all {.set : TRUE_VALUE }
Clears the stack. This process occurs at the end of parsing at the tokenization phase. The value is literally –true such as @tokenphase_pop_all {.set : –true }
ACTION
@action A <>
The defines an action. The content of an action is parser source instruction.
CHAR
@char
Parse any single character from the text.
COMPARE-CHAR-RANGE
@char { 0x20 }
@char { 0x20 : 0x32}
@char {'A'}
@char {'A' : 'Z'}
@char {'😀' : '😹'}
Parse a single character that matches the given range. The range can be a single value or smallest and bigest value.
COMPARE-POINT-RANGE
Ta { 0x20 }
Tb { 0x20 : 0x32}
Sa {'A'}
Sb {'A' : 'Z'}
A {'😀' : '😹'}
Compares the result parsed by the action (identified by the label) to the given character range.
Important
If the text parsed is greater than the length of a single character then this operation will be unsuccessful.
COMPARE-POINT-STRING
Compares the result parsed by the action (identified by the label) to the given string.
name {"Fred"}
You can also compare using sub-string using the sub-string identier % and the length of the string to compare.
name {"Fr" % 2}
STRING
Parse any a series of characters from the text that matches the string exactly.
"Hello"
Prepend with $ to make case-insensitive.
$"Hello"
Important
In the tokenphase, STRING is a command to parse the text that matches itself exactly. In the syntaxphase, STRING is a parsed token and had to have been used as a tokenizer in the tokenphase.
ORDER
@order "Hello"
@order $"Hello"
Parse any a series of characters from the text that matches the string in any order.
Important
Can be used only in the tokenphase.
ONEOF
@oneof "Hello"
@oneof $"Hello"
Parse any single character from the text that matches one of the characters in the string exactly.
Important
Can be used only in the tokenphase.
NOT
@not "Hello"
@not @oneof $"Hello"
@not ("A" | "B")
The negate a result(unsuccessful becomes successful and successful becomes unsuccessful). If it produces a successful of it’s own, the size will always be 1.
AND
@not "Hello" @and @not Ta
@not @oneof $"Hello" @and @not ("A" | "B") @and @not Sa
The chain NOT commands together. If it produces a successful of it’s own, the size will always be 1.
COUNT
[5] COMMAND # run the command 5 types
[2:7] COMMAND # run the command 2 to 7 times
[?] COMMAND # run the command 0 or 1 time
[*] COMMAND # run the command 0 or MORE times
[+] COMMAND # run the command 1 or MORE times
[3+] COMMAND # run the command 3 or MORE times
The iterator command. The COUNT command is defined using square brackets. The content of the brackets is either a number, number range (number : number) or symbol (+, *, ?) or increment (number followed by +).
DISCARD
@discard Ta
Discard a tokenizer’s token so that it does exist in the syntax phase.
REDUCE
@reduce Ta
Reduces a tokenizer’s token so that multiple of it does not exist in a sequence.
FIRST
@first item | item | item
The parameter of this command is the entire option (and not a single item) unlike other commands. This command gets the first option that is successful rather than the default of getting most successful.
PRIORITY
@tokenizer [name 10, otherName, space -10]
Priority is a feature that allows assigning priortity to competing actions. This degates duplication. Smallest numbers have lowest priority and largest numbers have highest priority.
Important
Only tokenizers support this feature.
SCOPE
<B> # core syntax
@action A < <B> > # used in action
Scope negates adding an item to the abstract syntax tree. It is a feature, that gives extra control of where not to add an objectpoint in the abstract syntax tree.
NULLIFY
@nullify @not A
The nullify reduces a result to a size of 0 but keeps the flag as true. This allows us check if an item would parse without actually parsing and moving the index.
NEWLINE
@newline
Built-in new line command. To make it easier building cross-platform parsers between Windows (rn) and others (n).
XSPACE
@xspace
Built-in horizontal space command.
DEFINE
@define:
%alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
This features allows you to add labels to constants. Then refer to the constants using the labels. For example, @action letter <@oneof %alphabet>.
VARIABLE
@variable:
&alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Allows you to use variable to store constants and results of parsing. Then refer to those variables to make use of it’s values. For example, @action letter <@oneof &alphabet>.
ALIAS
@action A <@char>
@action B @alias A
Allows you to create an action that is an exact copy of the other action.
BYTE
@byte
By default, Algodal™ generated parsers are UTF-8 parsers. However, this function allows you to parse a byte (the alternative to @char which parses UTF-8). When printing the parse data, if the printer detect bytes, it will automatically print them as hexadecimal.
WORD
@word VARIABLE
Used with variables to convert the result of parsing as a numberic word-sized value.
DWORD
@dword VARIABLE
Used with variables to convert the result of parsing as a numberic dword-sized value.
QWORD
@qword VARIABLE
Used with variables to convert the result of parsing as a numberic qword-sized value.
—- STACK —-
Important
The parsers now support stack. Unless you are using the simple API AlgodalParser_ParseText you will have to manually call AlgodalParser_FreeProgramStack at the end of parsing to ensure stack memory is freed.
POP
@pop VARIABLE
Pops an item off the stack.
PUSH
@push VARIABLE
Pushes an item on to the stack.
PEEK
@peek VARIABLE
Takes a look at an item on the stack.
LENGTH
@length VARIABLE
Used with variables to get the length of a parsed text.
GREATER THAN
@gt {ITEM, ITEM}
Used with variables or constants to return TRUE or FALSE if the one item is greater than the other.
LESSER THAN
@lt {ITEM, ITEM}
Used with variables or constants to return TRUE or FALSE if the one item is lesser than the other.
GREATER THAN OR EQUAL TO
@ge {ITEM, ITEM}
Used with variables or constants to return TRUE or FALSE if the one item is greater than or equal to the other.
LESSER THAN OR EQUAL TO
@le {ITEM, ITEM}
Used with variables or constants to return TRUE or FALSE if the one item is lesser than or equal to the other.
EQUAL TO
@eq {ITEM, ITEM}
Used with variables or constants to return TRUE or FALSE if the one item is equal to the other.
NOT EQUAL TO
@ne {ITEM, ITEM}
Used with variables or constants to return TRUE or FALSE if the one item is not equal to the other.
SILENT
@action A <@char> @silent
Ignore any unused warnings.
IF
@if (ITEM) @then (ITEM) @end
If logic. Both the condition and result if true will be processed.
THEN
@if (ITEM) @then (ITEM) @end
Used with the if command.
END
@if (ITEM) @then (ITEM) @end
Used with the if command.
ELSE
@if (ITEM) @then (ITEM) @else (ITEM) @end
Chain the if command
ELSE IF
@if (ITEM) @then (ITEM) @else @if (ITEM) @then (ITEM) @end
Chain the if command
CALL
@call VARIABLE
Call an action if the VARIABLE value is equal to the label of an action.