Apertium-recursive/Bytecode
< Apertium-recursive
Jump to navigation
Jump to search
Revision as of 00:14, 11 July 2020 by Popcorndude (talk | contribs)
File Structure
Recursive transfer bytecode files are written using Lttoolbox/compression.h
. The structure of the file is as follows:
Length of the longest input-time pattern (including blanks) Number of input-time rules [ for each input-time rule: the length the pattern the the rule ] Number of output-time rules Bytecode of each rule Number of global chunk variable slots Alphabet for the pattern transducer Pattern transducer The mapping from final states to rules Attribute patterns Global variables Lists
Datatypes
The datatypes available to bytecode instructions are string
, integer
, boolean
, and Chunk
, where Chunk objects represent lexical units, chunks, and blanks.
Bytecode Operations
[int] after the name indicates that this instruction is two characters long and the second is to be interpreted as an integer.
Name | Action | Stack before | Stack after |
---|---|---|---|
drop | pop the top of the stack | [1] X [2] ... |
[1] ... |
dup | push a copy of the top element | [1] X [2] ... |
[1] X [2] X [3] ... |
over | push a copy of the second element | [1] X [2] Y [3] ... |
[1] Y [2] X [3] Y [4] ... |
swap | exchange the first and second elements | [1] X [2] Y [3] ... |
[1] Y [2] X [3] ... |
string [int] | pushes the next [int] characters onto the stack as a literal string | [1] ... |
[1] string [2] ... |
int [int] | pushes [int] onto the stack | [1] ... |
[1] int [2] ... |
pushfalse | pushes false onto the stack | [1] ... |
[1] false [2] ... |
pushtrue | pushes true onto the stack | [1] ... |
[1] true [2] ... |
jump [int] | increments the instruction pointer by [int] | [1] ... |
[1] ... |
jumpontrue [int] | pops a bool off the stack and increments the instruction pointer by [int] if it is true | [1] bool [2] ... |
[1] ... |
jumponfalse [int] | pops a bool off the stack and increments the instruction pointer by [int] if it is false | [1] bool [2] ... |
[1] ... |
and | pops 2 bools of the stack and pushes whether both of them are true | [1] bool [2] bool [3] ... |
[1] bool [2] ... |
or | pops 2 bools of the stack and pushes whether either of them is true | [1] bool [2] bool [3] ... |
[1] bool [2] ... |
not | logically negates top of stack | [1] bool [2] ... |
[1] bool [2] ... |
equal | push whether the first two strings popped are the same | [1] string [2] string [3] ... |
[1] bool [2] ... |
isprefix | push whether the first string popped occurs at the beginning of the second | [1] string (part) [2] string (whole) [3] ... |
[1] bool [2] ... |
issuffix | push whether the first string popped occurs at the end of the second | [1] string (part) [2] string (whole) [3] ... |
[1] bool [2] ... |
issubstring | pushes whether the first string popped appears anywhere in the second | [1] string (part) [2] string (whole) [3] ... |
[1] bool [2] ... |
equalcl | equal , but ignores case
|
[1] string [2] string [3] ... |
[1] bool [2] ... |
isprefixcl | isprefix , but ignores case
|
[1] string (part) [2] string (whole) [3] ... |
[1] bool [2] ... |
issuffixcl | issuffix , but ignores case
|
[1] string (part) [2] string (whole) [3] ... |
[1] bool [2] ... |
issubstringcl | issubstring , but ignores case
|
[1] string (part) [2] string (whole) [3] ... |
[1] bool [2] ... |
hasprefix | push whether the second string popped begins with any member of the list named by the first string popped | [1] string (list) [2] string [3] ... |
[1] bool [2] ... |
hassuffix | push whether the second string popped ends with any member of the list named by the first string popped | [1] string (list) [2] string [3] ... |
[1] bool [2] ... |
in | push whether the second string popped is a member of the list named by the first | [1] string (list) [2] string [3] ... |
[1] bool [2] ... |
hasprefixcl | hasprefix , but ignores case
|
[1] string (list) [2] string [3] ... |
[1] bool [2] ... |
hassuffixcl | hassuffix , but ignores case
|
[1] string (list) [2] string [3] ... |
[1] bool [2] ... |
incl | in , but ignores case
|
[1] string (list) [2] string [3] ... |
[1] bool [2] ... |
getcase | pushes "aa", "Aa", or "AA", depending on the case of the first string popped | [1] string (text) [2] ... |
[1] string (case) [2] ... |
setcase | pops two strings, copies the case of the first to the second and pushes the result | [1] string (case) [2] string (text) [3] ... |
[1] string (text) [2] ... |
fetchvar | pops a string and pushes the value of the variable with that name | [1] string (name) [2] ... |
[1] string (value) [2] ... |
setvar | pops a two strings and sets the second as the value of the variable named by the first | [1] string (name) [2] string (value) [3] ... |
[1] ... |
fetchchunk | pops an integer and pushes the value of the chunk variable at that index | [1] int [2] ... |
[1] chunk [2] ... |
setchunk | pops an integer and a chunk and sets the chunk as the value of the chunk variable at that index | [1] int [2] chunk [3] ... |
[1] ... |
pushinput | pops an int and pushes the corresponding input chunk | [1] int [2] ... |
[1] chunk [2] ... |
sourceclip | pops a string and a chunk, pushes the value of the corresponding source-side clip | [1] string (part) [2] chunk [3] ... |
[1] string (clip) [2] ... |
targetclip | pops a string and a chunk, pushes the value of the corresponding target-side clip | [1] string (part) [2] chunk [3] ... |
[1] string (clip) [2] ... |
referenceclip | pops a string and a chunk, pushes the value of the corresponding reference-side clip | [1] string (part) [2] chunk [3] ... |
[1] string (clip) [2] ... |
setclip | pops an int and two strings, sets the second string as the value of the target-side clip identified by the int and the first string. If the integer is 0, the chunk on top of the stack is used. | [1] int [2] string (part) [3] string (value) [4] (chunk) [5] ... |
[1] (chunk) [2] ... |
chunk | creates an empty chunk and pushes it | [1] ... |
[1] chunk [2] ... |
appendchild | pops a chunk and appends it as a child to the chunk underneath it (which remains on the stack) | [1] chunk (child) [2] chunk (parent) [3] ... |
[1] chunk (parent) [2] ... |
appendsurface | pops a string and appends it to the target-side surface chunk underneath it (which remains on the stack) | [1] string [2] chunk [3] ... |
[1] chunk [2] ... |
appendsurfacesl | pops a string and appends it to the source-side surface chunk underneath it (which remains on the stack) | [1] string [2] chunk [3] ... |
[1] chunk [2] ... |
appendsurfaceref | pops a string and appends it to the reference-side surface chunk underneath it (which remains on the stack) | [1] string [2] chunk [3] ... |
[1] chunk [2] ... |
appendallchildren | pops a chunk and appends all of its children as children to the chunk underneath it (which remains on the stack) | [1] chunk (source) [2] chunk (destination) [3] ... |
[1] chunk (destination) [2] ... |
output | pops a chunk and appends it to the output queue | [1] chunk [2] ... |
[1] ... |
appendallinput | append the entire input queue as children of the chunk on top of the stack | [1] chunk [2] ... |
[1] chunk [2] ... |
blank | pops an int and pushes the corresponding blank (or a single space if the int is 0) | [1] int [2] ... |
[1] chunk (blank) [2] ... |
outputall | moves everything in the input queue to the output queue and ends the rule execution (creates a no-op rule) | [1] ... |
[1] ... |
concat | pops two strings, concatenates them, and pushes the result | [1] string X [2] string Y [3] ... |
[1] string YX [2] ... |
rejectrule | abort evaluation of current rule and attempt to match a different one | [1] ... |
[1] ... |
distag | removes initial < and final > from the string on top of the stack (this makes compiling comparisons easier) | [1] string (tag) [2] ... |
[1] string (text) [2] ... |
getrule | pop an int and push the index of the output rule associated with the chunk in that position. | [1] int (position) [2] ... |
[1] int (rule) [2] ... |
setrule | pop two ints, a position and a rule and push the output rule associated with the chunk in that position. 0 refers to the top of the stack | [1] int (position) [1] int (rule) [2] [chunk] [3] ... |
[1] chunk [2] ... |
lucount | push a string corresponding to the number of chunks in the input to the rule | [1] ... |
[1] string (number) [2] ... |
conjoin | push a joiner blank onto the stack | [1] ... |
[1] + (chunk) [2] ... |