Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bc: array name versus digits * Array names are allowed to contain numeric digits but cannot start with a digit: ary2 is valid but 2ary is not * Assigning then fetching an array value didn't work as expected * I got a hint when adding debug statement to the =P instruction: "name[[]] idx[] varName[ary2[]1] at bc.y line 982, <STDIN> line 2." * The regex did not match because varName is "ary2[]1"; the regex expected that a digit would only be found after the "[]" substring * Make the code more correct by splitting on "[]" to get the array name "ary2" and the index of "1" * varName string is built earlier by the P instruction %perl bc -d # before patch ary2[0] = 1 instruction: N, 0 instruction: N, 1 instruction: P, ary2 instruction: =P ary2[0] instruction: N, 0 instruction: p, ary2 0 * bc: fix implicit print * When looping, setting $return=1 in =v instruction caused the loop to terminate early * Example input: for (i=1; i<10; i++) print i * Instead, take a hint from FOR-COND instruction and set $return=3 for suppressing print * This allows the simple statement "x=1" to not print * Apply the same to =P instruction, where the $return=1 code was copied from * no implicit print for "break" * Set $return=1 in BREAK instruction to match RETURN * In a loop with nested break, this stops the break from printing 0 * Example input: for ( v=0; v<5; v++) { print v; if (v>2) break }; print "\n"
- Loading branch information