| 1 | #!/usr/bin/perl -I/home/phil/perl/cpan/DataTableText/lib/ -I/home/phil/perl/cpan/NasmX86/lib/ -I/home/phil/perl/cpan/AsmC/lib/ | ||||||||||
| 2 | #------------------------------------------------------------------------------- | ||||||||||
| 3 | # Parse a Unisyn expression. | ||||||||||
| 4 | # Philip R Brenan at appaapps dot com, Appa Apps Ltd Inc., 2021 | ||||||||||
| 5 | #------------------------------------------------------------------------------- | ||||||||||
| 6 | # podDocumentation | ||||||||||
| 7 | # Finished in 13.14s, bytes: 2,655,008, execs: 465,858 | ||||||||||
| 8 | package Unisyn::Parse; | ||||||||||
| 9 | our $VERSION = "20210818"; | ||||||||||
| 10 | 1 | ▶ | use warnings FATAL => qw(all); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Carp qw(confess cluck); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Data::Dump qw(dump); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use Data::Table::Text qw(:all !parse); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use Nasm::X86 qw(:all); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use feature qw(say current_sub); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | makeDieConfess; | ||||||||||
| 19 | |||||||||||
| 20 | my $develop = -e q(/home/phil/); # Developing | ||||||||||
| 21 | |||||||||||
| 22 | #D1 Parse # Parse Unisyn expressions | ||||||||||
| 23 | |||||||||||
| 24 | our $Lex = &lexicalData; # Lexical table definitions | ||||||||||
| 25 | our $tree; # Parse tree | ||||||||||
| 26 | |||||||||||
| 27 | our $debug = 0; # Include debug code if true | ||||||||||
| 28 | |||||||||||
| 29 | our $ses = RegisterSize rax; # Size of an element on the stack | ||||||||||
| 30 | our ($w1, $w2, $w3) = (r8, r9, r10); # Work registers | ||||||||||
| 31 | our $prevChar = r11; # The previous character parsed | ||||||||||
| 32 | our $index = r12; # Index of current element | ||||||||||
| 33 | our $element = r13; # Contains the item being parsed | ||||||||||
| 34 | our $start = r14; # Start of the parse string | ||||||||||
| 35 | our $size = r15; # Length of the input string | ||||||||||
| 36 | our $parseStackBase = rsi; # The base of the parsing stack in the stack | ||||||||||
| 37 | our $indexScale = 4; # The size of a utf32 character | ||||||||||
| 38 | our $lexCodeOffset = 3; # The offset in a classified character to the lexical code. | ||||||||||
| 39 | our $bitsPerByte = 8; # The number of bits in a byte | ||||||||||
| 40 | |||||||||||
| 41 | our $Ascii = $$Lex{lexicals}{Ascii} {number}; # Ascii | ||||||||||
| 42 | our $assign = $$Lex{lexicals}{assign} {number}; # Assign | ||||||||||
| 43 | our $CloseBracket = $$Lex{lexicals}{CloseBracket} {number}; # Close bracket | ||||||||||
| 44 | our $empty = $$Lex{lexicals}{empty} {number}; # Empty element | ||||||||||
| 45 | our $NewLineSemiColon = $$Lex{lexicals}{NewLineSemiColon}{number}; # New line semicolon | ||||||||||
| 46 | our $OpenBracket = $$Lex{lexicals}{OpenBracket} {number}; # Open bracket | ||||||||||
| 47 | our $prefix = $$Lex{lexicals}{prefix} {number}; # Prefix operator | ||||||||||
| 48 | our $semiColon = $$Lex{lexicals}{semiColon} {number}; # Semicolon | ||||||||||
| 49 | our $suffix = $$Lex{lexicals}{suffix} {number}; # Suffix | ||||||||||
| 50 | our $term = $$Lex{lexicals}{term} {number}; # Term | ||||||||||
| 51 | our $variable = $$Lex{lexicals}{variable} {number}; # Variable | ||||||||||
| 52 | our $WhiteSpace = $$Lex{lexicals}{WhiteSpace} {number}; # Variable | ||||||||||
| 53 | our $firstSet = $$Lex{structure}{first}; # First symbols allowed | ||||||||||
| 54 | our $lastSet = $$Lex{structure}{last}; # Last symbols allowed | ||||||||||
| 55 | our $asciiNewLine = ord("\n"); # New line in ascii | ||||||||||
| 56 | our $asciiSpace = ord(' '); # Space in ascii | ||||||||||
| 57 | |||||||||||
| 58 | sub getAlpha($$$) #P Load the position of a lexical item in its alphabet from the current character. | ||||||||||
| 59 | 0 | ▶ | {my ($register, $address, $index) = @_; # Register to load, address of start of string, index into string | ||||||||
|
Subroutine
getAlpha: not called CC=1 SCAR=6.9
| |||||||||||
| 60 | 0 | Mov $register, "[$address+$indexScale*$index]"; # Load lexical code | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | sub getLexicalCode($$$) #P Load the lexical code of the current character in memory into the specified register. | ||||||||||
| 64 | 0 | ▶ | {my ($register, $address, $index) = @_; # Register to load, address of start of string, index into string | ||||||||
|
Subroutine
getLexicalCode: not called CC=1 SCAR=6.9
| |||||||||||
| 65 | 0 | Mov $register, "[$address+$indexScale*$index+$lexCodeOffset]"; # Load lexical code | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | sub putLexicalCode($$$$) #P Put the specified lexical code into the current character in memory. | ||||||||||
| 69 | 0 | ▶ | {my ($register, $address, $index, $code) = @_; # Register used to load code, address of string, index into string, code to put | ||||||||
|
Subroutine
putLexicalCode: not called CC=2 SCAR=17.9
| |||||||||||
| 70 | 0 | ▶ | defined($code) or confess; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | Mov $register, $code; | |||||||||
| 72 | 0 | Mov "[$address+$indexScale*$index+$lexCodeOffset]", $register; # Save lexical code | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | sub loadCurrentChar() #P Load the details of the character currently being processed so that we have the index of the character in the upper half of the current character and the lexical type of the character in the lowest byte. | ||||||||||
| 76 | 0 | ▶ | {my $r = $element."b"; # Classification byte | ||||||||
|
Subroutine
loadCurrentChar: not called CC=1 SCAR=6.9
| |||||||||||
| 77 | |||||||||||
| 78 | 0 | Mov $element, $index; # Load index of character as upper dword | |||||||||
| 79 | 0 | Shl $element, $indexScale * $bitsPerByte; # Save the index of the character in the upper half of the register so that we know where the character came from. | |||||||||
| 80 | 0 | getLexicalCode $r, $start, $index; # Load lexical classification as lowest byte | |||||||||
| 81 | |||||||||||
| 82 | 0 | Cmp $r, $$Lex{bracketsBase}; # Brackets , due to their frequency, start after 0x10 with open even and close odd | |||||||||
| 83 | IfGe # Brackets | ||||||||||
| 84 | Then | ||||||||||
| 85 | 0 | ▶ | {And $r, 1 # Bracket: 0 - open, 1 - close | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 86 | }, | ||||||||||
| 87 | Else | ||||||||||
| 88 | 0 | ▶ | {Cmp $r, $Ascii; # Ascii is a type of variable | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 89 | IfEq | ||||||||||
| 90 | Then | ||||||||||
| 91 | 0 | ▶ | {Mov $r, $variable; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 92 | }, | ||||||||||
| 93 | Else | ||||||||||
| 94 | 0 | ▶ | {Cmp $r, $NewLineSemiColon; # New line semicolon is a type of semi colon | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 95 | IfEq | ||||||||||
| 96 | Then | ||||||||||
| 97 | 0 | ▶ | {Mov $r, $semiColon; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 98 | 0 | }; | |||||||||
| 99 | 0 | }; | |||||||||
| 100 | 0 | }; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | sub checkStackHas($) #P Check that we have at least the specified number of elements on the stack. | ||||||||||
| 104 | 0 | ▶ | {my ($depth) = @_; # Number of elements required on the stack | ||||||||
|
Subroutine
checkStackHas: not called CC=1 SCAR=6.9
| |||||||||||
| 105 | 0 | Mov $w1, $parseStackBase; | |||||||||
| 106 | 0 | Sub $w1, rsp; | |||||||||
| 107 | 0 | Cmp $w1, $ses * $depth; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | sub pushElement() #P Push the current element on to the stack. | ||||||||||
| 111 | 0 | ▶ | {Push $element; | ||||||||
|
Subroutine
pushElement: not called CC=2 SCAR=17.9
| |||||||||||
| 112 | 0 | ▶ | if ($debug) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | 0 | {PrintOutStringNL "Push Element:"; | |||||||||
| 114 | 0 | PrintOutRegisterInHex $element; | |||||||||
| 115 | } | ||||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | sub pushEmpty() #P Push the empty element on to the stack. | ||||||||||
| 119 | 0 | ▶ | {Mov $w1, $index; | ||||||||
|
Subroutine
pushEmpty: not called CC=2 SCAR=17.9
| |||||||||||
| 120 | 0 | Shl $w1, $indexScale * $bitsPerByte; | |||||||||
| 121 | 0 | Or $w1, $empty; | |||||||||
| 122 | 0 | Push $w1; | |||||||||
| 123 | 0 | ▶ | if ($debug) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | 0 | {PrintOutStringNL "Push Empty"; | |||||||||
| 125 | } | ||||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | sub lexicalNameFromLetter($) #P Lexical name for a lexical item described by its letter. | ||||||||||
| 129 | 0 | ▶ | {my ($l) = @_; # Letter of the lexical item | ||||||||
|
Subroutine
lexicalNameFromLetter: not called CC=2 SCAR=17.9
| |||||||||||
| 130 | 0 | my %l = $Lex->{treeTermLexicals}->%*; | |||||||||
| 131 | 0 | my $n = $l{$l}; | |||||||||
| 132 | 0 | ▶ | confess "No such lexical: $l" unless $n; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 133 | $n->{short} | ||||||||||
| 134 | 0 | } | |||||||||
| 135 | |||||||||||
| 136 | sub lexicalNumberFromLetter($) #P Lexical number for a lexical item described by its letter. | ||||||||||
| 137 | 0 | ▶ | {my ($l) = @_; # Letter of the lexical item | ||||||||
|
Subroutine
lexicalNumberFromLetter: not called CC=2 SCAR=17.9
| |||||||||||
| 138 | 0 | my $n = lexicalNameFromLetter $l; | |||||||||
| 139 | 0 | my $N = $Lex->{lexicals}{$n}{number}; | |||||||||
| 140 | 0 | ▶ | confess "No such lexical named: $n" unless defined $N; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | 0 | $N | |||||||||
| 142 | } | ||||||||||
| 143 | |||||||||||
| 144 | sub new2($$) #P Create a new term in the parse tree rooted on the stack. | ||||||||||
| 145 | {my ($depth, $description) = @_; # Stack depth to be converted, text reason why we are creating a new term | ||||||||||
| 146 | PrintOutStringNL "New: $description" if $debug; | ||||||||||
| 147 | |||||||||||
| 148 | my $t = $tree->bs->CreateTree; | ||||||||||
| 149 | my $d = V(data); | ||||||||||
| 150 | $t->insert(V(key, 0), V(data, $term)); # Create a term | ||||||||||
| 151 | $t->insert(V(key, 1), V(data, $depth)); # The number of elements in the term | ||||||||||
| 152 | |||||||||||
| 153 | for my $i(1..$depth) | ||||||||||
| 154 | {my $j = $depth + 1 - $i; | ||||||||||
| 155 | Pop $w1; | ||||||||||
| 156 | PrintOutRegisterInHex $w1 if $debug; | ||||||||||
| 157 | $d->getReg($w1); | ||||||||||
| 158 | $t->insert( V(key, 2 * $j ), $d); # The lexical type - which actually only takes 4 bits so this could be improved on. | ||||||||||
| 159 | |||||||||||
| 160 | Mov $w2, $w1; | ||||||||||
| 161 | Shr $w2, 32; # Offset in source | ||||||||||
| 162 | $d->getReg($w2); # Offset in source in lower dword | ||||||||||
| 163 | Cmp $w1."b", $term; # Check whether the lexical item on the stack is a term | ||||||||||
| 164 | |||||||||||
| 165 | |||||||||||
| 166 | IfEq | ||||||||||
| 167 | Then | ||||||||||
| 168 | {$t->insertTree(V(key, 2 * $j + 1), $d); # A reference to another term | ||||||||||
| 169 | }, | ||||||||||
| 170 | Else | ||||||||||
| 171 | {$t->insert (V(key, 2 * $j + 1), $d); # Offset in source | ||||||||||
| 172 | } | ||||||||||
| 173 | } | ||||||||||
| 174 | $t->first->setReg($w1); # Term | ||||||||||
| 175 | Shl $w1, 32; # Push offset to tree into the upper dword | ||||||||||
| 176 | Or $w1."b", $term; # Mark as a term tree | ||||||||||
| 177 | Push $w1; # Place simulated term on stack | ||||||||||
| 178 | } | ||||||||||
| 179 | |||||||||||
| 180 | sub new($$) #P Create a new term. | ||||||||||
| 181 | {my ($depth, $description) = @_; # Stack depth to be converted, text reason why we are creating a new term. | ||||||||||
| 182 | PrintOutStringNL "New: $description" if $debug; | ||||||||||
| 183 | |||||||||||
| 184 | if ($tree and $tree->bs) # Parse tree available | ||||||||||
| 185 | {new2($depth, $description); | ||||||||||
| 186 | } | ||||||||||
| 187 | else # Testing without building full parse tree | ||||||||||
| 188 | {for my $i(1..$depth) | ||||||||||
| 189 | {Pop $w1; | ||||||||||
| 190 | PrintOutRegisterInHex $w1 if $debug; | ||||||||||
| 191 | } | ||||||||||
| 192 | Mov $w1, $term; # Term | ||||||||||
| 193 | Push $w1; # Place simulated term on stack | ||||||||||
| 194 | } | ||||||||||
| 195 | } | ||||||||||
| 196 | |||||||||||
| 197 | sub error($) #P Die. | ||||||||||
| 198 | {my ($message) = @_; # Error message | ||||||||||
| 199 | PrintOutStringNL "Error: $message"; | ||||||||||
| 200 | PrintOutString "Element: "; | ||||||||||
| 201 | PrintOutRegisterInHex $element; | ||||||||||
| 202 | PrintOutString "Index : "; | ||||||||||
| 203 | PrintOutRegisterInHex $index; | ||||||||||
| 204 | Exit(0); | ||||||||||
| 205 | } | ||||||||||
| 206 | |||||||||||
| 207 | sub testSet($$) #P Test a set of items, setting the Zero Flag is one matches else clear the Zero flag. | ||||||||||
| 208 | {my ($set, $register) = @_; # Set of lexical letters, Register to test | ||||||||||
| 209 | my @n = map {sprintf("0x%x", lexicalNumberFromLetter $_)} split //, $set; # Each lexical item by number from letter | ||||||||||
| 210 | my $end = Label; | ||||||||||
| 211 | for my $n(@n) | ||||||||||
| 212 | {Cmp $register."b", $n; | ||||||||||
| 213 | Je $end | ||||||||||
| 214 | } | ||||||||||
| 215 | ClearZF; | ||||||||||
| 216 | SetLabel $end; | ||||||||||
| 217 | } | ||||||||||
| 218 | |||||||||||
| 219 | sub checkSet($) #P Check that one of a set of items is on the top of the stack or complain if it is not. | ||||||||||
| 220 | {my ($set) = @_; # Set of lexical letters | ||||||||||
| 221 | my @n = map {lexicalNumberFromLetter $_} split //, $set; | ||||||||||
| 222 | my $end = Label; | ||||||||||
| 223 | |||||||||||
| 224 | for my $n(@n) | ||||||||||
| 225 | {Cmp "byte[rsp]", $n; | ||||||||||
| 226 | Je $end | ||||||||||
| 227 | } | ||||||||||
| 228 | error("Expected one of: '$set' on the stack"); | ||||||||||
| 229 | ClearZF; | ||||||||||
| 230 | SetLabel $end; | ||||||||||
| 231 | } | ||||||||||
| 232 | |||||||||||
| 233 | sub reduce($) #P Convert the longest possible expression on top of the stack into a term at the specified priority. | ||||||||||
| 234 | {my ($priority) = @_; # Priority of the operators to reduce | ||||||||||
| 235 | $priority =~ m(\A(1|3)\Z); # Level: 1 - all operators, 2 - priority 2 operators | ||||||||||
| 236 | my ($success, $end) = map {Label} 1..2; # Exit points | ||||||||||
| 237 | |||||||||||
| 238 | checkStackHas 3; # At least three elements on the stack | ||||||||||
| 239 | IfGe | ||||||||||
| 240 | Then | ||||||||||
| 241 | {my ($l, $d, $r) = ($w1, $w2, $w3); | ||||||||||
| 242 | Mov $l, "[rsp+".(2*$ses)."]"; # Top 3 elements on the stack | ||||||||||
| 243 | Mov $d, "[rsp+".(1*$ses)."]"; | ||||||||||
| 244 | Mov $r, "[rsp+".(0*$ses)."]"; | ||||||||||
| 245 | |||||||||||
| 246 | if ($debug) | ||||||||||
| 247 | {PrintOutStringNL "Reduce 3:"; | ||||||||||
| 248 | PrintOutRegisterInHex $l, $d, $r; | ||||||||||
| 249 | } | ||||||||||
| 250 | |||||||||||
| 251 | testSet("t", $l); # Parse out infix operator expression | ||||||||||
| 252 | IfEq | ||||||||||
| 253 | Then | ||||||||||
| 254 | {testSet("t", $r); | ||||||||||
| 255 | IfEq | ||||||||||
| 256 | Then | ||||||||||
| 257 | {testSet($priority == 1 ? "ads" : 'd', $d); # Reduce all operators or just reduce infix priority 3 operators | ||||||||||
| 258 | IfEq | ||||||||||
| 259 | Then | ||||||||||
| 260 | {Add rsp, 3 * $ses; # Reorder into polish notation | ||||||||||
| 261 | Push $_ for $d, $l, $r; | ||||||||||
| 262 | new(3, "Term infix term"); | ||||||||||
| 263 | Jmp $success; | ||||||||||
| 264 | }; | ||||||||||
| 265 | }; | ||||||||||
| 266 | }; | ||||||||||
| 267 | |||||||||||
| 268 | testSet("b", $l); # Parse parenthesized term | ||||||||||
| 269 | IfEq | ||||||||||
| 270 | Then | ||||||||||
| 271 | {testSet("B", $r); | ||||||||||
| 272 | IfEq | ||||||||||
| 273 | Then | ||||||||||
| 274 | {testSet("t", $d); | ||||||||||
| 275 | IfEq | ||||||||||
| 276 | Then | ||||||||||
| 277 | {Add rsp, $ses; | ||||||||||
| 278 | new(1, "Bracketed term"); | ||||||||||
| 279 | new(2, "Brackets for term"); | ||||||||||
| 280 | PrintOutStringNL "Reduce by ( term )" if $debug; | ||||||||||
| 281 | Jmp $success; | ||||||||||
| 282 | }; | ||||||||||
| 283 | }; | ||||||||||
| 284 | }; | ||||||||||
| 285 | # KeepFree $l, $d, $r; | ||||||||||
| 286 | }; | ||||||||||
| 287 | |||||||||||
| 288 | checkStackHas 2; # At least two elements on the stack | ||||||||||
| 289 | IfGe # Convert an empty pair of parentheses to an empty term | ||||||||||
| 290 | Then | ||||||||||
| 291 | {my ($l, $r) = ($w1, $w2); | ||||||||||
| 292 | |||||||||||
| 293 | if ($debug) | ||||||||||
| 294 | {PrintOutStringNL "Reduce 2:"; | ||||||||||
| 295 | PrintOutRegisterInHex $l, $r; | ||||||||||
| 296 | } | ||||||||||
| 297 | |||||||||||
| 298 | # KeepFree $l, $r; # Why ? | ||||||||||
| 299 | Mov $l, "[rsp+".(1*$ses)."]"; # Top 3 elements on the stack | ||||||||||
| 300 | Mov $r, "[rsp+".(0*$ses)."]"; | ||||||||||
| 301 | testSet("b", $l); # Empty pair of parentheses | ||||||||||
| 302 | IfEq | ||||||||||
| 303 | Then | ||||||||||
| 304 | {testSet("B", $r); | ||||||||||
| 305 | IfEq | ||||||||||
| 306 | Then | ||||||||||
| 307 | {Add rsp, 2 * $ses; # Pop expression | ||||||||||
| 308 | Push $l; # Bracket as operator | ||||||||||
| 309 | new(1, "Empty brackets"); | ||||||||||
| 310 | Jmp $success; | ||||||||||
| 311 | }; | ||||||||||
| 312 | }; | ||||||||||
| 313 | testSet("s", $l); # Semi-colon, close implies remove unneeded semi | ||||||||||
| 314 | IfEq | ||||||||||
| 315 | Then | ||||||||||
| 316 | {testSet("B", $r); | ||||||||||
| 317 | IfEq | ||||||||||
| 318 | Then | ||||||||||
| 319 | {Add rsp, 2 * $ses; # Pop expression | ||||||||||
| 320 | Push $r; | ||||||||||
| 321 | PrintOutStringNL "Reduce by ;)" if $debug; | ||||||||||
| 322 | Jmp $success; | ||||||||||
| 323 | }; | ||||||||||
| 324 | }; | ||||||||||
| 325 | testSet("p", $l); # Prefix, term | ||||||||||
| 326 | IfEq | ||||||||||
| 327 | Then | ||||||||||
| 328 | {testSet("t", $r); | ||||||||||
| 329 | IfEq | ||||||||||
| 330 | Then | ||||||||||
| 331 | {new(2, "Prefix term"); | ||||||||||
| 332 | Jmp $success; | ||||||||||
| 333 | }; | ||||||||||
| 334 | }; | ||||||||||
| 335 | # KeepFree $l, $r; | ||||||||||
| 336 | }; | ||||||||||
| 337 | |||||||||||
| 338 | ClearZF; # Failed to match anything | ||||||||||
| 339 | Jmp $end; | ||||||||||
| 340 | |||||||||||
| 341 | SetLabel $success; # Successfully matched | ||||||||||
| 342 | SetZF; | ||||||||||
| 343 | |||||||||||
| 344 | SetLabel $end; # End | ||||||||||
| 345 | } # reduce | ||||||||||
| 346 | |||||||||||
| 347 | sub reduceMultiple($) #P Reduce existing operators on the stack. | ||||||||||
| 348 | {my ($priority) = @_; # Priority of the operators to reduce | ||||||||||
| 349 | K('count',99)->for(sub # An improbably high but finite number of reductions | ||||||||||
| 350 | {my ($index, $start, $next, $end) = @_; # Execute body | ||||||||||
| 351 | reduce($priority); | ||||||||||
| 352 | Jne $end; # Keep going as long as reductions are possible | ||||||||||
| 353 | }); | ||||||||||
| 354 | } | ||||||||||
| 355 | |||||||||||
| 356 | sub accept_a() #P Assign. | ||||||||||
| 357 | {checkSet("t"); | ||||||||||
| 358 | reduceMultiple 2; | ||||||||||
| 359 | PrintOutStringNL "accept a" if $debug; | ||||||||||
| 360 | pushElement; | ||||||||||
| 361 | } | ||||||||||
| 362 | |||||||||||
| 363 | sub accept_b #P Open. | ||||||||||
| 364 | {checkSet("abdps"); | ||||||||||
| 365 | PrintOutStringNL "accept b" if $debug; | ||||||||||
| 366 | pushElement; | ||||||||||
| 367 | } | ||||||||||
| 368 | |||||||||||
| 369 | sub accept_B #P Closing parenthesis. | ||||||||||
| 370 | {checkSet("bst"); | ||||||||||
| 371 | PrintOutStringNL "accept B" if $debug; | ||||||||||
| 372 | reduceMultiple 1; | ||||||||||
| 373 | pushElement; | ||||||||||
| 374 | reduceMultiple 1; | ||||||||||
| 375 | checkSet("bst"); | ||||||||||
| 376 | } | ||||||||||
| 377 | |||||||||||
| 378 | sub accept_d #P Infix but not assign or semi-colon. | ||||||||||
| 379 | {checkSet("t"); | ||||||||||
| 380 | PrintOutStringNL "accept d" if $debug; | ||||||||||
| 381 | pushElement; | ||||||||||
| 382 | } | ||||||||||
| 383 | |||||||||||
| 384 | sub accept_p #P Prefix. | ||||||||||
| 385 | {checkSet("abdps"); | ||||||||||
| 386 | PrintOutStringNL "accept p" if $debug; | ||||||||||
| 387 | pushElement; | ||||||||||
| 388 | } | ||||||||||
| 389 | |||||||||||
| 390 | sub accept_q #P Post fix. | ||||||||||
| 391 | {checkSet("t"); | ||||||||||
| 392 | PrintOutStringNL "accept q" if $debug; | ||||||||||
| 393 | IfEq # Post fix operator applied to a term | ||||||||||
| 394 | Then | ||||||||||
| 395 | {Pop $w1; | ||||||||||
| 396 | pushElement; | ||||||||||
| 397 | Push $w1; | ||||||||||
| 398 | new(2, "Postfix"); | ||||||||||
| 399 | } | ||||||||||
| 400 | } | ||||||||||
| 401 | |||||||||||
| 402 | sub accept_s #P Semi colon. | ||||||||||
| 403 | {checkSet("bst"); | ||||||||||
| 404 | PrintOutStringNL "accept s" if $debug; | ||||||||||
| 405 | Mov $w1, "[rsp]"; | ||||||||||
| 406 | testSet("s", $w1); | ||||||||||
| 407 | IfEq # Insert an empty element between two consecutive semicolons | ||||||||||
| 408 | Then | ||||||||||
| 409 | {pushEmpty; | ||||||||||
| 410 | }; | ||||||||||
| 411 | reduceMultiple 1; | ||||||||||
| 412 | pushElement; | ||||||||||
| 413 | } | ||||||||||
| 414 | |||||||||||
| 415 | sub accept_v #P Variable. | ||||||||||
| 416 | {checkSet("abdps"); | ||||||||||
| 417 | PrintOutStringNL "accept v" if $debug; | ||||||||||
| 418 | pushElement; | ||||||||||
| 419 | new(1, "Variable"); | ||||||||||
| 420 | V(count,99)->for(sub # Reduce prefix operators | ||||||||||
| 421 | {my ($index, $start, $next, $end) = @_; | ||||||||||
| 422 | checkStackHas 2; | ||||||||||
| 423 | Jl $end; | ||||||||||
| 424 | my ($l, $r) = ($w1, $w2); | ||||||||||
| 425 | Mov $l, "[rsp+".(1*$ses)."]"; | ||||||||||
| 426 | Mov $r, "[rsp+".(0*$ses)."]"; | ||||||||||
| 427 | testSet("p", $l); | ||||||||||
| 428 | Jne $end; | ||||||||||
| 429 | new(2, "Prefixed variable"); | ||||||||||
| 430 | }); | ||||||||||
| 431 | } | ||||||||||
| 432 | |||||||||||
| 433 | sub parseExpressionCode() #P Parse the string of classified lexical items addressed by register $start of length $length. The resulting parse tree (if any) is returned in r15. | ||||||||||
| 434 | {my $end = Label; | ||||||||||
| 435 | my $eb = $element."b"; # Contains a byte from the item being parsed | ||||||||||
| 436 | |||||||||||
| 437 | my $b = CreateArena; # Arena to hold parse tree | ||||||||||
| 438 | $tree = $b->CreateTree; # Root of parse tree | ||||||||||
| 439 | |||||||||||
| 440 | Cmp $size, 0; # Check for empty expression | ||||||||||
| 441 | Je $end; | ||||||||||
| 442 | |||||||||||
| 443 | loadCurrentChar; # Load current character | ||||||||||
| 444 | ### Need test for ignorable white space as first character | ||||||||||
| 445 | testSet($firstSet, $element); | ||||||||||
| 446 | IfNe | ||||||||||
| 447 | Then | ||||||||||
| 448 | {error(<<END =~ s(\n) ( )gsr); | ||||||||||
| 449 | Expression must start with 'opening parenthesis', 'prefix | ||||||||||
| 450 | operator', 'semi-colon' or 'variable'. | ||||||||||
| 451 | END | ||||||||||
| 452 | }; | ||||||||||
| 453 | |||||||||||
| 454 | testSet("v", $element); # Single variable | ||||||||||
| 455 | IfEq | ||||||||||
| 456 | Then | ||||||||||
| 457 | {pushElement; | ||||||||||
| 458 | new(1, "accept initial variable"); | ||||||||||
| 459 | }, | ||||||||||
| 460 | Else | ||||||||||
| 461 | {testSet("s", $element); # Semi | ||||||||||
| 462 | IfEq | ||||||||||
| 463 | Then | ||||||||||
| 464 | {pushEmpty; | ||||||||||
| 465 | new(1, "accept initial semicolon"); | ||||||||||
| 466 | }; | ||||||||||
| 467 | pushElement; | ||||||||||
| 468 | }; | ||||||||||
| 469 | |||||||||||
| 470 | Inc $index; # We have processed the first character above | ||||||||||
| 471 | Mov $prevChar, $element; # Initialize the previous lexical item | ||||||||||
| 472 | |||||||||||
| 473 | For # Parse each utf32 character after it has been classified | ||||||||||
| 474 | {my ($start, $end, $next) = @_; # Start and end of the classification loop | ||||||||||
| 475 | loadCurrentChar; # Load current character | ||||||||||
| 476 | |||||||||||
| 477 | PrintOutRegisterInHex $element if $debug; | ||||||||||
| 478 | |||||||||||
| 479 | Cmp $eb, $WhiteSpace; | ||||||||||
| 480 | Je $next; # Ignore white space | ||||||||||
| 481 | |||||||||||
| 482 | Cmp $eb, 1; # Brackets are singular but everything else can potential be a plurality | ||||||||||
| 483 | IfGt | ||||||||||
| 484 | Then | ||||||||||
| 485 | {Cmp $prevChar."b", $eb; # Compare with previous element known not to be white space or a bracket | ||||||||||
| 486 | Je $next | ||||||||||
| 487 | }; | ||||||||||
| 488 | Mov $prevChar, $element; # Save element to previous element now we know we are on a different element | ||||||||||
| 489 | |||||||||||
| 490 | for my $l(sort keys $Lex->{lexicals}->%*) # Each possible lexical item after classification | ||||||||||
| 491 | {my $x = $Lex->{lexicals}{$l}{letter}; | ||||||||||
| 492 | next unless $x; # Skip characters that do not have a letter defined for Tree::Term because the lexical items needed to layout a file of lexical items are folded down to the actual lexical items required to represent the language independent of the textual layout with white space. | ||||||||||
| 493 | |||||||||||
| 494 | my $n = $Lex->{lexicals}{$l}{number}; | ||||||||||
| 495 | Comment "Compare to $n for $l"; | ||||||||||
| 496 | Cmp $eb, $n; | ||||||||||
| 497 | |||||||||||
| 498 | IfEq | ||||||||||
| 499 | Then | ||||||||||
| 500 | {eval "accept_$x"; | ||||||||||
| 501 | Jmp $next | ||||||||||
| 502 | }; | ||||||||||
| 503 | } | ||||||||||
| 504 | error("Unexpected lexical item"); # Not selected | ||||||||||
| 505 | } $index, $size; | ||||||||||
| 506 | |||||||||||
| 507 | testSet($lastSet, $prevChar); # Last lexical element | ||||||||||
| 508 | IfNe # Incomplete expression | ||||||||||
| 509 | Then | ||||||||||
| 510 | {error("Incomplete expression"); | ||||||||||
| 511 | }; | ||||||||||
| 512 | |||||||||||
| 513 | K('count', 99)->for(sub # Remove trailing semicolons if present | ||||||||||
| 514 | {my ($index, $start, $next, $end) = @_; # Execute body | ||||||||||
| 515 | checkStackHas 2; | ||||||||||
| 516 | Jl $end; # Does not have two or more elements | ||||||||||
| 517 | Pop $w1; | ||||||||||
| 518 | testSet("s", $w1); # Check that the top most element is a semi colon | ||||||||||
| 519 | IfNe # Not a semi colon so put it back and finish the loop | ||||||||||
| 520 | Then | ||||||||||
| 521 | {Push $w1; | ||||||||||
| 522 | Jmp $end; | ||||||||||
| 523 | }; | ||||||||||
| 524 | }); | ||||||||||
| 525 | |||||||||||
| 526 | reduceMultiple 1; # Final reductions | ||||||||||
| 527 | |||||||||||
| 528 | checkStackHas 1; | ||||||||||
| 529 | IfNe # Incomplete expression | ||||||||||
| 530 | Then | ||||||||||
| 531 | {error("Multiple expressions on stack"); | ||||||||||
| 532 | }; | ||||||||||
| 533 | |||||||||||
| 534 | Pop r15; # The resulting parse tree | ||||||||||
| 535 | SetLabel $end; | ||||||||||
| 536 | } # parseExpressionCode | ||||||||||
| 537 | |||||||||||
| 538 | sub parseExpression(@) #P Create a parser for an expression described by variables. | ||||||||||
| 539 | {my (@parameters) = @_; # Parameters describing expression | ||||||||||
| 540 | |||||||||||
| 541 | my $s = Subroutine | ||||||||||
| 542 | {my ($p) = @_; # Parameters | ||||||||||
| 543 | PushR $parseStackBase, map {"r$_"} 8..15; | ||||||||||
| 544 | $$p{source}->setReg($start); # Start of expression string after it has been classified | ||||||||||
| 545 | $$p{size} ->setReg($size); # Number of characters in the expression | ||||||||||
| 546 | |||||||||||
| 547 | Mov $parseStackBase, rsp; # Set base of parse stack | ||||||||||
| 548 | |||||||||||
| 549 | parseExpressionCode; | ||||||||||
| 550 | $$p{parse}->getReg(r15); # Number of characters in the expression | ||||||||||
| 551 | |||||||||||
| 552 | Mov rsp, $parseStackBase; # Remove parse stack | ||||||||||
| 553 | # Remove new frame | ||||||||||
| 554 | PopR; | ||||||||||
| 555 | } [qw(source size parse)], name => q(Unisyn::Parse::parse); | ||||||||||
| 556 | |||||||||||
| 557 | |||||||||||
| 558 | $s->call(@parameters); | ||||||||||
| 559 | } # parse | ||||||||||
| 560 | |||||||||||
| 561 | sub MatchBrackets(@) #P Replace the low three bytes of a utf32 bracket character with 24 bits of offset to the matching opening or closing bracket. Opening brackets have even codes from 0x10 to 0x4e while the corresponding closing bracket has a code one higher. | ||||||||||
| 562 | {my (@parameters) = @_; # Parameters | ||||||||||
| 563 | @_ >= 1 or confess; | ||||||||||
| 564 | |||||||||||
| 565 | my $s = Subroutine | ||||||||||
| 566 | {my ($p) = @_; # Parameters | ||||||||||
| 567 | Comment "Match brackets in utf32 text"; | ||||||||||
| 568 | |||||||||||
| 569 | my $finish = Label; | ||||||||||
| 570 | PushR xmm0, k7, r10, r11, r12, r13, r14, r15, rsi; # R15 current character address. r14 is the current classification. r13 the last classification code. r12 the stack depth. r11 the number of opening brackets found. r10 address of first utf32 character. | ||||||||||
| 571 | |||||||||||
| 572 | Mov rsi, rsp; # Save stack location so we can use the stack to record the brackets we have found | ||||||||||
| 573 | ClearRegisters r11, r12, r15; # Count the number of brackets and track the stack depth, index of each character | ||||||||||
| 574 | K(three, 3)->setMaskFirst(k7); # These are the number of bytes that we are going to use for the offsets of brackets which limits the size of a program to 24 million utf32 characters | ||||||||||
| 575 | $$p{fail} ->getReg(r11); # Clear failure indicator | ||||||||||
| 576 | $$p{opens} ->getReg(r11); # Clear count of opens | ||||||||||
| 577 | $$p{address}->setReg(r10); # Address of first utf32 character | ||||||||||
| 578 | my $w = RegisterSize eax; # Size of a utf32 character | ||||||||||
| 579 | |||||||||||
| 580 | $$p{size}->for(sub # Process each utf32 character in the block of memory | ||||||||||
| 581 | {my ($index, $start, $next, $end) = @_; | ||||||||||
| 582 | my $continue = Label; | ||||||||||
| 583 | |||||||||||
| 584 | Mov r14b, "[r10+$w*r15+3]"; # Classification character | ||||||||||
| 585 | |||||||||||
| 586 | Cmp r14, 0x10; # First bracket | ||||||||||
| 587 | Jl $continue; # Less than first bracket | ||||||||||
| 588 | Cmp r14, 0x4f; # Last bracket | ||||||||||
| 589 | Jg $continue; # Greater than last bracket | ||||||||||
| 590 | |||||||||||
| 591 | Test r14, 1; # Zero means that the bracket is an opener | ||||||||||
| 592 | IfZ sub # Save an opener then continue | ||||||||||
| 593 | {Push r15; # Save position in input | ||||||||||
| 594 | Push r14; # Save opening code | ||||||||||
| 595 | Inc r11; # Count number of opening brackets | ||||||||||
| 596 | Inc r12; # Number of brackets currently open | ||||||||||
| 597 | Jmp $continue; | ||||||||||
| 598 | }; | ||||||||||
| 599 | Cmp r12, 1; # Check that there is a bracket to match on the stack | ||||||||||
| 600 | IfLt sub # Nothing on stack | ||||||||||
| 601 | {Not r15; # Minus the offset at which the error occurred so that we can fail at zero | ||||||||||
| 602 | $$p{fail}->getReg(r15); # Position in input that caused the failure | ||||||||||
| 603 | Jmp $finish; # Return | ||||||||||
| 604 | }; | ||||||||||
| 605 | Mov r13, "[rsp]"; # Peek at the opening bracket code which is on top of the stack | ||||||||||
| 606 | Inc r13; # Expected closing bracket | ||||||||||
| 607 | Cmp r13, r14; # Check for match | ||||||||||
| 608 | IfNe sub # Mismatch | ||||||||||
| 609 | {Not r15; # Minus the offset at which the error occurred so that we can fail at zero | ||||||||||
| 610 | $$p{fail}->getReg(r15); # Position in input that caused the failure | ||||||||||
| 611 | Jmp $finish; # Return | ||||||||||
| 612 | }; | ||||||||||
| 613 | Pop r13; # The closing bracket matches the opening bracket | ||||||||||
| 614 | Pop r13; # Offset of opener | ||||||||||
| 615 | Dec r12; # Close off bracket sequence | ||||||||||
| 616 | Vpbroadcastq xmm0, r15; # Load offset of opener | ||||||||||
| 617 | Vmovdqu8 "[r10+$w*r13]\{k7}", xmm0; # Save offset of opener in the code for the closer - the classification is left intact so we still know what kind of bracket we have | ||||||||||
| 618 | Vpbroadcastq xmm0, r13; # Load offset of opener | ||||||||||
| 619 | Vmovdqu8 "[r10+$w*r15]\{k7}", xmm0; # Save offset of closer in the code for the openercloser - the classification is left intact so we still know what kind of bracket we have | ||||||||||
| 620 | SetLabel $continue; # Continue with next character | ||||||||||
| 621 | Inc r15; # Next character | ||||||||||
| 622 | }); | ||||||||||
| 623 | |||||||||||
| 624 | SetLabel $finish; | ||||||||||
| 625 | Mov rsp, rsi; # Restore stack | ||||||||||
| 626 | $$p{opens}->getReg(r11); # Number of brackets opened | ||||||||||
| 627 | PopR; | ||||||||||
| 628 | } [qw(address size fail opens)], name => q(Unisyn::Parse::MatchBrackets); | ||||||||||
| 629 | |||||||||||
| 630 | $s->call(@parameters); | ||||||||||
| 631 | } # MatchBrackets | ||||||||||
| 632 | |||||||||||
| 633 | sub ClassifyNewLines(@) #P Scan input string looking for opportunities to convert new lines into semi colons. | ||||||||||
| 634 | {my (@parameters) = @_; # Parameters | ||||||||||
| 635 | @_ >= 1 or confess; | ||||||||||
| 636 | |||||||||||
| 637 | my $s = Subroutine | ||||||||||
| 638 | {my ($p) = @_; # Parameters | ||||||||||
| 639 | my $current = r15; # Index of the current character | ||||||||||
| 640 | my $middle = r14; # Index of the middle character | ||||||||||
| 641 | my $first = r13; # Index of the first character | ||||||||||
| 642 | my $address = r12; # Address of input string | ||||||||||
| 643 | my $size = r11; # Length of input utf32 string | ||||||||||
| 644 | my($c1, $c2) = (r8."b", r9."b"); # Lexical codes being tested | ||||||||||
| 645 | |||||||||||
| 646 | PushR r8, r9, r10, r11, r12, r13, r14, r15; | ||||||||||
| 647 | |||||||||||
| 648 | $$p{address}->setReg($address); # Address of string | ||||||||||
| 649 | $$p{size} ->setReg($size); # Size of string | ||||||||||
| 650 | Mov $current, 2; Mov $middle, 1; Mov $first, 0; | ||||||||||
| 651 | |||||||||||
| 652 | For # Each character in input string | ||||||||||
| 653 | {my ($start, $end, $next) = @_; # Start, end and next labels | ||||||||||
| 654 | |||||||||||
| 655 | |||||||||||
| 656 | getLexicalCode $c1, $address, $middle; # Lexical code of the middle character | ||||||||||
| 657 | Cmp $c1, $WhiteSpace; | ||||||||||
| 658 | IfEq | ||||||||||
| 659 | Then | ||||||||||
| 660 | {getAlpha $c1, $address, $middle; | ||||||||||
| 661 | |||||||||||
| 662 | Cmp $c1, $asciiNewLine; | ||||||||||
| 663 | IfEq # Middle character is a insignificant new line and thus could be a semicolon | ||||||||||
| 664 | Then | ||||||||||
| 665 | {getLexicalCode $c1, $address, $first; | ||||||||||
| 666 | |||||||||||
| 667 | my sub makeSemiColon # Make a new line into a new line semicolon | ||||||||||
| 668 | {putLexicalCode $c2, $address, $middle, $NewLineSemiColon; | ||||||||||
| 669 | } | ||||||||||
| 670 | |||||||||||
| 671 | my sub check_bpv # Make new line if followed by 'b', 'p' or 'v' | ||||||||||
| 672 | {getLexicalCode $c1, $address, $current; | ||||||||||
| 673 | Cmp $c1, $OpenBracket; | ||||||||||
| 674 | |||||||||||
| 675 | IfEq | ||||||||||
| 676 | Then | ||||||||||
| 677 | {makeSemiColon; | ||||||||||
| 678 | }, | ||||||||||
| 679 | Else | ||||||||||
| 680 | {Cmp $c1, $prefix; | ||||||||||
| 681 | IfEq | ||||||||||
| 682 | Then | ||||||||||
| 683 | {makeSemiColon; | ||||||||||
| 684 | }, | ||||||||||
| 685 | Else | ||||||||||
| 686 | {Cmp $c1, $variable; | ||||||||||
| 687 | IfEq | ||||||||||
| 688 | Then | ||||||||||
| 689 | {makeSemiColon; | ||||||||||
| 690 | }; | ||||||||||
| 691 | }; | ||||||||||
| 692 | }; | ||||||||||
| 693 | } | ||||||||||
| 694 | |||||||||||
| 695 | Cmp $c1, $CloseBracket; # Check first character of sequence | ||||||||||
| 696 | IfEq | ||||||||||
| 697 | Then | ||||||||||
| 698 | {check_bpv; | ||||||||||
| 699 | }, | ||||||||||
| 700 | Else | ||||||||||
| 701 | {Cmp $c1, $suffix; | ||||||||||
| 702 | IfEq | ||||||||||
| 703 | Then | ||||||||||
| 704 | {check_bpv; | ||||||||||
| 705 | }, | ||||||||||
| 706 | Else | ||||||||||
| 707 | {Cmp $c1, $variable; | ||||||||||
| 708 | IfEq | ||||||||||
| 709 | Then | ||||||||||
| 710 | {check_bpv; | ||||||||||
| 711 | }; | ||||||||||
| 712 | }; | ||||||||||
| 713 | }; | ||||||||||
| 714 | }; | ||||||||||
| 715 | }; | ||||||||||
| 716 | |||||||||||
| 717 | Mov $first, $middle; Mov $middle, $current; # Find next lexical item | ||||||||||
| 718 | getLexicalCode $c1, $address, $current; # Current lexical code | ||||||||||
| 719 | Mov $middle, $current; | ||||||||||
| 720 | Inc $current; # Next possible character | ||||||||||
| 721 | For | ||||||||||
| 722 | {my ($start, $end, $next) = @_; | ||||||||||
| 723 | getLexicalCode $c2, $address, $current; # Lexical code of next character | ||||||||||
| 724 | Cmp $c1, $c2; | ||||||||||
| 725 | Jne $end; # Terminate when we are in a different lexical item | ||||||||||
| 726 | } $current, $size; | ||||||||||
| 727 | } $current, $size; | ||||||||||
| 728 | |||||||||||
| 729 | PopR; | ||||||||||
| 730 | } [qw(address size)], name => q(Unisyn::Parse::ClassifyNewLines); | ||||||||||
| 731 | |||||||||||
| 732 | $s->call(@parameters); | ||||||||||
| 733 | } # ClassifyNewLines | ||||||||||
| 734 | |||||||||||
| 735 | sub ClassifyWhiteSpace(@) #P Classify white space per: "lib/Unisyn/whiteSpace/whiteSpaceClassification.pl". | ||||||||||
| 736 | {my (@parameters) = @_; # Parameters | ||||||||||
| 737 | @_ >= 1 or confess; | ||||||||||
| 738 | |||||||||||
| 739 | my $s = Subroutine | ||||||||||
| 740 | {my ($p) = @_; # Parameters | ||||||||||
| 741 | my $eb = r15."b"; # Lexical type of current char | ||||||||||
| 742 | my $s = r14; # State of white space between 'a' | ||||||||||
| 743 | my $S = r13; # State of white space before 'a' | ||||||||||
| 744 | my $cb = r12."b"; # Actual character within alphabet | ||||||||||
| 745 | my $address = r11; # Address of input string | ||||||||||
| 746 | my $index = r10; # Index of current char | ||||||||||
| 747 | my ($w1, $w2) = (r8."b", r9."b"); # Temporary work registers | ||||||||||
| 748 | |||||||||||
| 749 | my sub getAlpha($;$) # Load the position of a lexical item in its alphabet from the current character | ||||||||||
| 750 | {my ($register, $indexReg) = @_; # Register to load, optional index register | ||||||||||
| 751 | getAlpha $register, $address, $index // $indexReg # Supplied index or default | ||||||||||
| 752 | }; | ||||||||||
| 753 | |||||||||||
| 754 | my sub getLexicalCode() # Load the lexical code of the current character in memory into the current character | ||||||||||
| 755 | {getLexicalCode $eb, $address, $index; # Supplied index or default | ||||||||||
| 756 | }; | ||||||||||
| 757 | |||||||||||
| 758 | my sub putLexicalCode($;$) # Put the specified lexical code into the current character in memory. | ||||||||||
| 759 | {my ($code, $indexReg) = @_; # Code, optional index register | ||||||||||
| 760 | putLexicalCode $w1, $address, ($indexReg//$index), $code; | ||||||||||
| 761 | }; | ||||||||||
| 762 | |||||||||||
| 763 | PushR r8, r9, r10, r11, r12, r13, r14, r15; | ||||||||||
| 764 | |||||||||||
| 765 | $$p{address}->setReg($address); # Address of string | ||||||||||
| 766 | Mov $s, -1; Mov $S, -1; Mov $index, 0; # Initial states, position | ||||||||||
| 767 | |||||||||||
| 768 | $$p{size}->for(sub # Each character in expression | ||||||||||
| 769 | {my ($indexVariable, $start, $next, $end) = @_; | ||||||||||
| 770 | |||||||||||
| 771 | $indexVariable->setReg($index); | ||||||||||
| 772 | getLexicalCode; # Current lexical code | ||||||||||
| 773 | |||||||||||
| 774 | Block # Trap space before new line and detect new line after ascii | ||||||||||
| 775 | {my ($start, $end) = @_; | ||||||||||
| 776 | Cmp $index, 0; Je $end; # Start beyond the first character so we can look back one character. | ||||||||||
| 777 | Cmp $eb, $Ascii; Jne $end; # Current is ascii | ||||||||||
| 778 | |||||||||||
| 779 | Mov $w1, "[$address+$indexScale*$index-$indexScale+$lexCodeOffset]"; # Previous lexical code | ||||||||||
| 780 | Cmp $w1, $Ascii; Jne $end; # Previous is ascii | ||||||||||
| 781 | |||||||||||
| 782 | if (1) # Check for 's' followed by 'n' and 'a' followed by 'n' | ||||||||||
| 783 | {Mov $w1, "[$address+$indexScale*$index-$indexScale]"; # Previous character | ||||||||||
| 784 | getAlpha $w2; # Current character | ||||||||||
| 785 | |||||||||||
| 786 | Cmp $w1, $asciiSpace; # Check for space followed by new line | ||||||||||
| 787 | IfEq | ||||||||||
| 788 | Then | ||||||||||
| 789 | {Cmp $w2, $asciiNewLine; | ||||||||||
| 790 | IfEq # Disallow 's' followed by 'n' | ||||||||||
| 791 | Then | ||||||||||
| 792 | {PrintErrStringNL "Space detected before new line at index:"; | ||||||||||
| 793 | PrintErrRegisterInHex $index; | ||||||||||
| 794 | PrintErrTraceBack; | ||||||||||
| 795 | Exit(1); | ||||||||||
| 796 | }; | ||||||||||
| 797 | }; | ||||||||||
| 798 | |||||||||||
| 799 | Cmp $w1, $asciiSpace; Je $end; # Check for 'a' followed by 'n' | ||||||||||
| 800 | Cmp $w1, $asciiNewLine; Je $end; # Current is 'a' but not 'n' or 's' | ||||||||||
| 801 | Cmp $w2, $asciiNewLine; Jne $end; # Current is 'n' | ||||||||||
| 802 | |||||||||||
| 803 | putLexicalCode $WhiteSpace; # Mark new line as significant | ||||||||||
| 804 | } | ||||||||||
| 805 | }; | ||||||||||
| 806 | |||||||||||
| 807 | Block # Spaces and new lines between other ascii | ||||||||||
| 808 | {my ($start, $end) = @_; | ||||||||||
| 809 | Cmp $s, -1; | ||||||||||
| 810 | IfEq # Looking for opening ascii | ||||||||||
| 811 | Then | ||||||||||
| 812 | {Cmp $eb, $Ascii; Jne $end; # Not ascii | ||||||||||
| 813 | getAlpha $cb; # Current character | ||||||||||
| 814 | Cmp $cb, $asciiNewLine; Je $end; # Skip over new lines | ||||||||||
| 815 | Cmp $cb, $asciiSpace; Je $end; # Skip over spaces | ||||||||||
| 816 | IfEq | ||||||||||
| 817 | Then | ||||||||||
| 818 | {Mov $s, $index; Inc $s; # Ascii not space nor new line | ||||||||||
| 819 | }; | ||||||||||
| 820 | Jmp $end; | ||||||||||
| 821 | }, | ||||||||||
| 822 | Else # Looking for closing ascii | ||||||||||
| 823 | {Cmp $eb, $Ascii; | ||||||||||
| 824 | IfNe # Not ascii | ||||||||||
| 825 | Then | ||||||||||
| 826 | {Mov $s, -1; | ||||||||||
| 827 | Jmp $end | ||||||||||
| 828 | }; | ||||||||||
| 829 | getAlpha $cb; # Current character | ||||||||||
| 830 | Cmp $cb, $asciiNewLine; Je $end; # Skip over new lines | ||||||||||
| 831 | Cmp $cb, $asciiSpace; Je $end; # Skip over spaces | ||||||||||
| 832 | |||||||||||
| 833 | For # Move over spaces and new lines between two ascii characters that are neither of new line or space | ||||||||||
| 834 | {my ($start, $end, $next) = @_; | ||||||||||
| 835 | getAlpha $cb, $s; # Check for 's' or 'n' | ||||||||||
| 836 | Cmp $cb, $asciiSpace; | ||||||||||
| 837 | IfEq | ||||||||||
| 838 | Then | ||||||||||
| 839 | {putLexicalCode $WhiteSpace, $s; # Mark as significant white space. | ||||||||||
| 840 | Jmp $next; | ||||||||||
| 841 | }; | ||||||||||
| 842 | Cmp $cb, $asciiNewLine; | ||||||||||
| 843 | IfEq | ||||||||||
| 844 | Then | ||||||||||
| 845 | {putLexicalCode $WhiteSpace; # Mark as significant new line | ||||||||||
| 846 | Jmp $next; | ||||||||||
| 847 | }; | ||||||||||
| 848 | } $s, $index; | ||||||||||
| 849 | |||||||||||
| 850 | Mov $s, $index; Inc $s; | ||||||||||
| 851 | }; | ||||||||||
| 852 | }; | ||||||||||
| 853 | |||||||||||
| 854 | Block # Note: 's' preceding 'a' are significant | ||||||||||
| 855 | {my ($start, $end) = @_; | ||||||||||
| 856 | Cmp $S, -1; | ||||||||||
| 857 | IfEq # Looking for 's' | ||||||||||
| 858 | Then | ||||||||||
| 859 | {Cmp $eb, $Ascii; # Not 'a' | ||||||||||
| 860 | IfNe | ||||||||||
| 861 | Then | ||||||||||
| 862 | {Mov $S, -1; | ||||||||||
| 863 | Jmp $end | ||||||||||
| 864 | }; | ||||||||||
| 865 | getAlpha $cb; # Actual character in alphabet | ||||||||||
| 866 | Cmp $cb, $asciiSpace; # Space | ||||||||||
| 867 | IfEq | ||||||||||
| 868 | Then | ||||||||||
| 869 | {Mov $S, $index; | ||||||||||
| 870 | Jmp $end; | ||||||||||
| 871 | }; | ||||||||||
| 872 | }, | ||||||||||
| 873 | Else # Looking for 'a' | ||||||||||
| 874 | {Cmp $eb, $Ascii; # Not 'a' | ||||||||||
| 875 | IfNe | ||||||||||
| 876 | Then | ||||||||||
| 877 | {Mov $S, -1; | ||||||||||
| 878 | Jmp $end | ||||||||||
| 879 | }; | ||||||||||
| 880 | getAlpha $cb; # Actual character in alphabet | ||||||||||
| 881 | Cmp $cb, $asciiSpace; Je $end; # Skip 's' | ||||||||||
| 882 | |||||||||||
| 883 | Cmp $cb, $asciiNewLine; | ||||||||||
| 884 | IfEq # New lines prevent 's' from preceding 'a' | ||||||||||
| 885 | Then | ||||||||||
| 886 | {Mov $s, -1; | ||||||||||
| 887 | Jmp $end | ||||||||||
| 888 | }; | ||||||||||
| 889 | |||||||||||
| 890 | For # Move over spaces to non space ascii | ||||||||||
| 891 | {my ($start, $end, $next) = @_; | ||||||||||
| 892 | putLexicalCode $WhiteSpace, $S; # Mark new line as significant | ||||||||||
| 893 | } $S, $index; | ||||||||||
| 894 | Mov $S, -1; # Look for next possible space | ||||||||||
| 895 | } | ||||||||||
| 896 | }; | ||||||||||
| 897 | }); | ||||||||||
| 898 | |||||||||||
| 899 | $$p{size}->for(sub # Invert white space so that significant white space becomes ascii and the remainder is ignored | ||||||||||
| 900 | {my ($indexVariable, $start, $next, $end) = @_; | ||||||||||
| 901 | |||||||||||
| 902 | $indexVariable->setReg($index); | ||||||||||
| 903 | getLexicalCode; # Current lexical code | ||||||||||
| 904 | |||||||||||
| 905 | Block # Invert non significant white space | ||||||||||
| 906 | {my ($start, $end) = @_; | ||||||||||
| 907 | Cmp $eb, $Ascii; | ||||||||||
| 908 | Jne $end; # Ascii | ||||||||||
| 909 | |||||||||||
| 910 | getAlpha $cb; # Actual character in alphabet | ||||||||||
| 911 | Cmp $cb, $asciiSpace; | ||||||||||
| 912 | IfEq | ||||||||||
| 913 | Then | ||||||||||
| 914 | {putLexicalCode $WhiteSpace; | ||||||||||
| 915 | Jmp $next; | ||||||||||
| 916 | }; | ||||||||||
| 917 | Cmp $cb, $asciiNewLine; | ||||||||||
| 918 | IfEq | ||||||||||
| 919 | Then | ||||||||||
| 920 | {putLexicalCode $WhiteSpace; # Mark new line as not significant | ||||||||||
| 921 | Jmp $next; | ||||||||||
| 922 | }; | ||||||||||
| 923 | }; | ||||||||||
| 924 | |||||||||||
| 925 | Block # Mark significant white space | ||||||||||
| 926 | {my ($start, $end) = @_; | ||||||||||
| 927 | Cmp $eb, $WhiteSpace; Jne $end; # Not significant white space | ||||||||||
| 928 | putLexicalCode $Ascii; # Mark as ascii | ||||||||||
| 929 | }; | ||||||||||
| 930 | }); | ||||||||||
| 931 | |||||||||||
| 932 | PopR; | ||||||||||
| 933 | } [qw(address size)], name => q(Unisyn::Parse::ClassifyWhiteSpace); | ||||||||||
| 934 | |||||||||||
| 935 | $s->call(@parameters); | ||||||||||
| 936 | } # ClassifyWhiteSpace | ||||||||||
| 937 | |||||||||||
| 938 | sub parseUtf8(@) # Parse a unisyn expression encoded as utf8. | ||||||||||
| 939 | {my (@parameters) = @_; # Parameters | ||||||||||
| 940 | @_ >= 1 or confess; | ||||||||||
| 941 | |||||||||||
| 942 | my $s = Subroutine | ||||||||||
| 943 | {my ($p) = @_; # Parameters | ||||||||||
| 944 | |||||||||||
| 945 | PrintOutStringNL "ParseUtf8" if $debug; | ||||||||||
| 946 | |||||||||||
| 947 | PushR zmm0, zmm1; | ||||||||||
| 948 | |||||||||||
| 949 | my $source32 = V(u32), | ||||||||||
| 950 | my $sourceSize32 = V(size32); | ||||||||||
| 951 | my $sourceLength32 = V(count); | ||||||||||
| 952 | ConvertUtf8ToUtf32 u8 => $$p{address}, size8 => $$p{size}, # Convert to utf32 | ||||||||||
| 953 | $source32, $sourceSize32, $sourceLength32; | ||||||||||
| 954 | |||||||||||
| 955 | if ($debug) | ||||||||||
| 956 | {PrintOutStringNL "After conversion from utf8 to utf32"; | ||||||||||
| 957 | $sourceSize32 ->outNL("Output Length: "); # Write output length | ||||||||||
| 958 | PrintUtf32($sourceLength32, $source32); # Print utf32 | ||||||||||
| 959 | } | ||||||||||
| 960 | |||||||||||
| 961 | Vmovdqu8 zmm0, "[".Rd(join ', ', $Lex->{lexicalLow} ->@*)."]"; # Each double is [31::24] Classification, [21::0] Utf32 start character | ||||||||||
| 962 | Vmovdqu8 zmm1, "[".Rd(join ', ', $Lex->{lexicalHigh}->@*)."]"; # Each double is [31::24] Range offset, [21::0] Utf32 end character | ||||||||||
| 963 | |||||||||||
| 964 | ClassifyWithInRangeAndSaveOffset address=>$source32, size=>$sourceLength32; # Alphabetic classification | ||||||||||
| 965 | if ($debug) | ||||||||||
| 966 | {PrintOutStringNL "After classification into alphabet ranges"; | ||||||||||
| 967 | PrintUtf32($sourceLength32, $source32); # Print classified utf32 | ||||||||||
| 968 | } | ||||||||||
| 969 | |||||||||||
| 970 | Vmovdqu8 zmm0, "[".Rd(join ', ', $Lex->{bracketsLow} ->@*)."]"; # Each double is [31::24] Classification, [21::0] Utf32 start character | ||||||||||
| 971 | Vmovdqu8 zmm1, "[".Rd(join ', ', $Lex->{bracketsHigh}->@*)."]"; # Each double is [31::24] Range offset, [21::0] Utf32 end character | ||||||||||
| 972 | |||||||||||
| 973 | ClassifyWithInRange address=>$source32, size=>$sourceLength32; # Bracket classification | ||||||||||
| 974 | if ($debug) | ||||||||||
| 975 | {PrintOutStringNL "After classification into brackets"; | ||||||||||
| 976 | PrintUtf32($sourceLength32, $source32); # Print classified brackets | ||||||||||
| 977 | } | ||||||||||
| 978 | |||||||||||
| 979 | my $opens = V(opens, -1); | ||||||||||
| 980 | MatchBrackets address=>$source32, size=>$sourceLength32, $opens, $$p{fail}; # Match brackets | ||||||||||
| 981 | if ($debug) | ||||||||||
| 982 | {PrintOutStringNL "After bracket matching"; | ||||||||||
| 983 | PrintUtf32($sourceLength32, $source32); # Print matched brackets | ||||||||||
| 984 | } | ||||||||||
| 985 | |||||||||||
| 986 | ClassifyWhiteSpace address=>$source32, size=>$sourceLength32; # Classify white space | ||||||||||
| 987 | if ($debug) | ||||||||||
| 988 | {PrintOutStringNL "After white space classification"; | ||||||||||
| 989 | PrintUtf32($sourceLength32, $source32); | ||||||||||
| 990 | } | ||||||||||
| 991 | |||||||||||
| 992 | ClassifyNewLines address=>$source32, size=>$sourceLength32; # Classify new lines | ||||||||||
| 993 | if ($debug) | ||||||||||
| 994 | {PrintOutStringNL "After classifying new lines"; | ||||||||||
| 995 | PrintUtf32($sourceLength32, $source32); | ||||||||||
| 996 | } | ||||||||||
| 997 | |||||||||||
| 998 | parseExpression source=>$source32, size=>$sourceLength32, $$p{parse}; | ||||||||||
| 999 | |||||||||||
| 1000 | $$p{parse}->outNL if $debug; | ||||||||||
| 1001 | |||||||||||
| 1002 | PopR; | ||||||||||
| 1003 | } [qw(address size parse fail)], name => q(Unisyn::Parse::parseUtf8); | ||||||||||
| 1004 | |||||||||||
| 1005 | $s->call(@parameters); | ||||||||||
| 1006 | } # parseUtf8 | ||||||||||
| 1007 | |||||||||||
| 1008 | #d | ||||||||||
| 1009 | sub lexicalData {do { | ||||||||||
| 1010 | my $a = bless({ | ||||||||||
| 1011 | alphabetRanges => 13, | ||||||||||
| 1012 | alphabets => { | ||||||||||
| 1013 | "circledLatinLetter" => "\x{24B6}\x{24B7}\x{24B8}\x{24B9}\x{24BA}\x{24BB}\x{24BC}\x{24BD}\x{24BE}\x{24BF}\x{24C0}\x{24C1}\x{24C2}\x{24C3}\x{24C4}\x{24C5}\x{24C6}\x{24C7}\x{24C8}\x{24C9}\x{24CA}\x{24CB}\x{24CC}\x{24CD}\x{24CE}\x{24CF}\x{24D0}\x{24D1}\x{24D2}\x{24D3}\x{24D4}\x{24D5}\x{24D6}\x{24D7}\x{24D8}\x{24D9}\x{24DA}\x{24DB}\x{24DC}\x{24DD}\x{24DE}\x{24DF}\x{24E0}\x{24E1}\x{24E2}\x{24E3}\x{24E4}\x{24E5}\x{24E6}\x{24E7}\x{24E8}\x{24E9}", | ||||||||||
| 1014 | "mathematicalBold" => "\x{1D400}\x{1D401}\x{1D402}\x{1D403}\x{1D404}\x{1D405}\x{1D406}\x{1D407}\x{1D408}\x{1D409}\x{1D40A}\x{1D40B}\x{1D40C}\x{1D40D}\x{1D40E}\x{1D40F}\x{1D410}\x{1D411}\x{1D412}\x{1D413}\x{1D414}\x{1D415}\x{1D416}\x{1D417}\x{1D418}\x{1D419}\x{1D41A}\x{1D41B}\x{1D41C}\x{1D41D}\x{1D41E}\x{1D41F}\x{1D420}\x{1D421}\x{1D422}\x{1D423}\x{1D424}\x{1D425}\x{1D426}\x{1D427}\x{1D428}\x{1D429}\x{1D42A}\x{1D42B}\x{1D42C}\x{1D42D}\x{1D42E}\x{1D42F}\x{1D430}\x{1D431}\x{1D432}\x{1D433}\x{1D6A8}\x{1D6A9}\x{1D6AA}\x{1D6AB}\x{1D6AC}\x{1D6AD}\x{1D6AE}\x{1D6AF}\x{1D6B0}\x{1D6B1}\x{1D6B2}\x{1D6B3}\x{1D6B4}\x{1D6B5}\x{1D6B6}\x{1D6B7}\x{1D6B8}\x{1D6B9}\x{1D6BA}\x{1D6BB}\x{1D6BC}\x{1D6BD}\x{1D6BE}\x{1D6BF}\x{1D6C0}\x{1D6C1}\x{1D6C2}\x{1D6C3}\x{1D6C4}\x{1D6C5}\x{1D6C6}\x{1D6C7}\x{1D6C8}\x{1D6C9}\x{1D6CA}\x{1D6CB}\x{1D6CC}\x{1D6CD}\x{1D6CE}\x{1D6CF}\x{1D6D0}\x{1D6D1}\x{1D6D2}\x{1D6D3}\x{1D6D4}\x{1D6D5}\x{1D6D6}\x{1D6D7}\x{1D6D8}\x{1D6D9}\x{1D6DA}\x{1D6DB}\x{1D6DC}\x{1D6DD}\x{1D6DE}\x{1D6DF}\x{1D6E0}\x{1D6E1}", | ||||||||||
| 1015 | "mathematicalBoldFraktur" => "\x{1D56C}\x{1D56D}\x{1D56E}\x{1D56F}\x{1D570}\x{1D571}\x{1D572}\x{1D573}\x{1D574}\x{1D575}\x{1D576}\x{1D577}\x{1D578}\x{1D579}\x{1D57A}\x{1D57B}\x{1D57C}\x{1D57D}\x{1D57E}\x{1D57F}\x{1D580}\x{1D581}\x{1D582}\x{1D583}\x{1D584}\x{1D585}\x{1D586}\x{1D587}\x{1D588}\x{1D589}\x{1D58A}\x{1D58B}\x{1D58C}\x{1D58D}\x{1D58E}\x{1D58F}\x{1D590}\x{1D591}\x{1D592}\x{1D593}\x{1D594}\x{1D595}\x{1D596}\x{1D597}\x{1D598}\x{1D599}\x{1D59A}\x{1D59B}\x{1D59C}\x{1D59D}\x{1D59E}\x{1D59F}", | ||||||||||
| 1016 | "mathematicalBoldItalic" => "\x{1D468}\x{1D469}\x{1D46A}\x{1D46B}\x{1D46C}\x{1D46D}\x{1D46E}\x{1D46F}\x{1D470}\x{1D471}\x{1D472}\x{1D473}\x{1D474}\x{1D475}\x{1D476}\x{1D477}\x{1D478}\x{1D479}\x{1D47A}\x{1D47B}\x{1D47C}\x{1D47D}\x{1D47E}\x{1D47F}\x{1D480}\x{1D481}\x{1D482}\x{1D483}\x{1D484}\x{1D485}\x{1D486}\x{1D487}\x{1D488}\x{1D489}\x{1D48A}\x{1D48B}\x{1D48C}\x{1D48D}\x{1D48E}\x{1D48F}\x{1D490}\x{1D491}\x{1D492}\x{1D493}\x{1D494}\x{1D495}\x{1D496}\x{1D497}\x{1D498}\x{1D499}\x{1D49A}\x{1D49B}\x{1D71C}\x{1D71D}\x{1D71E}\x{1D71F}\x{1D720}\x{1D721}\x{1D722}\x{1D723}\x{1D724}\x{1D725}\x{1D726}\x{1D727}\x{1D728}\x{1D729}\x{1D72A}\x{1D72B}\x{1D72C}\x{1D72D}\x{1D72E}\x{1D72F}\x{1D730}\x{1D731}\x{1D732}\x{1D733}\x{1D734}\x{1D735}\x{1D736}\x{1D737}\x{1D738}\x{1D739}\x{1D73A}\x{1D73B}\x{1D73C}\x{1D73D}\x{1D73E}\x{1D73F}\x{1D740}\x{1D741}\x{1D742}\x{1D743}\x{1D744}\x{1D745}\x{1D746}\x{1D747}\x{1D748}\x{1D749}\x{1D74A}\x{1D74B}\x{1D74C}\x{1D74D}\x{1D74E}\x{1D74F}\x{1D750}\x{1D751}\x{1D752}\x{1D753}\x{1D754}\x{1D755}", | ||||||||||
| 1017 | "mathematicalBoldScript" => "\x{1D4D0}\x{1D4D1}\x{1D4D2}\x{1D4D3}\x{1D4D4}\x{1D4D5}\x{1D4D6}\x{1D4D7}\x{1D4D8}\x{1D4D9}\x{1D4DA}\x{1D4DB}\x{1D4DC}\x{1D4DD}\x{1D4DE}\x{1D4DF}\x{1D4E0}\x{1D4E1}\x{1D4E2}\x{1D4E3}\x{1D4E4}\x{1D4E5}\x{1D4E6}\x{1D4E7}\x{1D4E8}\x{1D4E9}\x{1D4EA}\x{1D4EB}\x{1D4EC}\x{1D4ED}\x{1D4EE}\x{1D4EF}\x{1D4F0}\x{1D4F1}\x{1D4F2}\x{1D4F3}\x{1D4F4}\x{1D4F5}\x{1D4F6}\x{1D4F7}\x{1D4F8}\x{1D4F9}\x{1D4FA}\x{1D4FB}\x{1D4FC}\x{1D4FD}\x{1D4FE}\x{1D4FF}\x{1D500}\x{1D501}\x{1D502}\x{1D503}", | ||||||||||
| 1018 | "mathematicalDouble-struck" => "\x{1D538}\x{1D539}\x{1D53B}\x{1D53C}\x{1D53D}\x{1D53E}\x{1D540}\x{1D541}\x{1D542}\x{1D543}\x{1D544}\x{1D546}\x{1D54A}\x{1D54B}\x{1D54C}\x{1D54D}\x{1D54E}\x{1D54F}\x{1D550}\x{1D552}\x{1D553}\x{1D554}\x{1D555}\x{1D556}\x{1D557}\x{1D558}\x{1D559}\x{1D55A}\x{1D55B}\x{1D55C}\x{1D55D}\x{1D55E}\x{1D55F}\x{1D560}\x{1D561}\x{1D562}\x{1D563}\x{1D564}\x{1D565}\x{1D566}\x{1D567}\x{1D568}\x{1D569}\x{1D56A}\x{1D56B}", | ||||||||||
| 1019 | "mathematicalFraktur" => "\x{1D504}\x{1D505}\x{1D507}\x{1D508}\x{1D509}\x{1D50A}\x{1D50D}\x{1D50E}\x{1D50F}\x{1D510}\x{1D511}\x{1D512}\x{1D513}\x{1D514}\x{1D516}\x{1D517}\x{1D518}\x{1D519}\x{1D51A}\x{1D51B}\x{1D51C}\x{1D51E}\x{1D51F}\x{1D520}\x{1D521}\x{1D522}\x{1D523}\x{1D524}\x{1D525}\x{1D526}\x{1D527}\x{1D528}\x{1D529}\x{1D52A}\x{1D52B}\x{1D52C}\x{1D52D}\x{1D52E}\x{1D52F}\x{1D530}\x{1D531}\x{1D532}\x{1D533}\x{1D534}\x{1D535}\x{1D536}\x{1D537}", | ||||||||||
| 1020 | "mathematicalItalic" => "\x{1D434}\x{1D435}\x{1D436}\x{1D437}\x{1D438}\x{1D439}\x{1D43A}\x{1D43B}\x{1D43C}\x{1D43D}\x{1D43E}\x{1D43F}\x{1D440}\x{1D441}\x{1D442}\x{1D443}\x{1D444}\x{1D445}\x{1D446}\x{1D447}\x{1D448}\x{1D449}\x{1D44A}\x{1D44B}\x{1D44C}\x{1D44D}\x{1D44E}\x{1D44F}\x{1D450}\x{1D451}\x{1D452}\x{1D453}\x{1D454}\x{1D456}\x{1D457}\x{1D458}\x{1D459}\x{1D45A}\x{1D45B}\x{1D45C}\x{1D45D}\x{1D45E}\x{1D45F}\x{1D460}\x{1D461}\x{1D462}\x{1D463}\x{1D464}\x{1D465}\x{1D466}\x{1D467}\x{1D6E2}\x{1D6E3}\x{1D6E4}\x{1D6E5}\x{1D6E6}\x{1D6E7}\x{1D6E8}\x{1D6E9}\x{1D6EA}\x{1D6EB}\x{1D6EC}\x{1D6ED}\x{1D6EE}\x{1D6EF}\x{1D6F0}\x{1D6F1}\x{1D6F2}\x{1D6F3}\x{1D6F4}\x{1D6F5}\x{1D6F6}\x{1D6F7}\x{1D6F8}\x{1D6F9}\x{1D6FA}\x{1D6FB}\x{1D6FC}\x{1D6FD}\x{1D6FE}\x{1D6FF}\x{1D700}\x{1D701}\x{1D702}\x{1D703}\x{1D704}\x{1D705}\x{1D706}\x{1D707}\x{1D708}\x{1D709}\x{1D70A}\x{1D70B}\x{1D70C}\x{1D70D}\x{1D70E}\x{1D70F}\x{1D710}\x{1D711}\x{1D712}\x{1D713}\x{1D714}\x{1D715}\x{1D716}\x{1D717}\x{1D718}\x{1D719}\x{1D71A}\x{1D71B}", | ||||||||||
| 1021 | "mathematicalMonospace" => "\x{1D670}\x{1D671}\x{1D672}\x{1D673}\x{1D674}\x{1D675}\x{1D676}\x{1D677}\x{1D678}\x{1D679}\x{1D67A}\x{1D67B}\x{1D67C}\x{1D67D}\x{1D67E}\x{1D67F}\x{1D680}\x{1D681}\x{1D682}\x{1D683}\x{1D684}\x{1D685}\x{1D686}\x{1D687}\x{1D688}\x{1D689}\x{1D68A}\x{1D68B}\x{1D68C}\x{1D68D}\x{1D68E}\x{1D68F}\x{1D690}\x{1D691}\x{1D692}\x{1D693}\x{1D694}\x{1D695}\x{1D696}\x{1D697}\x{1D698}\x{1D699}\x{1D69A}\x{1D69B}\x{1D69C}\x{1D69D}\x{1D69E}\x{1D69F}\x{1D6A0}\x{1D6A1}\x{1D6A2}\x{1D6A3}", | ||||||||||
| 1022 | "mathematicalSans-serif" => "\x{1D5A0}\x{1D5A1}\x{1D5A2}\x{1D5A3}\x{1D5A4}\x{1D5A5}\x{1D5A6}\x{1D5A7}\x{1D5A8}\x{1D5A9}\x{1D5AA}\x{1D5AB}\x{1D5AC}\x{1D5AD}\x{1D5AE}\x{1D5AF}\x{1D5B0}\x{1D5B1}\x{1D5B2}\x{1D5B3}\x{1D5B4}\x{1D5B5}\x{1D5B6}\x{1D5B7}\x{1D5B8}\x{1D5B9}\x{1D5BA}\x{1D5BB}\x{1D5BC}\x{1D5BD}\x{1D5BE}\x{1D5BF}\x{1D5C0}\x{1D5C1}\x{1D5C2}\x{1D5C3}\x{1D5C4}\x{1D5C5}\x{1D5C6}\x{1D5C7}\x{1D5C8}\x{1D5C9}\x{1D5CA}\x{1D5CB}\x{1D5CC}\x{1D5CD}\x{1D5CE}\x{1D5CF}\x{1D5D0}\x{1D5D1}\x{1D5D2}\x{1D5D3}", | ||||||||||
| 1023 | "mathematicalSans-serifBold" => "\x{1D5D4}\x{1D5D5}\x{1D5D6}\x{1D5D7}\x{1D5D8}\x{1D5D9}\x{1D5DA}\x{1D5DB}\x{1D5DC}\x{1D5DD}\x{1D5DE}\x{1D5DF}\x{1D5E0}\x{1D5E1}\x{1D5E2}\x{1D5E3}\x{1D5E4}\x{1D5E5}\x{1D5E6}\x{1D5E7}\x{1D5E8}\x{1D5E9}\x{1D5EA}\x{1D5EB}\x{1D5EC}\x{1D5ED}\x{1D5EE}\x{1D5EF}\x{1D5F0}\x{1D5F1}\x{1D5F2}\x{1D5F3}\x{1D5F4}\x{1D5F5}\x{1D5F6}\x{1D5F7}\x{1D5F8}\x{1D5F9}\x{1D5FA}\x{1D5FB}\x{1D5FC}\x{1D5FD}\x{1D5FE}\x{1D5FF}\x{1D600}\x{1D601}\x{1D602}\x{1D603}\x{1D604}\x{1D605}\x{1D606}\x{1D607}\x{1D756}\x{1D757}\x{1D758}\x{1D759}\x{1D75A}\x{1D75B}\x{1D75C}\x{1D75D}\x{1D75E}\x{1D75F}\x{1D760}\x{1D761}\x{1D762}\x{1D763}\x{1D764}\x{1D765}\x{1D766}\x{1D767}\x{1D768}\x{1D769}\x{1D76A}\x{1D76B}\x{1D76C}\x{1D76D}\x{1D76E}\x{1D76F}\x{1D770}\x{1D771}\x{1D772}\x{1D773}\x{1D774}\x{1D775}\x{1D776}\x{1D777}\x{1D778}\x{1D779}\x{1D77A}\x{1D77B}\x{1D77C}\x{1D77D}\x{1D77E}\x{1D77F}\x{1D780}\x{1D781}\x{1D782}\x{1D783}\x{1D784}\x{1D785}\x{1D786}\x{1D787}\x{1D788}\x{1D789}\x{1D78A}\x{1D78B}\x{1D78C}\x{1D78D}\x{1D78E}\x{1D78F}", | ||||||||||
| 1024 | "mathematicalSans-serifBoldItalic" => "\x{1D63C}\x{1D63D}\x{1D63E}\x{1D63F}\x{1D640}\x{1D641}\x{1D642}\x{1D643}\x{1D644}\x{1D645}\x{1D646}\x{1D647}\x{1D648}\x{1D649}\x{1D64A}\x{1D64B}\x{1D64C}\x{1D64D}\x{1D64E}\x{1D64F}\x{1D650}\x{1D651}\x{1D652}\x{1D653}\x{1D654}\x{1D655}\x{1D656}\x{1D657}\x{1D658}\x{1D659}\x{1D65A}\x{1D65B}\x{1D65C}\x{1D65D}\x{1D65E}\x{1D65F}\x{1D660}\x{1D661}\x{1D662}\x{1D663}\x{1D664}\x{1D665}\x{1D666}\x{1D667}\x{1D668}\x{1D669}\x{1D66A}\x{1D66B}\x{1D66C}\x{1D66D}\x{1D66E}\x{1D66F}\x{1D790}\x{1D791}\x{1D792}\x{1D793}\x{1D794}\x{1D795}\x{1D796}\x{1D797}\x{1D798}\x{1D799}\x{1D79A}\x{1D79B}\x{1D79C}\x{1D79D}\x{1D79E}\x{1D79F}\x{1D7A0}\x{1D7A1}\x{1D7A2}\x{1D7A3}\x{1D7A4}\x{1D7A5}\x{1D7A6}\x{1D7A7}\x{1D7A8}\x{1D7A9}\x{1D7AA}\x{1D7AB}\x{1D7AC}\x{1D7AD}\x{1D7AE}\x{1D7AF}\x{1D7B0}\x{1D7B1}\x{1D7B2}\x{1D7B3}\x{1D7B4}\x{1D7B5}\x{1D7B6}\x{1D7B7}\x{1D7B8}\x{1D7B9}\x{1D7BA}\x{1D7BB}\x{1D7BC}\x{1D7BD}\x{1D7BE}\x{1D7BF}\x{1D7C0}\x{1D7C1}\x{1D7C2}\x{1D7C3}\x{1D7C4}\x{1D7C5}\x{1D7C6}\x{1D7C7}\x{1D7C8}\x{1D7C9}", | ||||||||||
| 1025 | "mathematicalSans-serifItalic" => "\x{1D608}\x{1D609}\x{1D60A}\x{1D60B}\x{1D60C}\x{1D60D}\x{1D60E}\x{1D60F}\x{1D610}\x{1D611}\x{1D612}\x{1D613}\x{1D614}\x{1D615}\x{1D616}\x{1D617}\x{1D618}\x{1D619}\x{1D61A}\x{1D61B}\x{1D61C}\x{1D61D}\x{1D61E}\x{1D61F}\x{1D620}\x{1D621}\x{1D622}\x{1D623}\x{1D624}\x{1D625}\x{1D626}\x{1D627}\x{1D628}\x{1D629}\x{1D62A}\x{1D62B}\x{1D62C}\x{1D62D}\x{1D62E}\x{1D62F}\x{1D630}\x{1D631}\x{1D632}\x{1D633}\x{1D634}\x{1D635}\x{1D636}\x{1D637}\x{1D638}\x{1D639}\x{1D63A}\x{1D63B}", | ||||||||||
| 1026 | "mathematicalScript" => "\x{1D49C}\x{1D49E}\x{1D49F}\x{1D4A2}\x{1D4A5}\x{1D4A6}\x{1D4A9}\x{1D4AA}\x{1D4AB}\x{1D4AC}\x{1D4AE}\x{1D4AF}\x{1D4B0}\x{1D4B1}\x{1D4B2}\x{1D4B3}\x{1D4B4}\x{1D4B5}\x{1D4B6}\x{1D4B7}\x{1D4B8}\x{1D4B9}\x{1D4BB}\x{1D4BD}\x{1D4BE}\x{1D4BF}\x{1D4C0}\x{1D4C1}\x{1D4C2}\x{1D4C3}\x{1D4C5}\x{1D4C6}\x{1D4C7}\x{1D4C8}\x{1D4C9}\x{1D4CA}\x{1D4CB}\x{1D4CC}\x{1D4CD}\x{1D4CE}\x{1D4CF}", | ||||||||||
| 1027 | "negativeCircledLatinLetter" => "\x{1F150}\x{1F151}\x{1F152}\x{1F153}\x{1F154}\x{1F155}\x{1F156}\x{1F157}\x{1F158}\x{1F159}\x{1F15A}\x{1F15B}\x{1F15C}\x{1F15D}\x{1F15E}\x{1F15F}\x{1F160}\x{1F161}\x{1F162}\x{1F163}\x{1F164}\x{1F165}\x{1F166}\x{1F167}\x{1F168}\x{1F169}", | ||||||||||
| 1028 | "negativeSquaredLatinLetter" => "\x{1F170}\x{1F171}\x{1F172}\x{1F173}\x{1F174}\x{1F175}\x{1F176}\x{1F177}\x{1F178}\x{1F179}\x{1F17A}\x{1F17B}\x{1F17C}\x{1F17D}\x{1F17E}\x{1F17F}\x{1F180}\x{1F181}\x{1F182}\x{1F183}\x{1F184}\x{1F185}\x{1F186}\x{1F187}\x{1F188}\x{1F189}", | ||||||||||
| 1029 | "semiColon" => "\x{27E2}", | ||||||||||
| 1030 | "squaredLatinLetter" => "\x{1F130}\x{1F131}\x{1F132}\x{1F133}\x{1F134}\x{1F135}\x{1F136}\x{1F137}\x{1F138}\x{1F139}\x{1F13A}\x{1F13B}\x{1F13C}\x{1F13D}\x{1F13E}\x{1F13F}\x{1F140}\x{1F141}\x{1F142}\x{1F143}\x{1F144}\x{1F145}\x{1F146}\x{1F147}\x{1F148}\x{1F149}\x{1F1A5}", | ||||||||||
| 1031 | }, | ||||||||||
| 1032 | brackets => 16, | ||||||||||
| 1033 | bracketsBase => 16, | ||||||||||
| 1034 | bracketsClose => [ | ||||||||||
| 1035 | "\x{2309}", | ||||||||||
| 1036 | "\x{230B}", | ||||||||||
| 1037 | "\x{232A}", | ||||||||||
| 1038 | "\x{2769}", | ||||||||||
| 1039 | "\x{276B}", | ||||||||||
| 1040 | "\x{276D}", | ||||||||||
| 1041 | "\x{276F}", | ||||||||||
| 1042 | "\x{2771}", | ||||||||||
| 1043 | "\x{2773}", | ||||||||||
| 1044 | "\x{2775}", | ||||||||||
| 1045 | "\x{27E7}", | ||||||||||
| 1046 | "\x{27E9}", | ||||||||||
| 1047 | "\x{27EB}", | ||||||||||
| 1048 | "\x{27ED}", | ||||||||||
| 1049 | "\x{27EF}", | ||||||||||
| 1050 | "\x{2984}", | ||||||||||
| 1051 | "\x{2986}", | ||||||||||
| 1052 | "\x{2988}", | ||||||||||
| 1053 | "\x{298A}", | ||||||||||
| 1054 | "\x{298C}", | ||||||||||
| 1055 | "\x{298E}", | ||||||||||
| 1056 | "\x{2990}", | ||||||||||
| 1057 | "\x{2992}", | ||||||||||
| 1058 | "\x{2994}", | ||||||||||
| 1059 | "\x{2996}", | ||||||||||
| 1060 | "\x{2998}", | ||||||||||
| 1061 | "\x{29FD}", | ||||||||||
| 1062 | "\x{2E29}", | ||||||||||
| 1063 | "\x{3009}", | ||||||||||
| 1064 | "\x{300B}", | ||||||||||
| 1065 | "\x{3011}", | ||||||||||
| 1066 | "\x{3015}", | ||||||||||
| 1067 | "\x{3017}", | ||||||||||
| 1068 | "\x{3019}", | ||||||||||
| 1069 | "\x{301B}", | ||||||||||
| 1070 | "\x{FD3F}", | ||||||||||
| 1071 | "\x{FF09}", | ||||||||||
| 1072 | "\x{FF60}", | ||||||||||
| 1073 | ], | ||||||||||
| 1074 | bracketsHigh => [ | ||||||||||
| 1075 | "0x1300230b", | ||||||||||
| 1076 | "0x1500232a", | ||||||||||
| 1077 | "0x23002775", | ||||||||||
| 1078 | "0x2d0027ef", | ||||||||||
| 1079 | "0x43002998", | ||||||||||
| 1080 | "0x450029fd", | ||||||||||
| 1081 | "0x47002e29", | ||||||||||
| 1082 | "0x4b00300b", | ||||||||||
| 1083 | "0x4d003011", | ||||||||||
| 1084 | "0x5500301b", | ||||||||||
| 1085 | "0x5700fd3f", | ||||||||||
| 1086 | "0x5900ff09", | ||||||||||
| 1087 | "0x5b00ff60", | ||||||||||
| 1088 | 0, | ||||||||||
| 1089 | 0, | ||||||||||
| 1090 | 0, | ||||||||||
| 1091 | ], | ||||||||||
| 1092 | bracketsLow => [ | ||||||||||
| 1093 | "0x10002308", | ||||||||||
| 1094 | "0x14002329", | ||||||||||
| 1095 | "0x16002768", | ||||||||||
| 1096 | "0x240027e6", | ||||||||||
| 1097 | "0x2e002983", | ||||||||||
| 1098 | "0x440029fc", | ||||||||||
| 1099 | "0x46002e28", | ||||||||||
| 1100 | "0x48003008", | ||||||||||
| 1101 | "0x4c003010", | ||||||||||
| 1102 | "0x4e003014", | ||||||||||
| 1103 | "0x5600fd3e", | ||||||||||
| 1104 | "0x5800ff08", | ||||||||||
| 1105 | "0x5a00ff5f", | ||||||||||
| 1106 | 0, | ||||||||||
| 1107 | 0, | ||||||||||
| 1108 | 0, | ||||||||||
| 1109 | ], | ||||||||||
| 1110 | bracketsOpen => [ | ||||||||||
| 1111 | "\x{2308}", | ||||||||||
| 1112 | "\x{230A}", | ||||||||||
| 1113 | "\x{2329}", | ||||||||||
| 1114 | "\x{2768}", | ||||||||||
| 1115 | "\x{276A}", | ||||||||||
| 1116 | "\x{276C}", | ||||||||||
| 1117 | "\x{276E}", | ||||||||||
| 1118 | "\x{2770}", | ||||||||||
| 1119 | "\x{2772}", | ||||||||||
| 1120 | "\x{2774}", | ||||||||||
| 1121 | "\x{27E6}", | ||||||||||
| 1122 | "\x{27E8}", | ||||||||||
| 1123 | "\x{27EA}", | ||||||||||
| 1124 | "\x{27EC}", | ||||||||||
| 1125 | "\x{27EE}", | ||||||||||
| 1126 | "\x{2983}", | ||||||||||
| 1127 | "\x{2985}", | ||||||||||
| 1128 | "\x{2987}", | ||||||||||
| 1129 | "\x{2989}", | ||||||||||
| 1130 | "\x{298B}", | ||||||||||
| 1131 | "\x{298D}", | ||||||||||
| 1132 | "\x{298F}", | ||||||||||
| 1133 | "\x{2991}", | ||||||||||
| 1134 | "\x{2993}", | ||||||||||
| 1135 | "\x{2995}", | ||||||||||
| 1136 | "\x{2997}", | ||||||||||
| 1137 | "\x{29FC}", | ||||||||||
| 1138 | "\x{2E28}", | ||||||||||
| 1139 | "\x{3008}", | ||||||||||
| 1140 | "\x{300A}", | ||||||||||
| 1141 | "\x{3010}", | ||||||||||
| 1142 | "\x{3014}", | ||||||||||
| 1143 | "\x{3016}", | ||||||||||
| 1144 | "\x{3018}", | ||||||||||
| 1145 | "\x{301A}", | ||||||||||
| 1146 | "\x{FD3E}", | ||||||||||
| 1147 | "\x{FF08}", | ||||||||||
| 1148 | "\x{FF5F}", | ||||||||||
| 1149 | ], | ||||||||||
| 1150 | lexicalAlpha => { | ||||||||||
| 1151 | "" => [ | ||||||||||
| 1152 | "circledLatinLetter", | ||||||||||
| 1153 | "mathematicalBoldFraktur", | ||||||||||
| 1154 | "mathematicalBoldScript", | ||||||||||
| 1155 | "mathematicalDouble-struck", | ||||||||||
| 1156 | "mathematicalFraktur", | ||||||||||
| 1157 | "mathematicalMonospace", | ||||||||||
| 1158 | "mathematicalSans-serif", | ||||||||||
| 1159 | "mathematicalSans-serifItalic", | ||||||||||
| 1160 | "mathematicalScript", | ||||||||||
| 1161 | "negativeSquaredLatinLetter", | ||||||||||
| 1162 | "semiColon", | ||||||||||
| 1163 | "squaredLatinLetter", | ||||||||||
| 1164 | ], | ||||||||||
| 1165 | "Ascii" => ["negativeCircledLatinLetter"], | ||||||||||
| 1166 | "assign" => ["mathematicalItalic"], | ||||||||||
| 1167 | "CloseBracket" => [], | ||||||||||
| 1168 | "dyad" => ["mathematicalBold"], | ||||||||||
| 1169 | "OpenBracket" => [], | ||||||||||
| 1170 | "prefix" => ["mathematicalBoldItalic"], | ||||||||||
| 1171 | "semiColon" => [], | ||||||||||
| 1172 | "suffix" => ["mathematicalSans-serifBoldItalic"], | ||||||||||
| 1173 | "term" => [], | ||||||||||
| 1174 | "variable" => ["mathematicalSans-serifBold"], | ||||||||||
| 1175 | }, | ||||||||||
| 1176 | lexicalHigh => [ | ||||||||||
| 1177 | 127, | ||||||||||
| 1178 | 10210, | ||||||||||
| 1179 | 119859, | ||||||||||
| 1180 | 119911, | ||||||||||
| 1181 | 119963, | ||||||||||
| 1182 | 120327, | ||||||||||
| 1183 | 120431, | ||||||||||
| 1184 | 872535777, | ||||||||||
| 1185 | 872535835, | ||||||||||
| 1186 | 872535893, | ||||||||||
| 1187 | 872535951, | ||||||||||
| 1188 | 872536009, | ||||||||||
| 1189 | 2147610985, | ||||||||||
| 1190 | 0, | ||||||||||
| 1191 | 0, | ||||||||||
| 1192 | 0, | ||||||||||
| 1193 | ], | ||||||||||
| 1194 | lexicalLow => [ | ||||||||||
| 1195 | 33554432, | ||||||||||
| 1196 | 134227938, | ||||||||||
| 1197 | 50451456, | ||||||||||
| 1198 | 84005940, | ||||||||||
| 1199 | 67228776, | ||||||||||
| 1200 | 100783572, | ||||||||||
| 1201 | 117560892, | ||||||||||
| 1202 | 50452136, | ||||||||||
| 1203 | 84006626, | ||||||||||
| 1204 | 67229468, | ||||||||||
| 1205 | 100783958, | ||||||||||
| 1206 | 117561232, | ||||||||||
| 1207 | 33681744, | ||||||||||
| 1208 | 0, | ||||||||||
| 1209 | 0, | ||||||||||
| 1210 | 0, | ||||||||||
| 1211 | ], | ||||||||||
| 1212 | lexicals => bless({ | ||||||||||
| 1213 | Ascii => bless({ letter => "a", like => "v", name => "Ascii", number => 2 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1214 | assign => bless({ letter => "a", like => "a", name => "assign", number => 5 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1215 | CloseBracket => bless({ letter => "B", like => "B", name => "CloseBracket", number => 1 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1216 | dyad => bless({ letter => "d", like => "d", name => "dyad", number => 3 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1217 | empty => bless({ letter => "e", like => "e", name => "empty", number => 10 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1218 | NewLineSemiColon => bless({ letter => "N", like => undef, name => "NewLineSemiColon", number => 12 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1219 | OpenBracket => bless({ letter => "b", like => "b", name => "OpenBracket", number => 0 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1220 | prefix => bless({ letter => "p", like => "p", name => "prefix", number => 4 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1221 | semiColon => bless({ letter => "s", like => "s", name => "semiColon", number => 8 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1222 | suffix => bless({ letter => "q", like => "q", name => "suffix", number => 7 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1223 | term => bless({ letter => "t", like => "t", name => "term", number => 9 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1224 | variable => bless({ letter => "v", like => "v", name => "variable", number => 6 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1225 | WhiteSpace => bless({ letter => "W", like => undef, name => "WhiteSpace", number => 11 }, "Unisyn::Parse::Lexical::Constant"), | ||||||||||
| 1226 | }, "Unisyn::Parse::Lexicals"), | ||||||||||
| 1227 | sampleLexicals => { | ||||||||||
| 1228 | brackets => [ | ||||||||||
| 1229 | 100663296, | ||||||||||
| 1230 | 83886080, | ||||||||||
| 1231 | 0, | ||||||||||
| 1232 | 0, | ||||||||||
| 1233 | 0, | ||||||||||
| 1234 | 100663296, | ||||||||||
| 1235 | 16777216, | ||||||||||
| 1236 | 16777216, | ||||||||||
| 1237 | 50331648, | ||||||||||
| 1238 | 0, | ||||||||||
| 1239 | 100663296, | ||||||||||
| 1240 | 16777216, | ||||||||||
| 1241 | 16777216, | ||||||||||
| 1242 | 134217728, | ||||||||||
| 1243 | ], | ||||||||||
| 1244 | nosemi => [ | ||||||||||
| 1245 | 100663296, | ||||||||||
| 1246 | 83886080, | ||||||||||
| 1247 | 0, | ||||||||||
| 1248 | 0, | ||||||||||
| 1249 | 0, | ||||||||||
| 1250 | 100663296, | ||||||||||
| 1251 | 16777216, | ||||||||||
| 1252 | 16777216, | ||||||||||
| 1253 | 50331648, | ||||||||||
| 1254 | 0, | ||||||||||
| 1255 | 100663296, | ||||||||||
| 1256 | 16777216, | ||||||||||
| 1257 | 16777216, | ||||||||||
| 1258 | ], | ||||||||||
| 1259 | s1 => [ | ||||||||||
| 1260 | 100663296, | ||||||||||
| 1261 | 83886080, | ||||||||||
| 1262 | 33554442, | ||||||||||
| 1263 | 33554464, | ||||||||||
| 1264 | 33554464, | ||||||||||
| 1265 | 33554497, | ||||||||||
| 1266 | 33554442, | ||||||||||
| 1267 | 33554464, | ||||||||||
| 1268 | 33554464, | ||||||||||
| 1269 | 33554464, | ||||||||||
| 1270 | ], | ||||||||||
| 1271 | v => [100663296], | ||||||||||
| 1272 | vav => [100663296, 83886080, 100663296], | ||||||||||
| 1273 | vnsvs => [ | ||||||||||
| 1274 | 100663296, | ||||||||||
| 1275 | 33554442, | ||||||||||
| 1276 | 33554464, | ||||||||||
| 1277 | 33554464, | ||||||||||
| 1278 | 33554464, | ||||||||||
| 1279 | 100663296, | ||||||||||
| 1280 | 33554464, | ||||||||||
| 1281 | 33554464, | ||||||||||
| 1282 | 33554464, | ||||||||||
| 1283 | ], | ||||||||||
| 1284 | vnv => [100663296, 33554442, 100663296], | ||||||||||
| 1285 | vnvs => [ | ||||||||||
| 1286 | 100663296, | ||||||||||
| 1287 | 33554442, | ||||||||||
| 1288 | 100663296, | ||||||||||
| 1289 | 33554464, | ||||||||||
| 1290 | 33554464, | ||||||||||
| 1291 | 33554464, | ||||||||||
| 1292 | 33554464, | ||||||||||
| 1293 | ], | ||||||||||
| 1294 | ws => [ | ||||||||||
| 1295 | 100663296, | ||||||||||
| 1296 | 83886080, | ||||||||||
| 1297 | 0, | ||||||||||
| 1298 | 0, | ||||||||||
| 1299 | 0, | ||||||||||
| 1300 | 100663296, | ||||||||||
| 1301 | 16777216, | ||||||||||
| 1302 | 16777216, | ||||||||||
| 1303 | 50331648, | ||||||||||
| 1304 | 0, | ||||||||||
| 1305 | 100663296, | ||||||||||
| 1306 | 16777216, | ||||||||||
| 1307 | 16777216, | ||||||||||
| 1308 | 134217728, | ||||||||||
| 1309 | 100663296, | ||||||||||
| 1310 | 83886080, | ||||||||||
| 1311 | 33554497, | ||||||||||
| 1312 | 50331648, | ||||||||||
| 1313 | 100663296, | ||||||||||
| 1314 | 134217728, | ||||||||||
| 1315 | ], | ||||||||||
| 1316 | }, | ||||||||||
| 1317 | sampleText => { | ||||||||||
| 1318 | brackets => "\x{1D5EE}\x{1D44E}\x{1D460}\x{1D460}\x{1D456}\x{1D454}\x{1D45B}\x{230A}\x{2329}\x{2768}\x{1D5EF}\x{1D5FD}\x{2769}\x{232A}\x{1D429}\x{1D425}\x{1D42E}\x{1D42C}\x{276A}\x{1D600}\x{1D5F0}\x{276B}\x{230B}\x{27E2}", | ||||||||||
| 1319 | nosemi => "\x{1D5EE}\x{1D44E}\x{1D460}\x{1D460}\x{1D456}\x{1D454}\x{1D45B}\x{230A}\x{2329}\x{2768}\x{1D5EF}\x{1D5FD}\x{2769}\x{232A}\x{1D429}\x{1D425}\x{1D42E}\x{1D42C}\x{276A}\x{1D600}\x{1D5F0}\x{276B}\x{230B}", | ||||||||||
| 1320 | s1 => "\x{1D5EE}\x{1D44E}\n A\n ", | ||||||||||
| 1321 | v => "\x{1D5EE}", | ||||||||||
| 1322 | vav => "\x{1D78F}\x{1D44E}\x{1D78F}", | ||||||||||
| 1323 | vnsvs => "\x{1D5EE}\x{1D5EE}\n \x{1D5EF}\x{1D5EF} ", | ||||||||||
| 1324 | vnv => "\x{1D5EE}\n\x{1D5EF}", | ||||||||||
| 1325 | vnvs => "\x{1D5EE}\n\x{1D5EF} ", | ||||||||||
| 1326 | ws => "\x{1D5EE}\x{1D44E}\x{1D460}\x{1D460}\x{1D456}\x{1D454}\x{1D45B}\x{230A}\x{2329}\x{2768}\x{1D5EF}\x{1D5FD}\x{2769}\x{232A}\x{1D429}\x{1D425}\x{1D42E}\x{1D42C}\x{276A}\x{1D600}\x{1D5F0}\x{276B}\x{230B}\x{27E2}\x{1D5EE}\x{1D5EE}\x{1D44E}\x{1D460}\x{1D460}\x{1D456}\x{1D454}\x{1D45B}A\x{1D429}\x{1D425}\x{1D42E}\x{1D42C}\x{1D5F0}\x{1D5F0}\x{27E2}", | ||||||||||
| 1327 | }, | ||||||||||
| 1328 | semiColon => "\x{27E2}", | ||||||||||
| 1329 | separator => "\x{205F}", | ||||||||||
| 1330 | structure => bless({ | ||||||||||
| 1331 | codes => bless({ | ||||||||||
| 1332 | a => bless({ | ||||||||||
| 1333 | letter => "a", | ||||||||||
| 1334 | name => "assignment operator", | ||||||||||
| 1335 | next => "bpv", | ||||||||||
| 1336 | short => "assign", | ||||||||||
| 1337 | }, "Tree::Term::LexicalCode"), | ||||||||||
| 1338 | B => bless({ | ||||||||||
| 1339 | letter => "B", | ||||||||||
| 1340 | name => "closing parenthesis", | ||||||||||
| 1341 | next => "aBdqs", | ||||||||||
| 1342 | short => "CloseBracket", | ||||||||||
| 1343 | }, "Tree::Term::LexicalCode"), | ||||||||||
| 1344 | b => bless({ | ||||||||||
| 1345 | letter => "b", | ||||||||||
| 1346 | name => "opening parenthesis", | ||||||||||
| 1347 | next => "bBpsv", | ||||||||||
| 1348 | short => "OpenBracket", | ||||||||||
| 1349 | }, "Tree::Term::LexicalCode"), | ||||||||||
| 1350 | d => bless({ letter => "d", name => "dyadic operator", next => "bpv", short => "dyad" }, "Tree::Term::LexicalCode"), | ||||||||||
| 1351 | p => bless({ letter => "p", name => "prefix operator", next => "bpv", short => "prefix" }, "Tree::Term::LexicalCode"), | ||||||||||
| 1352 | q => bless({ | ||||||||||
| 1353 | letter => "q", | ||||||||||
| 1354 | name => "suffix operator", | ||||||||||
| 1355 | next => "aBdqs", | ||||||||||
| 1356 | short => "suffix", | ||||||||||
| 1357 | }, "Tree::Term::LexicalCode"), | ||||||||||
| 1358 | s => bless({ letter => "s", name => "semi-colon", next => "bBpsv", short => "semiColon" }, "Tree::Term::LexicalCode"), | ||||||||||
| 1359 | t => bless({ letter => "t", name => "term", next => "aBdqs", short => "term" }, "Tree::Term::LexicalCode"), | ||||||||||
| 1360 | v => bless({ letter => "v", name => "variable", next => "aBdqs", short => "variable" }, "Tree::Term::LexicalCode"), | ||||||||||
| 1361 | }, "Tree::Term::Codes"), | ||||||||||
| 1362 | first => "bpsv", | ||||||||||
| 1363 | last => "Bqsv", | ||||||||||
| 1364 | }, "Tree::Term::LexicalStructure"), | ||||||||||
| 1365 | treeTermLexicals => 'fix', | ||||||||||
| 1366 | }, "Unisyn::Parse::Lexical::Tables"); | ||||||||||
| 1367 | $a->{treeTermLexicals} = $a->{structure}{codes}; | ||||||||||
| 1368 | $a; | ||||||||||
| 1369 | }} | ||||||||||
| 1370 | |||||||||||
| 1371 | #------------------------------------------------------------------------------- | ||||||||||
| 1372 | # Export - eeee | ||||||||||
| 1373 | #------------------------------------------------------------------------------- | ||||||||||
| 1374 | |||||||||||
| 1375 | use Exporter qw(import); | ||||||||||
| 1376 | |||||||||||
| 1377 | use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||||
| 1378 | |||||||||||
| 1379 | @ISA = qw(Exporter); | ||||||||||
| 1380 | @EXPORT = qw(); | ||||||||||
| 1381 | @EXPORT_OK = qw(); | ||||||||||
| 1382 | %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | ||||||||||
| 1383 | |||||||||||
| 1384 | # podDocumentation | ||||||||||
| 1385 | =pod | ||||||||||
| 1386 | |||||||||||
| 1387 | =encoding utf-8 | ||||||||||
| 1388 | |||||||||||
| 1389 | =head1 Name | ||||||||||
| 1390 | |||||||||||
| 1391 | Unisyn::Parse - Parse a Unisyn expression. | ||||||||||
| 1392 | |||||||||||
| 1393 | =head1 Synopsis | ||||||||||
| 1394 | |||||||||||
| 1395 | Parse a Unisyn expression. | ||||||||||
| 1396 | |||||||||||
| 1397 | =head1 Description | ||||||||||
| 1398 | |||||||||||
| 1399 | Parse a Unisyn expression. | ||||||||||
| 1400 | |||||||||||
| 1401 | |||||||||||
| 1402 | Version "20210810". | ||||||||||
| 1403 | |||||||||||
| 1404 | |||||||||||
| 1405 | The following sections describe the methods in each functional area of this | ||||||||||
| 1406 | module. For an alphabetic listing of all methods by name see L<Index|/Index>. | ||||||||||
| 1407 | |||||||||||
| 1408 | |||||||||||
| 1409 | |||||||||||
| 1410 | =head1 Parse | ||||||||||
| 1411 | |||||||||||
| 1412 | Parse Unisyn expressions | ||||||||||
| 1413 | |||||||||||
| 1414 | =head2 parseUtf8(@parameters) | ||||||||||
| 1415 | |||||||||||
| 1416 | Parse a unisyn expression encoded as utf8 | ||||||||||
| 1417 | |||||||||||
| 1418 | Parameter Description | ||||||||||
| 1419 | 1 @parameters Parameters | ||||||||||
| 1420 | |||||||||||
| 1421 | B<Example:> | ||||||||||
| 1422 | |||||||||||
| 1423 | |||||||||||
| 1424 | |||||||||||
| 1425 | parseUtf8 V(address, $address), $size, $fail, $parse; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1426 | |||||||||||
| 1427 | |||||||||||
| 1428 | |||||||||||
| 1429 | =head2 printParseTree() | ||||||||||
| 1430 | |||||||||||
| 1431 | Print the parse tree addressed by r15 | ||||||||||
| 1432 | |||||||||||
| 1433 | |||||||||||
| 1434 | B<Example:> | ||||||||||
| 1435 | |||||||||||
| 1436 | |||||||||||
| 1437 | my $l = $Lex->{sampleLexicals}{vav}; | ||||||||||
| 1438 | Mov $start, Rd(@$l); | ||||||||||
| 1439 | Mov $size, scalar(@$l); | ||||||||||
| 1440 | |||||||||||
| 1441 | parseExpressionCode; | ||||||||||
| 1442 | PrintOutStringNL "Result:"; | ||||||||||
| 1443 | PrintOutRegisterInHex r15; | ||||||||||
| 1444 | |||||||||||
| 1445 | |||||||||||
| 1446 | printParseTree; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1447 | |||||||||||
| 1448 | |||||||||||
| 1449 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1450 | Push Element: | ||||||||||
| 1451 | r13: 0000 0000 0000 0006 | ||||||||||
| 1452 | New: accept initial variable | ||||||||||
| 1453 | New: accept initial variable | ||||||||||
| 1454 | r8: 0000 0000 0000 0006 | ||||||||||
| 1455 | r13: 0000 0001 0000 0005 | ||||||||||
| 1456 | accept a | ||||||||||
| 1457 | Push Element: | ||||||||||
| 1458 | r13: 0000 0001 0000 0005 | ||||||||||
| 1459 | r13: 0000 0002 0000 0006 | ||||||||||
| 1460 | accept v | ||||||||||
| 1461 | Push Element: | ||||||||||
| 1462 | r13: 0000 0002 0000 0006 | ||||||||||
| 1463 | New: Variable | ||||||||||
| 1464 | New: Variable | ||||||||||
| 1465 | r8: 0000 0002 0000 0006 | ||||||||||
| 1466 | Reduce 3: | ||||||||||
| 1467 | r8: 0000 0098 0000 0009 | ||||||||||
| 1468 | r9: 0000 0001 0000 0005 | ||||||||||
| 1469 | r10: 0000 0118 0000 0009 | ||||||||||
| 1470 | New: Term infix term | ||||||||||
| 1471 | New: Term infix term | ||||||||||
| 1472 | r8: 0000 0118 0000 0009 | ||||||||||
| 1473 | r8: 0000 0098 0000 0009 | ||||||||||
| 1474 | r8: 0000 0001 0000 0005 | ||||||||||
| 1475 | Result: | ||||||||||
| 1476 | r15: 0000 0198 0000 0009 | ||||||||||
| 1477 | Tree at: r15: 0000 0000 0000 0198 | ||||||||||
| 1478 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 1479 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0003 depth: 0000 0000 0000 0001 | ||||||||||
| 1480 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 1481 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0118 depth: 0000 0000 0000 0001 | ||||||||||
| 1482 | key: 0000 0000 0000 0004 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 1483 | key: 0000 0000 0000 0005 data: 0000 0000 0000 0098 depth: 0000 0000 0000 0001 | ||||||||||
| 1484 | key: 0000 0000 0000 0006 data: 0000 0000 0000 0005 depth: 0000 0000 0000 0001 | ||||||||||
| 1485 | key: 0000 0000 0000 0007 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 1486 | Tree at: r15: 0000 0000 0000 0098 | ||||||||||
| 1487 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 1488 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 1489 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0006 depth: 0000 0000 0000 0001 | ||||||||||
| 1490 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0000 depth: 0000 0000 0000 0001 | ||||||||||
| 1491 | Tree at: r15: 0000 0000 0000 0118 | ||||||||||
| 1492 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 1493 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 1494 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0006 depth: 0000 0000 0000 0001 | ||||||||||
| 1495 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0002 depth: 0000 0000 0000 0001 | ||||||||||
| 1496 | END | ||||||||||
| 1497 | |||||||||||
| 1498 | |||||||||||
| 1499 | |||||||||||
| 1500 | =head1 Private Methods | ||||||||||
| 1501 | |||||||||||
| 1502 | =head2 getAlpha($register, $address, $index) | ||||||||||
| 1503 | |||||||||||
| 1504 | Load the position of a lexical item in its alphabet from the current character | ||||||||||
| 1505 | |||||||||||
| 1506 | Parameter Description | ||||||||||
| 1507 | 1 $register Register to load | ||||||||||
| 1508 | 2 $address Address of start of string | ||||||||||
| 1509 | 3 $index Index into string | ||||||||||
| 1510 | |||||||||||
| 1511 | =head2 getLexicalCode($register, $address, $index) | ||||||||||
| 1512 | |||||||||||
| 1513 | Load the lexical code of the current character in memory into the specified register. | ||||||||||
| 1514 | |||||||||||
| 1515 | Parameter Description | ||||||||||
| 1516 | 1 $register Register to load | ||||||||||
| 1517 | 2 $address Address of start of string | ||||||||||
| 1518 | 3 $index Index into string | ||||||||||
| 1519 | |||||||||||
| 1520 | =head2 putLexicalCode($register, $address, $index, $code) | ||||||||||
| 1521 | |||||||||||
| 1522 | Put the specified lexical code into the current character in memory. | ||||||||||
| 1523 | |||||||||||
| 1524 | Parameter Description | ||||||||||
| 1525 | 1 $register Register used to load code | ||||||||||
| 1526 | 2 $address Address of string | ||||||||||
| 1527 | 3 $index Index into string | ||||||||||
| 1528 | 4 $code Code to put | ||||||||||
| 1529 | |||||||||||
| 1530 | =head2 loadCurrentChar() | ||||||||||
| 1531 | |||||||||||
| 1532 | Load the details of the character currently being processed so that we have the index of the character in the upper half of the current character and the lexical type of the character in the lowest byte | ||||||||||
| 1533 | |||||||||||
| 1534 | |||||||||||
| 1535 | =head2 checkStackHas($depth) | ||||||||||
| 1536 | |||||||||||
| 1537 | Check that we have at least the specified number of elements on the stack | ||||||||||
| 1538 | |||||||||||
| 1539 | Parameter Description | ||||||||||
| 1540 | 1 $depth Number of elements required on the stack | ||||||||||
| 1541 | |||||||||||
| 1542 | B<Example:> | ||||||||||
| 1543 | |||||||||||
| 1544 | |||||||||||
| 1545 | my @o = (Rb(reverse 0x10, 0, 0, 1), # Open bracket | ||||||||||
| 1546 | Rb(reverse 0x11, 0, 0, 2), # Close bracket | ||||||||||
| 1547 | Rb(reverse $Ascii, 0, 0, 27), # Ascii 'a' | ||||||||||
| 1548 | Rb(reverse $variable, 0, 0, 27), # Variable 'a' | ||||||||||
| 1549 | Rb(reverse $NewLineSemiColon, 0, 0, 0), # New line semicolon | ||||||||||
| 1550 | Rb(reverse $semiColon, 0, 0, 0)); # Semi colon | ||||||||||
| 1551 | |||||||||||
| 1552 | for my $o(@o) # Try converting each input element | ||||||||||
| 1553 | {Mov $start, $o; | ||||||||||
| 1554 | Mov $index, 0; | ||||||||||
| 1555 | loadCurrentChar; | ||||||||||
| 1556 | PrintOutRegisterInHex $element; | ||||||||||
| 1557 | } | ||||||||||
| 1558 | |||||||||||
| 1559 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1560 | r13: 0000 0000 0000 0000 | ||||||||||
| 1561 | r13: 0000 0000 0000 0001 | ||||||||||
| 1562 | r13: 0000 0000 0000 0006 | ||||||||||
| 1563 | r13: 0000 0000 0000 0006 | ||||||||||
| 1564 | r13: 0000 0000 0000 0008 | ||||||||||
| 1565 | r13: 0000 0000 0000 0008 | ||||||||||
| 1566 | END | ||||||||||
| 1567 | |||||||||||
| 1568 | PushR $parseStackBase; | ||||||||||
| 1569 | Mov $parseStackBase, rsp; | ||||||||||
| 1570 | Push rax; | ||||||||||
| 1571 | Push rax; | ||||||||||
| 1572 | |||||||||||
| 1573 | checkStackHas 2; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1574 | |||||||||||
| 1575 | |||||||||||
| 1576 | IfEq Then {PrintOutStringNL "ok"}, Else {PrintOutStringNL "fail"}; checkStackHas 2; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1577 | |||||||||||
| 1578 | |||||||||||
| 1579 | IfGe Then {PrintOutStringNL "ok"}, Else {PrintOutStringNL "fail"}; checkStackHas 2; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1580 | |||||||||||
| 1581 | IfGt Then {PrintOutStringNL "fail"}, Else {PrintOutStringNL "ok"}; | ||||||||||
| 1582 | |||||||||||
| 1583 | Push rax; checkStackHas 3; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1584 | |||||||||||
| 1585 | |||||||||||
| 1586 | |||||||||||
| 1587 | IfEq Then {PrintOutStringNL "ok"}, Else {PrintOutStringNL "fail"}; checkStackHas 3; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1588 | |||||||||||
| 1589 | |||||||||||
| 1590 | IfGe Then {PrintOutStringNL "ok"}, Else {PrintOutStringNL "fail"}; checkStackHas 3; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1591 | |||||||||||
| 1592 | IfGt Then {PrintOutStringNL "fail"}, Else {PrintOutStringNL "ok"}; | ||||||||||
| 1593 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1594 | ok | ||||||||||
| 1595 | ok | ||||||||||
| 1596 | ok | ||||||||||
| 1597 | ok | ||||||||||
| 1598 | ok | ||||||||||
| 1599 | ok | ||||||||||
| 1600 | END | ||||||||||
| 1601 | |||||||||||
| 1602 | |||||||||||
| 1603 | =head2 pushElement() | ||||||||||
| 1604 | |||||||||||
| 1605 | Push the current element on to the stack | ||||||||||
| 1606 | |||||||||||
| 1607 | |||||||||||
| 1608 | =head2 pushEmpty() | ||||||||||
| 1609 | |||||||||||
| 1610 | Push the empty element on to the stack | ||||||||||
| 1611 | |||||||||||
| 1612 | |||||||||||
| 1613 | B<Example:> | ||||||||||
| 1614 | |||||||||||
| 1615 | |||||||||||
| 1616 | Mov $index, 1; | ||||||||||
| 1617 | |||||||||||
| 1618 | pushEmpty; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1619 | |||||||||||
| 1620 | Mov rax, "[rsp]"; | ||||||||||
| 1621 | PrintOutRegisterInHex rax; | ||||||||||
| 1622 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1623 | Push Empty | ||||||||||
| 1624 | rax: 0000 0001 0000 000A | ||||||||||
| 1625 | END | ||||||||||
| 1626 | |||||||||||
| 1627 | |||||||||||
| 1628 | =head2 lexicalNameFromLetter($l) | ||||||||||
| 1629 | |||||||||||
| 1630 | Lexical name for a lexical item described by its letter | ||||||||||
| 1631 | |||||||||||
| 1632 | Parameter Description | ||||||||||
| 1633 | 1 $l Letter of the lexical item | ||||||||||
| 1634 | |||||||||||
| 1635 | B<Example:> | ||||||||||
| 1636 | |||||||||||
| 1637 | |||||||||||
| 1638 | |||||||||||
| 1639 | is_deeply lexicalNameFromLetter('a'), q(assign); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1640 | |||||||||||
| 1641 | is_deeply lexicalNumberFromLetter('a'), $assign; | ||||||||||
| 1642 | |||||||||||
| 1643 | |||||||||||
| 1644 | =head2 lexicalNumberFromLetter($l) | ||||||||||
| 1645 | |||||||||||
| 1646 | Lexical number for a lexical item described by its letter | ||||||||||
| 1647 | |||||||||||
| 1648 | Parameter Description | ||||||||||
| 1649 | 1 $l Letter of the lexical item | ||||||||||
| 1650 | |||||||||||
| 1651 | B<Example:> | ||||||||||
| 1652 | |||||||||||
| 1653 | |||||||||||
| 1654 | is_deeply lexicalNameFromLetter('a'), q(assign); | ||||||||||
| 1655 | |||||||||||
| 1656 | is_deeply lexicalNumberFromLetter('a'), $assign; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1657 | |||||||||||
| 1658 | |||||||||||
| 1659 | |||||||||||
| 1660 | =head2 new2($depth, $description) | ||||||||||
| 1661 | |||||||||||
| 1662 | Create a new term in the parse tree rooted on the stack. | ||||||||||
| 1663 | |||||||||||
| 1664 | Parameter Description | ||||||||||
| 1665 | 1 $depth Stack depth to be converted | ||||||||||
| 1666 | 2 $description Text reason why we are creating a new term | ||||||||||
| 1667 | |||||||||||
| 1668 | =head2 new($depth, $description) | ||||||||||
| 1669 | |||||||||||
| 1670 | Create a new term | ||||||||||
| 1671 | |||||||||||
| 1672 | Parameter Description | ||||||||||
| 1673 | 1 $depth Stack depth to be converted | ||||||||||
| 1674 | 2 $description Text reason why we are creating a new term | ||||||||||
| 1675 | |||||||||||
| 1676 | B<Example:> | ||||||||||
| 1677 | |||||||||||
| 1678 | |||||||||||
| 1679 | Mov $index, 1; | ||||||||||
| 1680 | Mov rax,-1; Push rax; | ||||||||||
| 1681 | Mov rax, 3; Push rax; | ||||||||||
| 1682 | Mov rax, 2; Push rax; | ||||||||||
| 1683 | Mov rax, 1; Push rax; | ||||||||||
| 1684 | |||||||||||
| 1685 | new 3, 'test'; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1686 | |||||||||||
| 1687 | Pop rax; PrintOutRegisterInHex rax; | ||||||||||
| 1688 | Pop rax; PrintOutRegisterInHex rax; | ||||||||||
| 1689 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1690 | New: test | ||||||||||
| 1691 | r8: 0000 0000 0000 0001 | ||||||||||
| 1692 | r8: 0000 0000 0000 0002 | ||||||||||
| 1693 | r8: 0000 0000 0000 0003 | ||||||||||
| 1694 | rax: 0000 0000 0000 0009 | ||||||||||
| 1695 | rax: FFFF FFFF FFFF FFFF | ||||||||||
| 1696 | END | ||||||||||
| 1697 | |||||||||||
| 1698 | |||||||||||
| 1699 | =head2 error($message) | ||||||||||
| 1700 | |||||||||||
| 1701 | Die | ||||||||||
| 1702 | |||||||||||
| 1703 | Parameter Description | ||||||||||
| 1704 | 1 $message Error message | ||||||||||
| 1705 | |||||||||||
| 1706 | B<Example:> | ||||||||||
| 1707 | |||||||||||
| 1708 | |||||||||||
| 1709 | |||||||||||
| 1710 | error "aaa bbbb"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1711 | |||||||||||
| 1712 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1713 | Error: aaa bbbb | ||||||||||
| 1714 | Element: r13: 0000 0000 0000 0000 | ||||||||||
| 1715 | Index : r12: 0000 0000 0000 0000 | ||||||||||
| 1716 | END | ||||||||||
| 1717 | |||||||||||
| 1718 | |||||||||||
| 1719 | =head2 testSet($set, $register) | ||||||||||
| 1720 | |||||||||||
| 1721 | Test a set of items, setting the Zero Flag is one matches else clear the Zero flag | ||||||||||
| 1722 | |||||||||||
| 1723 | Parameter Description | ||||||||||
| 1724 | 1 $set Set of lexical letters | ||||||||||
| 1725 | 2 $register Register to test | ||||||||||
| 1726 | |||||||||||
| 1727 | B<Example:> | ||||||||||
| 1728 | |||||||||||
| 1729 | |||||||||||
| 1730 | Mov r15, -1; | ||||||||||
| 1731 | Mov r15b, $term; | ||||||||||
| 1732 | |||||||||||
| 1733 | testSet("ast", r15); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1734 | |||||||||||
| 1735 | PrintOutZF; | ||||||||||
| 1736 | |||||||||||
| 1737 | testSet("as", r15); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1738 | |||||||||||
| 1739 | PrintOutZF; | ||||||||||
| 1740 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1741 | ZF=1 | ||||||||||
| 1742 | ZF=0 | ||||||||||
| 1743 | END | ||||||||||
| 1744 | |||||||||||
| 1745 | |||||||||||
| 1746 | =head2 checkSet($set) | ||||||||||
| 1747 | |||||||||||
| 1748 | Check that one of a set of items is on the top of the stack or complain if it is not | ||||||||||
| 1749 | |||||||||||
| 1750 | Parameter Description | ||||||||||
| 1751 | 1 $set Set of lexical letters | ||||||||||
| 1752 | |||||||||||
| 1753 | B<Example:> | ||||||||||
| 1754 | |||||||||||
| 1755 | |||||||||||
| 1756 | Mov r15, -1; | ||||||||||
| 1757 | Mov r15b, $term; | ||||||||||
| 1758 | Push r15; | ||||||||||
| 1759 | |||||||||||
| 1760 | checkSet("ast"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1761 | |||||||||||
| 1762 | PrintOutZF; | ||||||||||
| 1763 | |||||||||||
| 1764 | checkSet("as"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1765 | |||||||||||
| 1766 | PrintOutZF; | ||||||||||
| 1767 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1768 | ZF=1 | ||||||||||
| 1769 | Error: Expected one of: 'as' on the stack | ||||||||||
| 1770 | Element: r13: 0000 0000 0000 0000 | ||||||||||
| 1771 | Index : r12: 0000 0000 0000 0000 | ||||||||||
| 1772 | END | ||||||||||
| 1773 | |||||||||||
| 1774 | |||||||||||
| 1775 | =head2 reduce($priority) | ||||||||||
| 1776 | |||||||||||
| 1777 | Convert the longest possible expression on top of the stack into a term at the specified priority | ||||||||||
| 1778 | |||||||||||
| 1779 | Parameter Description | ||||||||||
| 1780 | 1 $priority Priority of the operators to reduce | ||||||||||
| 1781 | |||||||||||
| 1782 | B<Example:> | ||||||||||
| 1783 | |||||||||||
| 1784 | |||||||||||
| 1785 | Mov rsi, rsp; # Create parse stack base | ||||||||||
| 1786 | Mov r15, -1; Push r15; | ||||||||||
| 1787 | Mov r15, $term; Push r15; | ||||||||||
| 1788 | Mov r15, $assign; Push r15; | ||||||||||
| 1789 | Mov r15, $term; Push r15; | ||||||||||
| 1790 | |||||||||||
| 1791 | reduce 1; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1792 | |||||||||||
| 1793 | Pop r15; PrintOutRegisterInHex r15; | ||||||||||
| 1794 | Pop r14; PrintOutRegisterInHex r14; | ||||||||||
| 1795 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1796 | Reduce 3: | ||||||||||
| 1797 | r8: 0000 0000 0000 0009 | ||||||||||
| 1798 | r9: 0000 0000 0000 0005 | ||||||||||
| 1799 | r10: 0000 0000 0000 0009 | ||||||||||
| 1800 | New: Term infix term | ||||||||||
| 1801 | r8: 0000 0000 0000 0009 | ||||||||||
| 1802 | r8: 0000 0000 0000 0009 | ||||||||||
| 1803 | r8: 0000 0000 0000 0005 | ||||||||||
| 1804 | r15: 0000 0000 0000 0009 | ||||||||||
| 1805 | r14: FFFF FFFF FFFF FFFF | ||||||||||
| 1806 | END | ||||||||||
| 1807 | |||||||||||
| 1808 | |||||||||||
| 1809 | =head2 reduceMultiple($priority) | ||||||||||
| 1810 | |||||||||||
| 1811 | Reduce existing operators on the stack | ||||||||||
| 1812 | |||||||||||
| 1813 | Parameter Description | ||||||||||
| 1814 | 1 $priority Priority of the operators to reduce | ||||||||||
| 1815 | |||||||||||
| 1816 | B<Example:> | ||||||||||
| 1817 | |||||||||||
| 1818 | |||||||||||
| 1819 | Mov rsi, rsp; # Create parse stack base | ||||||||||
| 1820 | Mov r15, -1; Push r15; | ||||||||||
| 1821 | Mov r15, $OpenBracket; Push r15; | ||||||||||
| 1822 | |||||||||||
| 1823 | reduceMultiple 1; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||
| 1824 | |||||||||||
| 1825 | Pop r15; PrintOutRegisterInHex r15; | ||||||||||
| 1826 | Pop r14; PrintOutRegisterInHex r14; | ||||||||||
| 1827 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1828 | Reduce 2: | ||||||||||
| 1829 | r8: 0000 0000 0000 0010 | ||||||||||
| 1830 | r9: 0000 0000 0000 0000 | ||||||||||
| 1831 | r15: 0000 0000 0000 0000 | ||||||||||
| 1832 | r14: FFFF FFFF FFFF FFFF | ||||||||||
| 1833 | END | ||||||||||
| 1834 | |||||||||||
| 1835 | |||||||||||
| 1836 | =head2 accept_a() | ||||||||||
| 1837 | |||||||||||
| 1838 | Assign | ||||||||||
| 1839 | |||||||||||
| 1840 | |||||||||||
| 1841 | =head2 accept_b() | ||||||||||
| 1842 | |||||||||||
| 1843 | Open | ||||||||||
| 1844 | |||||||||||
| 1845 | |||||||||||
| 1846 | =head2 accept_B() | ||||||||||
| 1847 | |||||||||||
| 1848 | Closing parenthesis | ||||||||||
| 1849 | |||||||||||
| 1850 | |||||||||||
| 1851 | =head2 accept_d() | ||||||||||
| 1852 | |||||||||||
| 1853 | Infix but not assign or semi-colon | ||||||||||
| 1854 | |||||||||||
| 1855 | |||||||||||
| 1856 | =head2 accept_p() | ||||||||||
| 1857 | |||||||||||
| 1858 | Prefix | ||||||||||
| 1859 | |||||||||||
| 1860 | |||||||||||
| 1861 | =head2 accept_q() | ||||||||||
| 1862 | |||||||||||
| 1863 | Post fix | ||||||||||
| 1864 | |||||||||||
| 1865 | |||||||||||
| 1866 | =head2 accept_s() | ||||||||||
| 1867 | |||||||||||
| 1868 | Semi colon | ||||||||||
| 1869 | |||||||||||
| 1870 | |||||||||||
| 1871 | =head2 accept_v() | ||||||||||
| 1872 | |||||||||||
| 1873 | Variable | ||||||||||
| 1874 | |||||||||||
| 1875 | |||||||||||
| 1876 | =head2 parseExpressionCode() | ||||||||||
| 1877 | |||||||||||
| 1878 | Parse the string of classified lexical items addressed by register $start of length $length. The resulting parse tree (if any) is returned in r15. | ||||||||||
| 1879 | |||||||||||
| 1880 | |||||||||||
| 1881 | =head2 parseExpression(@parameters) | ||||||||||
| 1882 | |||||||||||
| 1883 | Create a parser for an expression described by variables | ||||||||||
| 1884 | |||||||||||
| 1885 | Parameter Description | ||||||||||
| 1886 | 1 @parameters Parameters describing expression | ||||||||||
| 1887 | |||||||||||
| 1888 | =head2 MatchBrackets(@parameters) | ||||||||||
| 1889 | |||||||||||
| 1890 | Replace the low three bytes of a utf32 bracket character with 24 bits of offset to the matching opening or closing bracket. Opening brackets have even codes from 0x10 to 0x4e while the corresponding closing bracket has a code one higher. | ||||||||||
| 1891 | |||||||||||
| 1892 | Parameter Description | ||||||||||
| 1893 | 1 @parameters Parameters | ||||||||||
| 1894 | |||||||||||
| 1895 | B<Example:> | ||||||||||
| 1896 | |||||||||||
| 1897 | |||||||||||
| 1898 | my $l = $Lex->{sampleLexicals}{brackets}; | ||||||||||
| 1899 | |||||||||||
| 1900 | Mov $start, Rd(@$l); | ||||||||||
| 1901 | Mov $size, scalar(@$l); | ||||||||||
| 1902 | |||||||||||
| 1903 | parseExpressionCode; | ||||||||||
| 1904 | PrintOutStringNL "Result:"; | ||||||||||
| 1905 | PrintOutRegisterInHex r15; | ||||||||||
| 1906 | |||||||||||
| 1907 | printParseTree; | ||||||||||
| 1908 | |||||||||||
| 1909 | ok Assemble(debug => 0, eq => <<END); | ||||||||||
| 1910 | Push Element: | ||||||||||
| 1911 | r13: 0000 0000 0000 0006 | ||||||||||
| 1912 | New: accept initial variable | ||||||||||
| 1913 | New: accept initial variable | ||||||||||
| 1914 | r8: 0000 0000 0000 0006 | ||||||||||
| 1915 | r13: 0000 0001 0000 0005 | ||||||||||
| 1916 | accept a | ||||||||||
| 1917 | Push Element: | ||||||||||
| 1918 | r13: 0000 0001 0000 0005 | ||||||||||
| 1919 | r13: 0000 0002 0000 0000 | ||||||||||
| 1920 | accept b | ||||||||||
| 1921 | Push Element: | ||||||||||
| 1922 | r13: 0000 0002 0000 0000 | ||||||||||
| 1923 | r13: 0000 0003 0000 0000 | ||||||||||
| 1924 | accept b | ||||||||||
| 1925 | Push Element: | ||||||||||
| 1926 | r13: 0000 0003 0000 0000 | ||||||||||
| 1927 | r13: 0000 0004 0000 0000 | ||||||||||
| 1928 | accept b | ||||||||||
| 1929 | Push Element: | ||||||||||
| 1930 | r13: 0000 0004 0000 0000 | ||||||||||
| 1931 | r13: 0000 0005 0000 0006 | ||||||||||
| 1932 | accept v | ||||||||||
| 1933 | Push Element: | ||||||||||
| 1934 | r13: 0000 0005 0000 0006 | ||||||||||
| 1935 | New: Variable | ||||||||||
| 1936 | New: Variable | ||||||||||
| 1937 | r8: 0000 0005 0000 0006 | ||||||||||
| 1938 | r13: 0000 0006 0000 0001 | ||||||||||
| 1939 | accept B | ||||||||||
| 1940 | Reduce 3: | ||||||||||
| 1941 | r8: 0000 0003 0000 0000 | ||||||||||
| 1942 | r9: 0000 0004 0000 0000 | ||||||||||
| 1943 | r10: 0000 0118 0000 0009 | ||||||||||
| 1944 | Reduce 2: | ||||||||||
| 1945 | r8: 0000 0000 0000 0030 | ||||||||||
| 1946 | r9: 0000 0004 0000 0000 | ||||||||||
| 1947 | Push Element: | ||||||||||
| 1948 | r13: 0000 0006 0000 0001 | ||||||||||
| 1949 | Reduce 3: | ||||||||||
| 1950 | r8: 0000 0004 0000 0000 | ||||||||||
| 1951 | r9: 0000 0118 0000 0009 | ||||||||||
| 1952 | r10: 0000 0006 0000 0001 | ||||||||||
| 1953 | New: Bracketed term | ||||||||||
| 1954 | New: Bracketed term | ||||||||||
| 1955 | r8: 0000 0118 0000 0009 | ||||||||||
| 1956 | New: Brackets for term | ||||||||||
| 1957 | New: Brackets for term | ||||||||||
| 1958 | r8: 0000 0198 0000 0009 | ||||||||||
| 1959 | r8: 0000 0004 0000 0000 | ||||||||||
| 1960 | Reduce by ( term ) | ||||||||||
| 1961 | Reduce 3: | ||||||||||
| 1962 | r8: 0000 0002 0000 0000 | ||||||||||
| 1963 | r9: 0000 0003 0000 0000 | ||||||||||
| 1964 | r10: 0000 0218 0000 0009 | ||||||||||
| 1965 | Reduce 2: | ||||||||||
| 1966 | r8: 0000 0000 0000 0028 | ||||||||||
| 1967 | r9: 0000 0003 0000 0000 | ||||||||||
| 1968 | r13: 0000 0007 0000 0001 | ||||||||||
| 1969 | accept B | ||||||||||
| 1970 | Reduce 3: | ||||||||||
| 1971 | r8: 0000 0002 0000 0000 | ||||||||||
| 1972 | r9: 0000 0003 0000 0000 | ||||||||||
| 1973 | r10: 0000 0218 0000 0009 | ||||||||||
| 1974 | Reduce 2: | ||||||||||
| 1975 | r8: 0000 0000 0000 0028 | ||||||||||
| 1976 | r9: 0000 0003 0000 0000 | ||||||||||
| 1977 | Push Element: | ||||||||||
| 1978 | r13: 0000 0007 0000 0001 | ||||||||||
| 1979 | Reduce 3: | ||||||||||
| 1980 | r8: 0000 0003 0000 0000 | ||||||||||
| 1981 | r9: 0000 0218 0000 0009 | ||||||||||
| 1982 | r10: 0000 0007 0000 0001 | ||||||||||
| 1983 | New: Bracketed term | ||||||||||
| 1984 | New: Bracketed term | ||||||||||
| 1985 | r8: 0000 0218 0000 0009 | ||||||||||
| 1986 | New: Brackets for term | ||||||||||
| 1987 | New: Brackets for term | ||||||||||
| 1988 | r8: 0000 0298 0000 0009 | ||||||||||
| 1989 | r8: 0000 0003 0000 0000 | ||||||||||
| 1990 | Reduce by ( term ) | ||||||||||
| 1991 | Reduce 3: | ||||||||||
| 1992 | r8: 0000 0001 0000 0005 | ||||||||||
| 1993 | r9: 0000 0002 0000 0000 | ||||||||||
| 1994 | r10: 0000 0318 0000 0009 | ||||||||||
| 1995 | Reduce 2: | ||||||||||
| 1996 | r8: 0000 0000 0000 0020 | ||||||||||
| 1997 | r9: 0000 0002 0000 0000 | ||||||||||
| 1998 | r13: 0000 0008 0000 0003 | ||||||||||
| 1999 | accept d | ||||||||||
| 2000 | Push Element: | ||||||||||
| 2001 | r13: 0000 0008 0000 0003 | ||||||||||
| 2002 | r13: 0000 0009 0000 0000 | ||||||||||
| 2003 | accept b | ||||||||||
| 2004 | Push Element: | ||||||||||
| 2005 | r13: 0000 0009 0000 0000 | ||||||||||
| 2006 | r13: 0000 000A 0000 0006 | ||||||||||
| 2007 | accept v | ||||||||||
| 2008 | Push Element: | ||||||||||
| 2009 | r13: 0000 000A 0000 0006 | ||||||||||
| 2010 | New: Variable | ||||||||||
| 2011 | New: Variable | ||||||||||
| 2012 | r8: 0000 000A 0000 0006 | ||||||||||
| 2013 | r13: 0000 000B 0000 0001 | ||||||||||
| 2014 | accept B | ||||||||||
| 2015 | Reduce 3: | ||||||||||
| 2016 | r8: 0000 0008 0000 0003 | ||||||||||
| 2017 | r9: 0000 0009 0000 0000 | ||||||||||
| 2018 | r10: 0000 0398 0000 0009 | ||||||||||
| 2019 | Reduce 2: | ||||||||||
| 2020 | r8: 0000 0000 0000 0038 | ||||||||||
| 2021 | r9: 0000 0009 0000 0000 | ||||||||||
| 2022 | Push Element: | ||||||||||
| 2023 | r13: 0000 000B 0000 0001 | ||||||||||
| 2024 | Reduce 3: | ||||||||||
| 2025 | r8: 0000 0009 0000 0000 | ||||||||||
| 2026 | r9: 0000 0398 0000 0009 | ||||||||||
| 2027 | r10: 0000 000B 0000 0001 | ||||||||||
| 2028 | New: Bracketed term | ||||||||||
| 2029 | New: Bracketed term | ||||||||||
| 2030 | r8: 0000 0398 0000 0009 | ||||||||||
| 2031 | New: Brackets for term | ||||||||||
| 2032 | New: Brackets for term | ||||||||||
| 2033 | r8: 0000 0418 0000 0009 | ||||||||||
| 2034 | r8: 0000 0009 0000 0000 | ||||||||||
| 2035 | Reduce by ( term ) | ||||||||||
| 2036 | Reduce 3: | ||||||||||
| 2037 | r8: 0000 0318 0000 0009 | ||||||||||
| 2038 | r9: 0000 0008 0000 0003 | ||||||||||
| 2039 | r10: 0000 0498 0000 0009 | ||||||||||
| 2040 | New: Term infix term | ||||||||||
| 2041 | New: Term infix term | ||||||||||
| 2042 | r8: 0000 0498 0000 0009 | ||||||||||
| 2043 | r8: 0000 0318 0000 0009 | ||||||||||
| 2044 | r8: 0000 0008 0000 0003 | ||||||||||
| 2045 | Reduce 3: | ||||||||||
| 2046 | r8: 0000 0001 0000 0005 | ||||||||||
| 2047 | r9: 0000 0002 0000 0000 | ||||||||||
| 2048 | r10: 0000 0518 0000 0009 | ||||||||||
| 2049 | Reduce 2: | ||||||||||
| 2050 | r8: 0000 0000 0000 0020 | ||||||||||
| 2051 | r9: 0000 0002 0000 0000 | ||||||||||
| 2052 | r13: 0000 000C 0000 0001 | ||||||||||
| 2053 | accept B | ||||||||||
| 2054 | Reduce 3: | ||||||||||
| 2055 | r8: 0000 0001 0000 0005 | ||||||||||
| 2056 | r9: 0000 0002 0000 0000 | ||||||||||
| 2057 | r10: 0000 0518 0000 0009 | ||||||||||
| 2058 | Reduce 2: | ||||||||||
| 2059 | r8: 0000 0000 0000 0020 | ||||||||||
| 2060 | r9: 0000 0002 0000 0000 | ||||||||||
| 2061 | Push Element: | ||||||||||
| 2062 | r13: 0000 000C 0000 0001 | ||||||||||
| 2063 | Reduce 3: | ||||||||||
| 2064 | r8: 0000 0002 0000 0000 | ||||||||||
| 2065 | r9: 0000 0518 0000 0009 | ||||||||||
| 2066 | r10: 0000 000C 0000 0001 | ||||||||||
| 2067 | New: Bracketed term | ||||||||||
| 2068 | New: Bracketed term | ||||||||||
| 2069 | r8: 0000 0518 0000 0009 | ||||||||||
| 2070 | New: Brackets for term | ||||||||||
| 2071 | New: Brackets for term | ||||||||||
| 2072 | r8: 0000 0598 0000 0009 | ||||||||||
| 2073 | r8: 0000 0002 0000 0000 | ||||||||||
| 2074 | Reduce by ( term ) | ||||||||||
| 2075 | Reduce 3: | ||||||||||
| 2076 | r8: 0000 0098 0000 0009 | ||||||||||
| 2077 | r9: 0000 0001 0000 0005 | ||||||||||
| 2078 | r10: 0000 0618 0000 0009 | ||||||||||
| 2079 | New: Term infix term | ||||||||||
| 2080 | New: Term infix term | ||||||||||
| 2081 | r8: 0000 0618 0000 0009 | ||||||||||
| 2082 | r8: 0000 0098 0000 0009 | ||||||||||
| 2083 | r8: 0000 0001 0000 0005 | ||||||||||
| 2084 | r13: 0000 000D 0000 0008 | ||||||||||
| 2085 | accept s | ||||||||||
| 2086 | Push Element: | ||||||||||
| 2087 | r13: 0000 000D 0000 0008 | ||||||||||
| 2088 | Result: | ||||||||||
| 2089 | r15: 0000 0698 0000 0009 | ||||||||||
| 2090 | Tree at: r15: 0000 0000 0000 0698 | ||||||||||
| 2091 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2092 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0003 depth: 0000 0000 0000 0001 | ||||||||||
| 2093 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2094 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0618 depth: 0000 0000 0000 0001 | ||||||||||
| 2095 | key: 0000 0000 0000 0004 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2096 | key: 0000 0000 0000 0005 data: 0000 0000 0000 0098 depth: 0000 0000 0000 0001 | ||||||||||
| 2097 | key: 0000 0000 0000 0006 data: 0000 0000 0000 0005 depth: 0000 0000 0000 0001 | ||||||||||
| 2098 | key: 0000 0000 0000 0007 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 2099 | Tree at: r15: 0000 0000 0000 0098 | ||||||||||
| 2100 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2101 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 2102 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0006 depth: 0000 0000 0000 0001 | ||||||||||
| 2103 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0000 depth: 0000 0000 0000 0001 | ||||||||||
| 2104 | Tree at: r15: 0000 0000 0000 0618 | ||||||||||
| 2105 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2106 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0002 depth: 0000 0000 0000 0001 | ||||||||||
| 2107 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2108 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0598 depth: 0000 0000 0000 0001 | ||||||||||
| 2109 | key: 0000 0000 0000 0004 data: 0000 0000 0000 0000 depth: 0000 0000 0000 0001 | ||||||||||
| 2110 | key: 0000 0000 0000 0005 data: 0000 0000 0000 0002 depth: 0000 0000 0000 0001 | ||||||||||
| 2111 | Tree at: r15: 0000 0000 0000 0598 | ||||||||||
| 2112 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2113 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 2114 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2115 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0518 depth: 0000 0000 0000 0001 | ||||||||||
| 2116 | Tree at: r15: 0000 0000 0000 0518 | ||||||||||
| 2117 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2118 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0003 depth: 0000 0000 0000 0001 | ||||||||||
| 2119 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2120 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0498 depth: 0000 0000 0000 0001 | ||||||||||
| 2121 | key: 0000 0000 0000 0004 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2122 | key: 0000 0000 0000 0005 data: 0000 0000 0000 0318 depth: 0000 0000 0000 0001 | ||||||||||
| 2123 | key: 0000 0000 0000 0006 data: 0000 0000 0000 0003 depth: 0000 0000 0000 0001 | ||||||||||
| 2124 | key: 0000 0000 0000 0007 data: 0000 0000 0000 0008 depth: 0000 0000 0000 0001 | ||||||||||
| 2125 | Tree at: r15: 0000 0000 0000 0318 | ||||||||||
| 2126 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2127 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0002 depth: 0000 0000 0000 0001 | ||||||||||
| 2128 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2129 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0298 depth: 0000 0000 0000 0001 | ||||||||||
| 2130 | key: 0000 0000 0000 0004 data: 0000 0000 0000 0000 depth: 0000 0000 0000 0001 | ||||||||||
| 2131 | key: 0000 0000 0000 0005 data: 0000 0000 0000 0003 depth: 0000 0000 0000 0001 | ||||||||||
| 2132 | Tree at: r15: 0000 0000 0000 0298 | ||||||||||
| 2133 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2134 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 2135 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2136 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0218 depth: 0000 0000 0000 0001 | ||||||||||
| 2137 | Tree at: r15: 0000 0000 0000 0218 | ||||||||||
| 2138 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2139 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0002 depth: 0000 0000 0000 0001 | ||||||||||
| 2140 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2141 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0198 depth: 0000 0000 0000 0001 | ||||||||||
| 2142 | key: 0000 0000 0000 0004 data: 0000 0000 0000 0000 depth: 0000 0000 0000 0001 | ||||||||||
| 2143 | key: 0000 0000 0000 0005 data: 0000 0000 0000 0004 depth: 0000 0000 0000 0001 | ||||||||||
| 2144 | Tree at: r15: 0000 0000 0000 0198 | ||||||||||
| 2145 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2146 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 2147 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2148 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0118 depth: 0000 0000 0000 0001 | ||||||||||
| 2149 | Tree at: r15: 0000 0000 0000 0118 | ||||||||||
| 2150 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2151 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 2152 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0006 depth: 0000 0000 0000 0001 | ||||||||||
| 2153 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0005 depth: 0000 0000 0000 0001 | ||||||||||
| 2154 | Tree at: r15: 0000 0000 0000 0498 | ||||||||||
| 2155 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2156 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0002 depth: 0000 0000 0000 0001 | ||||||||||
| 2157 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2158 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0418 depth: 0000 0000 0000 0001 | ||||||||||
| 2159 | key: 0000 0000 0000 0004 data: 0000 0000 0000 0000 depth: 0000 0000 0000 0001 | ||||||||||
| 2160 | key: 0000 0000 0000 0005 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2161 | Tree at: r15: 0000 0000 0000 0418 | ||||||||||
| 2162 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2163 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 2164 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2165 | key: 0000 0000 0000 0003 data: 0000 0000 0000 0398 depth: 0000 0000 0000 0001 | ||||||||||
| 2166 | Tree at: r15: 0000 0000 0000 0398 | ||||||||||
| 2167 | key: 0000 0000 0000 0000 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0001 | ||||||||||
| 2168 | key: 0000 0000 0000 0001 data: 0000 0000 0000 0001 depth: 0000 0000 0000 0001 | ||||||||||
| 2169 | key: 0000 0000 0000 0002 data: 0000 0000 0000 0006 depth: 0000 0000 0000 0001 | ||||||||||
| 2170 | key: 0000 0000 0000 0003 data: 0000 0000 0000 000A depth: 0000 0000 0000 0001 | ||||||||||
| 2171 | END | ||||||||||
| 2172 | |||||||||||
| 2173 | |||||||||||
| 2174 | =head2 ClassifyNewLines(@parameters) | ||||||||||
| 2175 | |||||||||||
| 2176 | Scan input string looking for opportunities to convert new lines into semi colons | ||||||||||
| 2177 | |||||||||||
| 2178 | Parameter Description | ||||||||||
| 2179 | 1 @parameters Parameters | ||||||||||
| 2180 | |||||||||||
| 2181 | =head2 ClassifyWhiteSpace(@parameters) | ||||||||||
| 2182 | |||||||||||
| 2183 | Classify white space per: "lib/Unisyn/whiteSpace/whiteSpaceClassification.pl" | ||||||||||
| 2184 | |||||||||||
| 2185 | Parameter Description | ||||||||||
| 2186 | 1 @parameters Parameters | ||||||||||
| 2187 | |||||||||||
| 2188 | =head2 T($key, $expected, $countComments) | ||||||||||
| 2189 | |||||||||||
| 2190 | Test a parse | ||||||||||
| 2191 | |||||||||||
| 2192 | Parameter Description | ||||||||||
| 2193 | 1 $key Key of text to be parsed | ||||||||||
| 2194 | 2 $expected Expected result | ||||||||||
| 2195 | 3 $countComments Optionally print most frequent comments to locate most generated code | ||||||||||
| 2196 | |||||||||||
| 2197 | |||||||||||
| 2198 | =head1 Index | ||||||||||
| 2199 | |||||||||||
| 2200 | |||||||||||
| 2201 | 1 L<accept_a|/accept_a> - Assign | ||||||||||
| 2202 | |||||||||||
| 2203 | 2 L<accept_B|/accept_B> - Closing parenthesis | ||||||||||
| 2204 | |||||||||||
| 2205 | 3 L<accept_b|/accept_b> - Open | ||||||||||
| 2206 | |||||||||||
| 2207 | 4 L<accept_d|/accept_d> - Infix but not assign or semi-colon | ||||||||||
| 2208 | |||||||||||
| 2209 | 5 L<accept_p|/accept_p> - Prefix | ||||||||||
| 2210 | |||||||||||
| 2211 | 6 L<accept_q|/accept_q> - Post fix | ||||||||||
| 2212 | |||||||||||
| 2213 | 7 L<accept_s|/accept_s> - Semi colon | ||||||||||
| 2214 | |||||||||||
| 2215 | 8 L<accept_v|/accept_v> - Variable | ||||||||||
| 2216 | |||||||||||
| 2217 | 9 L<checkSet|/checkSet> - Check that one of a set of items is on the top of the stack or complain if it is not | ||||||||||
| 2218 | |||||||||||
| 2219 | 10 L<checkStackHas|/checkStackHas> - Check that we have at least the specified number of elements on the stack | ||||||||||
| 2220 | |||||||||||
| 2221 | 11 L<ClassifyNewLines|/ClassifyNewLines> - Scan input string looking for opportunities to convert new lines into semi colons | ||||||||||
| 2222 | |||||||||||
| 2223 | 12 L<ClassifyWhiteSpace|/ClassifyWhiteSpace> - Classify white space per: "lib/Unisyn/whiteSpace/whiteSpaceClassification. | ||||||||||
| 2224 | |||||||||||
| 2225 | 13 L<error|/error> - Die | ||||||||||
| 2226 | |||||||||||
| 2227 | 14 L<getAlpha|/getAlpha> - Load the position of a lexical item in its alphabet from the current character | ||||||||||
| 2228 | |||||||||||
| 2229 | 15 L<getLexicalCode|/getLexicalCode> - Load the lexical code of the current character in memory into the specified register. | ||||||||||
| 2230 | |||||||||||
| 2231 | 16 L<lexicalNameFromLetter|/lexicalNameFromLetter> - Lexical name for a lexical item described by its letter | ||||||||||
| 2232 | |||||||||||
| 2233 | 17 L<lexicalNumberFromLetter|/lexicalNumberFromLetter> - Lexical number for a lexical item described by its letter | ||||||||||
| 2234 | |||||||||||
| 2235 | 18 L<loadCurrentChar|/loadCurrentChar> - Load the details of the character currently being processed so that we have the index of the character in the upper half of the current character and the lexical type of the character in the lowest byte | ||||||||||
| 2236 | |||||||||||
| 2237 | 19 L<MatchBrackets|/MatchBrackets> - Replace the low three bytes of a utf32 bracket character with 24 bits of offset to the matching opening or closing bracket. | ||||||||||
| 2238 | |||||||||||
| 2239 | 20 L<new|/new> - Create a new term | ||||||||||
| 2240 | |||||||||||
| 2241 | 21 L<new2|/new2> - Create a new term in the parse tree rooted on the stack. | ||||||||||
| 2242 | |||||||||||
| 2243 | 22 L<parseExpression|/parseExpression> - Create a parser for an expression described by variables | ||||||||||
| 2244 | |||||||||||
| 2245 | 23 L<parseExpressionCode|/parseExpressionCode> - Parse the string of classified lexical items addressed by register $start of length $length. | ||||||||||
| 2246 | |||||||||||
| 2247 | 24 L<parseUtf8|/parseUtf8> - Parse a unisyn expression encoded as utf8 | ||||||||||
| 2248 | |||||||||||
| 2249 | 25 L<printParseTree|/printParseTree> - Print the parse tree addressed by r15 | ||||||||||
| 2250 | |||||||||||
| 2251 | 26 L<pushElement|/pushElement> - Push the current element on to the stack | ||||||||||
| 2252 | |||||||||||
| 2253 | 27 L<pushEmpty|/pushEmpty> - Push the empty element on to the stack | ||||||||||
| 2254 | |||||||||||
| 2255 | 28 L<putLexicalCode|/putLexicalCode> - Put the specified lexical code into the current character in memory. | ||||||||||
| 2256 | |||||||||||
| 2257 | 29 L<reduce|/reduce> - Convert the longest possible expression on top of the stack into a term at the specified priority | ||||||||||
| 2258 | |||||||||||
| 2259 | 30 L<reduceMultiple|/reduceMultiple> - Reduce existing operators on the stack | ||||||||||
| 2260 | |||||||||||
| 2261 | 31 L<T|/T> - Test a parse | ||||||||||
| 2262 | |||||||||||
| 2263 | 32 L<testSet|/testSet> - Test a set of items, setting the Zero Flag is one matches else clear the Zero flag | ||||||||||
| 2264 | |||||||||||
| 2265 | =head1 Installation | ||||||||||
| 2266 | |||||||||||
| 2267 | This module is written in 100% Pure Perl and, thus, it is easy to read, | ||||||||||
| 2268 | comprehend, use, modify and install via B<cpan>: | ||||||||||
| 2269 | |||||||||||
| 2270 | sudo cpan install Unisyn::Parse | ||||||||||
| 2271 | |||||||||||
| 2272 | =head1 Author | ||||||||||
| 2273 | |||||||||||
| 2274 | L<philiprbrenan@gmail.com|mailto:philiprbrenan@gmail.com> | ||||||||||
| 2275 | |||||||||||
| 2276 | L<http://www.appaapps.com|http://www.appaapps.com> | ||||||||||
| 2277 | |||||||||||
| 2278 | =head1 Copyright | ||||||||||
| 2279 | |||||||||||
| 2280 | Copyright (c) 2016-2021 Philip R Brenan. | ||||||||||
| 2281 | |||||||||||
| 2282 | This module is free software. It may be used, redistributed and/or modified | ||||||||||
| 2283 | under the same terms as Perl itself. | ||||||||||
| 2284 | |||||||||||
| 2285 | =cut | ||||||||||
| 2286 | |||||||||||
| 2287 | |||||||||||
| 2288 | |||||||||||
| 2289 | # Tests and documentation | ||||||||||
| 2290 | |||||||||||
| 2291 | sub test | ||||||||||
| 2292 | {my $p = __PACKAGE__; | ||||||||||
| 2293 | binmode($_, ":utf8") for *STDOUT, *STDERR; | ||||||||||
| 2294 | return if eval "eof(${p}::DATA)"; | ||||||||||
| 2295 | my $s = eval "join('', <${p}::DATA>)"; | ||||||||||
| 2296 | $@ and die $@; | ||||||||||
| 2297 | eval $s; | ||||||||||
| 2298 | $@ and die $@; | ||||||||||
| 2299 | 1 | ||||||||||
| 2300 | } | ||||||||||
| 2301 | |||||||||||
| 2302 | test unless caller; | ||||||||||
| 2303 | |||||||||||
| 2304 | 1; | ||||||||||
| 2305 | # podDocumentation | ||||||||||
| 2306 | __DATA__ | ||||||||||