Difference between revisions of "Apertium-recursive/Bytecode"

From Apertium
Jump to navigation Jump to search
(→‎Bytecode Operations: add fetchchunk and setchunk)
(changes to clip instructions)
Line 423: Line 423:
 
</pre>
 
</pre>
 
|-
 
|-
  +
| pushinput
| sourceclip
 
| pops an int and a string, pushes the value of the source-side clip identified by them
+
| pops an int and pushes the corresponding input chunk
 
| <pre>
 
| <pre>
 
[1] int
 
[1] int
[2] string (part)
+
[2] ...
  +
</pre>
  +
| <pre>
  +
[1] chunk
  +
[2] ...
  +
</pre>
  +
|-
 
| sourceclip
  +
| pops a string and a chunk, pushes the value of the corresponding source-side clip
  +
| <pre>
  +
[1] string (part)
  +
[2] chunk
 
[3] ...
 
[3] ...
 
</pre>
 
</pre>
Line 436: Line 447:
 
|-
 
|-
 
| targetclip
 
| targetclip
| pops an int and a string, pushes the value of the target-side clip identified by them
+
| pops a string and a chunk, pushes the value of the corresponding target-side clip
 
| <pre>
 
| <pre>
[1] int
+
[1] string (part)
[2] string (part)
+
[2] chunk
 
[3] ...
 
[3] ...
 
</pre>
 
</pre>
Line 448: Line 459:
 
|-
 
|-
 
| referenceclip
 
| referenceclip
| pops an int and a string, pushes the value of the reference-side clip identified by them
+
| pops a string and a chunk, pushes the value of the corresponding reference-side clip
 
| <pre>
 
| <pre>
[1] int
+
[1] string (part)
[2] string (part)
+
[2] chunk
 
[3] ...
 
[3] ...
 
</pre>
 
</pre>

Revision as of 16:29, 17 August 2019

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] ...
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 an int and set it as the index of the output rule of the chunk on top of the stack
[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] ...