basic101 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.simplecov +1 -0
- data/.yardopts +7 -0
- data/Changelog.md +3 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +75 -0
- data/LICENSE.md +9 -0
- data/README.md +193 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/bin/basic101 +10 -0
- data/lib/basic101/abs_function.rb +19 -0
- data/lib/basic101/argument_checker.rb +61 -0
- data/lib/basic101/arguments.rb +32 -0
- data/lib/basic101/array_reference.rb +52 -0
- data/lib/basic101/asc_function.rb +17 -0
- data/lib/basic101/basic_array.rb +69 -0
- data/lib/basic101/basic_comparisons.rb +20 -0
- data/lib/basic101/basic_float.rb +48 -0
- data/lib/basic101/basic_integer.rb +48 -0
- data/lib/basic101/basic_math.rb +22 -0
- data/lib/basic101/basic_numeric.rb +96 -0
- data/lib/basic101/basic_object.rb +35 -0
- data/lib/basic101/basic_string.rb +85 -0
- data/lib/basic101/binary_operation.rb +32 -0
- data/lib/basic101/binary_operations.rb +26 -0
- data/lib/basic101/built_in_functions.rb +31 -0
- data/lib/basic101/chr_function.rb +17 -0
- data/lib/basic101/cos_function.rb +17 -0
- data/lib/basic101/data_statement.rb +24 -0
- data/lib/basic101/define_function_statement.rb +23 -0
- data/lib/basic101/dim_statement.rb +25 -0
- data/lib/basic101/else_statement.rb +22 -0
- data/lib/basic101/end_statement.rb +13 -0
- data/lib/basic101/endif_statement.rb +19 -0
- data/lib/basic101/errors.rb +50 -0
- data/lib/basic101/exp_function.rb +17 -0
- data/lib/basic101/for_stack.rb +48 -0
- data/lib/basic101/for_statement.rb +57 -0
- data/lib/basic101/function.rb +11 -0
- data/lib/basic101/function_call.rb +32 -0
- data/lib/basic101/function_identifier.rb +8 -0
- data/lib/basic101/functions.rb +39 -0
- data/lib/basic101/gosub_statement.rb +23 -0
- data/lib/basic101/goto_statement.rb +23 -0
- data/lib/basic101/identifier.rb +23 -0
- data/lib/basic101/identity.rb +18 -0
- data/lib/basic101/if_statement.rb +31 -0
- data/lib/basic101/input.rb +44 -0
- data/lib/basic101/input_reader.rb +55 -0
- data/lib/basic101/input_statement.rb +46 -0
- data/lib/basic101/int_function.rb +17 -0
- data/lib/basic101/left_function.rb +19 -0
- data/lib/basic101/len_function.rb +18 -0
- data/lib/basic101/let_statement.rb +24 -0
- data/lib/basic101/line.rb +32 -0
- data/lib/basic101/log_function.rb +17 -0
- data/lib/basic101/main.rb +24 -0
- data/lib/basic101/mid_function.rb +20 -0
- data/lib/basic101/negate_operation.rb +21 -0
- data/lib/basic101/next_statement.rb +34 -0
- data/lib/basic101/not_operation.rb +23 -0
- data/lib/basic101/null_prompt_delimeter.rb +12 -0
- data/lib/basic101/null_transcript.rb +20 -0
- data/lib/basic101/numeric_identifier.rb +16 -0
- data/lib/basic101/on_goto_statement.rb +29 -0
- data/lib/basic101/output.rb +73 -0
- data/lib/basic101/parser.rb +457 -0
- data/lib/basic101/power_operation.rb +24 -0
- data/lib/basic101/print_comma.rb +20 -0
- data/lib/basic101/print_semicolon.rb +19 -0
- data/lib/basic101/print_statement.rb +33 -0
- data/lib/basic101/program.rb +100 -0
- data/lib/basic101/program_counter.rb +52 -0
- data/lib/basic101/prompt_delimeter.rb +13 -0
- data/lib/basic101/randomize_statement.rb +13 -0
- data/lib/basic101/read_statement.rb +25 -0
- data/lib/basic101/reference.rb +25 -0
- data/lib/basic101/remark_statement.rb +12 -0
- data/lib/basic101/restore_statement.rb +23 -0
- data/lib/basic101/return_statement.rb +16 -0
- data/lib/basic101/right_function.rb +19 -0
- data/lib/basic101/rnd_function.rb +24 -0
- data/lib/basic101/runtime.rb +132 -0
- data/lib/basic101/scalar_reference.rb +19 -0
- data/lib/basic101/sgn_function.rb +17 -0
- data/lib/basic101/sin_function.rb +17 -0
- data/lib/basic101/sqr_function.rb +17 -0
- data/lib/basic101/statement.rb +36 -0
- data/lib/basic101/stop_statement.rb +14 -0
- data/lib/basic101/str_function.rb +16 -0
- data/lib/basic101/string_identifier.rb +16 -0
- data/lib/basic101/tab.rb +18 -0
- data/lib/basic101/tab_function.rb +17 -0
- data/lib/basic101/tan_function.rb +17 -0
- data/lib/basic101/transcript.rb +37 -0
- data/lib/basic101/transform.rb +264 -0
- data/lib/basic101/user_defined_function.rb +54 -0
- data/lib/basic101/val_function.rb +16 -0
- data/lib/basic101.rb +93 -0
- data/rake_tasks/default.rake +1 -0
- data/rake_tasks/integration.rake +8 -0
- data/rake_tasks/jeweler.rake +28 -0
- data/rake_tasks/spec.rake +8 -0
- data/rake_tasks/test.rake +2 -0
- data/rake_tasks/yard.rake +3 -0
- data/test/integration/arguments.rb +25 -0
- data/test/integration/errors.rb +7 -0
- data/test/integration/integration_test.rb +28 -0
- data/test/integration/main.rb +49 -0
- data/test/integration/output_file.rb +40 -0
- data/test/integration/test.rb +135 -0
- data/test/integration/tests/basic_computer_games/23-match.bas +64 -0
- data/test/integration/tests/basic_computer_games/23-match.input +1 -0
- data/test/integration/tests/basic_computer_games/23-match.output +29 -0
- data/test/integration/tests/basic_computer_games/3dplot.bas +17 -0
- data/test/integration/tests/basic_computer_games/3dplot.input +0 -0
- data/test/integration/tests/basic_computer_games/3dplot.output +47 -0
- data/test/integration/tests/basic_computer_games/aceyducy.bas +100 -0
- data/test/integration/tests/basic_computer_games/aceyducy.input +8 -0
- data/test/integration/tests/basic_computer_games/aceyducy.output +78 -0
- data/test/integration/tests/basic_computer_games/amazing.bas +138 -0
- data/test/integration/tests/basic_computer_games/amazing.input +1 -0
- data/test/integration/tests/basic_computer_games/amazing.output +32 -0
- data/test/integration/tests/basic_computer_games/animal.bas +71 -0
- data/test/integration/tests/basic_computer_games/animal.input +17 -0
- data/test/integration/tests/basic_computer_games/animal.output +38 -0
- data/test/integration/tests/basic_computer_games/awari.bas +70 -0
- data/test/integration/tests/basic_computer_games/awari.input +11 -0
- data/test/integration/tests/basic_computer_games/awari.output +117 -0
- data/test/integration/tests/basic_computer_games/bagels.bas +81 -0
- data/test/integration/tests/basic_computer_games/bagels.input +12 -0
- data/test/integration/tests/basic_computer_games/bagels.output +42 -0
- data/test/integration/tests/basic_computer_games/banner.bas +94 -0
- data/test/integration/tests/basic_computer_games/banner.input +6 -0
- data/test/integration/tests/basic_computer_games/banner.output +135 -0
- data/test/integration/tests/basic_computer_games/basketbl.bas +196 -0
- data/test/integration/tests/basic_computer_games/basketbl.input +46 -0
- data/test/integration/tests/basic_computer_games/basketbl.output +509 -0
- data/test/integration/tests/basic_computer_games/batnum.bas +90 -0
- data/test/integration/tests/basic_computer_games/batnum.input +14 -0
- data/test/integration/tests/basic_computer_games/batnum.output +67 -0
- data/test/integration/tests/basic_computer_games/battle.bas +196 -0
- data/test/integration/tests/basic_computer_games/battle.input +21 -0
- data/test/integration/tests/basic_computer_games/battle.output +118 -0
- data/test/integration/tests/basic_computer_games/blackjck.bas +321 -0
- data/test/integration/tests/basic_computer_games/blackjck.input +26 -0
- data/test/integration/tests/basic_computer_games/blackjck.output +144 -0
- data/test/integration/tests/basic_computer_games/bombard.bas +93 -0
- data/test/integration/tests/basic_computer_games/bombard.input +20 -0
- data/test/integration/tests/basic_computer_games/bombard.output +175 -0
- data/test/integration/tests/basic_computer_games/bounce.bas +53 -0
- data/test/integration/tests/basic_computer_games/bounce.input +0 -0
- data/test/integration/tests/basic_computer_games/bounce.output +15 -0
- data/test/integration/tests/basic_computer_games/bowling.bas +101 -0
- data/test/integration/tests/basic_computer_games/bowling.input +23 -0
- data/test/integration/tests/basic_computer_games/bowling.output +229 -0
- data/test/integration/tests/basic_computer_games/boxing.bas +142 -0
- data/test/integration/tests/basic_computer_games/boxing.input +8 -0
- data/test/integration/tests/basic_computer_games/boxing.output +47 -0
- data/test/integration/tests/basic_computer_games/bug.bas +256 -0
- data/test/integration/tests/basic_computer_games/bug.input +17 -0
- data/test/integration/tests/basic_computer_games/bug.output +847 -0
- data/test/integration/tests/basic_computer_games/bullfght.bas +193 -0
- data/test/integration/tests/basic_computer_games/bullfght.input +4 -0
- data/test/integration/tests/basic_computer_games/bullfght.output +60 -0
- data/test/integration/tests/basic_computer_games/bullseye.bas +37 -0
- data/test/integration/tests/basic_computer_games/bullseye.input +10 -0
- data/test/integration/tests/basic_computer_games/bullseye.output +79 -0
- data/test/integration/tests/basic_computer_games/bunny.bas +40 -0
- data/test/integration/tests/basic_computer_games/bunny.input +0 -0
- data/test/integration/tests/basic_computer_games/bunny.output +67 -0
- data/test/integration/tests/basic_computer_games/buzzword.bas +25 -0
- data/test/integration/tests/basic_computer_games/buzzword.input +4 -0
- data/test/integration/tests/basic_computer_games/buzzword.output +25 -0
- data/test/integration/tests/basic_computer_games/calendar.bas +58 -0
- data/test/integration/tests/basic_computer_games/calendar.input +0 -0
- data/test/integration/tests/basic_computer_games/calendar.output +213 -0
- data/test/integration/tests/basic_computer_games/change.bas +51 -0
- data/test/integration/tests/basic_computer_games/change.input +4 -0
- data/test/integration/tests/basic_computer_games/change.output +28 -0
- data/test/integration/tests/basic_computer_games/checkers.bas +82 -0
- data/test/integration/tests/basic_computer_games/checkers.input +74 -0
- data/test/integration/tests/basic_computer_games/checkers.output +673 -0
- data/test/integration/tests/basic_computer_games/chemist.bas +27 -0
- data/test/integration/tests/basic_computer_games/chemist.input +11 -0
- data/test/integration/tests/basic_computer_games/chemist.output +54 -0
- data/test/integration/tests/basic_computer_games/chief.bas +51 -0
- data/test/integration/tests/basic_computer_games/chief.input +5 -0
- data/test/integration/tests/basic_computer_games/chief.output +19 -0
- data/test/integration/tests/basic_computer_games/chomp.bas +104 -0
- data/test/integration/tests/basic_computer_games/chomp.input +15 -0
- data/test/integration/tests/basic_computer_games/chomp.output +159 -0
- data/test/integration/tests/basic_computer_games/combat.bas +124 -0
- data/test/integration/tests/basic_computer_games/combat.input +7 -0
- data/test/integration/tests/basic_computer_games/combat.output +33 -0
- data/test/integration/tests/basic_computer_games/craps.bas +82 -0
- data/test/integration/tests/basic_computer_games/craps.input +9 -0
- data/test/integration/tests/basic_computer_games/craps.output +51 -0
- data/test/integration/tests/basic_computer_games/cube.bas +161 -0
- data/test/integration/tests/basic_computer_games/cube.input +25 -0
- data/test/integration/tests/basic_computer_games/cube.output +72 -0
- data/test/integration/tests/basic_computer_games/depthchg.bas +33 -0
- data/test/integration/tests/basic_computer_games/depthchg.input +16 -0
- data/test/integration/tests/basic_computer_games/depthchg.output +83 -0
- data/test/integration/tests/basic_computer_games/diamond.bas +27 -0
- data/test/integration/tests/basic_computer_games/diamond.input +1 -0
- data/test/integration/tests/basic_computer_games/diamond.output +65 -0
- data/test/integration/tests/basic_computer_games/dice.bas +31 -0
- data/test/integration/tests/basic_computer_games/dice.input +4 -0
- data/test/integration/tests/basic_computer_games/dice.output +46 -0
- data/test/integration/tests/basic_computer_games/digits.bas +78 -0
- data/test/integration/tests/basic_computer_games/digits.input +5 -0
- data/test/integration/tests/basic_computer_games/digits.output +70 -0
- data/test/integration/tests/basic_computer_games/evenwin1.bas +128 -0
- data/test/integration/tests/basic_computer_games/evenwin1.input +13 -0
- data/test/integration/tests/basic_computer_games/evenwin1.output +116 -0
- data/test/integration/tests/basic_computer_games/evenwin2.bas +70 -0
- data/test/integration/tests/basic_computer_games/evenwin2.input +14 -0
- data/test/integration/tests/basic_computer_games/evenwin2.output +56 -0
- data/test/integration/tests/basic_computer_games/flipflop.bas +79 -0
- data/test/integration/tests/basic_computer_games/flipflop.input +8 -0
- data/test/integration/tests/basic_computer_games/flipflop.output +45 -0
- data/test/integration/tests/basic_computer_games/footbal1.bas +298 -0
- data/test/integration/tests/basic_computer_games/footbal1.input +13 -0
- data/test/integration/tests/basic_computer_games/footbal1.output +315 -0
- data/test/integration/tests/basic_computer_games/footbal2.bas +181 -0
- data/test/integration/tests/basic_computer_games/footbal2.input +23 -0
- data/test/integration/tests/basic_computer_games/footbal2.output +318 -0
- data/test/integration/tests/basic_computer_games/furtradr.bas +170 -0
- data/test/integration/tests/basic_computer_games/furtradr.input +20 -0
- data/test/integration/tests/basic_computer_games/furtradr.output +133 -0
- data/test/integration/tests/basic_computer_games/golf.bas +244 -0
- data/test/integration/tests/basic_computer_games/golf.input +11 -0
- data/test/integration/tests/basic_computer_games/golf.output +69 -0
- data/test/integration/tests/basic_computer_games/gomoko.bas +54 -0
- data/test/integration/tests/basic_computer_games/gomoko.input +6 -0
- data/test/integration/tests/basic_computer_games/gomoko.output +66 -0
- data/test/integration/tests/basic_computer_games/guess.bas +40 -0
- data/test/integration/tests/basic_computer_games/guess.input +8 -0
- data/test/integration/tests/basic_computer_games/guess.output +37 -0
- data/test/integration/tests/basic_computer_games/gunner.bas +52 -0
- data/test/integration/tests/basic_computer_games/gunner.input +18 -0
- data/test/integration/tests/basic_computer_games/gunner.output +91 -0
- data/test/integration/tests/basic_computer_games/hamurabi.bas +119 -0
- data/test/integration/tests/basic_computer_games/hamurabi.input +7 -0
- data/test/integration/tests/basic_computer_games/hamurabi.output +51 -0
- data/test/integration/tests/basic_computer_games/hangman.bas +81 -0
- data/test/integration/tests/basic_computer_games/hangman.input +69 -0
- data/test/integration/tests/basic_computer_games/hangman.output +889 -0
- data/test/integration/tests/basic_computer_games/hello.bas +83 -0
- data/test/integration/tests/basic_computer_games/hello.input +7 -0
- data/test/integration/tests/basic_computer_games/hello.output +46 -0
- data/test/integration/tests/basic_computer_games/hexapawn.bas +174 -0
- data/test/integration/tests/basic_computer_games/hexapawn.input +38 -0
- data/test/integration/tests/basic_computer_games/hexapawn.output +521 -0
- data/test/integration/tests/basic_computer_games/hi-q.bas +135 -0
- data/test/integration/tests/basic_computer_games/hi-q.input +14 -0
- data/test/integration/tests/basic_computer_games/hi-q.output +115 -0
- data/test/integration/tests/basic_computer_games/hilo.bas +29 -0
- data/test/integration/tests/basic_computer_games/hilo.input +20 -0
- data/test/integration/tests/basic_computer_games/hilo.output +76 -0
- data/test/integration/tests/basic_computer_games/hockey.bas +210 -0
- data/test/integration/tests/basic_computer_games/hockey.input +59 -0
- data/test/integration/tests/basic_computer_games/hockey.output +243 -0
- data/test/integration/tests/basic_computer_games/horsrace.bas +130 -0
- data/test/integration/tests/basic_computer_games/horsrace.input +11 -0
- data/test/integration/tests/basic_computer_games/horsrace.output +517 -0
- data/test/integration/tests/basic_computer_games/hurkle.bas +51 -0
- data/test/integration/tests/basic_computer_games/hurkle.input +16 -0
- data/test/integration/tests/basic_computer_games/hurkle.output +81 -0
- data/test/integration/tests/basic_computer_games/kinema.bas +34 -0
- data/test/integration/tests/basic_computer_games/kinema.input +9 -0
- data/test/integration/tests/basic_computer_games/kinema.output +64 -0
- data/test/integration/tests/basic_computer_games/king.bas +268 -0
- data/test/integration/tests/basic_computer_games/king.input +7 -0
- data/test/integration/tests/basic_computer_games/king.output +57 -0
- data/test/integration/tests/basic_computer_games/lem.bas +246 -0
- data/test/integration/tests/basic_computer_games/lem.input +4 -0
- data/test/integration/tests/basic_computer_games/lem.output +68 -0
- data/test/integration/tests/basic_computer_games/letter.bas +26 -0
- data/test/integration/tests/basic_computer_games/letter.input +24 -0
- data/test/integration/tests/basic_computer_games/letter.output +123 -0
- data/test/integration/tests/basic_computer_games/life.bas +66 -0
- data/test/integration/tests/basic_computer_games/life.input +4 -0
- data/test/integration/tests/basic_computer_games/life.options +1 -0
- data/test/integration/tests/basic_computer_games/life.output +200 -0
- data/test/integration/tests/basic_computer_games/life2.bas +83 -0
- data/test/integration/tests/basic_computer_games/life2.input +17 -0
- data/test/integration/tests/basic_computer_games/life2.output +113 -0
- data/test/integration/tests/basic_computer_games/litquiz.bas +49 -0
- data/test/integration/tests/basic_computer_games/litquiz.input +4 -0
- data/test/integration/tests/basic_computer_games/litquiz.output +36 -0
- data/test/integration/tests/basic_computer_games/love.bas +34 -0
- data/test/integration/tests/basic_computer_games/love.input +1 -0
- data/test/integration/tests/basic_computer_games/love.output +67 -0
- data/test/integration/tests/basic_computer_games/lunar.bas +48 -0
- data/test/integration/tests/basic_computer_games/lunar.input +87 -0
- data/test/integration/tests/basic_computer_games/lunar.output +195 -0
- data/test/integration/tests/basic_computer_games/mastrmnd.bas +232 -0
- data/test/integration/tests/basic_computer_games/mastrmnd.input +18 -0
- data/test/integration/tests/basic_computer_games/mastrmnd.output +67 -0
- data/test/integration/tests/basic_computer_games/mathdice.bas +60 -0
- data/test/integration/tests/basic_computer_games/mathdice.input +4 -0
- data/test/integration/tests/basic_computer_games/mathdice.output +86 -0
- data/test/integration/tests/basic_computer_games/mugwump.bas +56 -0
- data/test/integration/tests/basic_computer_games/mugwump.input +16 -0
- data/test/integration/tests/basic_computer_games/mugwump.output +139 -0
- data/test/integration/tests/basic_computer_games/name.bas +25 -0
- data/test/integration/tests/basic_computer_games/name.input +2 -0
- data/test/integration/tests/basic_computer_games/name.output +22 -0
- data/test/integration/tests/basic_computer_games/nicoma.bas +34 -0
- data/test/integration/tests/basic_computer_games/nicoma.input +8 -0
- data/test/integration/tests/basic_computer_games/nicoma.output +36 -0
- data/test/integration/tests/basic_computer_games/nim.bas +156 -0
- data/test/integration/tests/basic_computer_games/nim.input +8 -0
- data/test/integration/tests/basic_computer_games/nim.output +30 -0
- data/test/integration/tests/basic_computer_games/number.bas +37 -0
- data/test/integration/tests/basic_computer_games/number.input +19 -0
- data/test/integration/tests/basic_computer_games/number.output +73 -0
- data/test/integration/tests/basic_computer_games/onecheck.bas +86 -0
- data/test/integration/tests/basic_computer_games/onecheck.input +6 -0
- data/test/integration/tests/basic_computer_games/onecheck.output +77 -0
- data/test/integration/tests/basic_computer_games/orbit.bas +96 -0
- data/test/integration/tests/basic_computer_games/orbit.input +10 -0
- data/test/integration/tests/basic_computer_games/orbit.output +113 -0
- data/test/integration/tests/basic_computer_games/pizza.bas +68 -0
- data/test/integration/tests/basic_computer_games/pizza.input +10 -0
- data/test/integration/tests/basic_computer_games/pizza.output +93 -0
- data/test/integration/tests/basic_computer_games/poetry.bas +42 -0
- data/test/integration/tests/basic_computer_games/poetry.input +0 -0
- data/test/integration/tests/basic_computer_games/poetry.options +1 -0
- data/test/integration/tests/basic_computer_games/poetry.output +50 -0
- data/test/integration/tests/basic_computer_games/poker.bas +416 -0
- data/test/integration/tests/basic_computer_games/poker.input +34 -0
- data/test/integration/tests/basic_computer_games/poker.output +197 -0
- data/test/integration/tests/basic_computer_games/queen.bas +168 -0
- data/test/integration/tests/basic_computer_games/queen.input +10 -0
- data/test/integration/tests/basic_computer_games/queen.output +133 -0
- data/test/integration/tests/basic_computer_games/reverse.bas +62 -0
- data/test/integration/tests/basic_computer_games/reverse.input +12 -0
- data/test/integration/tests/basic_computer_games/reverse.output +79 -0
- data/test/integration/tests/basic_computer_games/rocket.bas +71 -0
- data/test/integration/tests/basic_computer_games/rocket.input +42 -0
- data/test/integration/tests/basic_computer_games/rocket.output +149 -0
- data/test/integration/tests/basic_computer_games/rocksp.bas +33 -0
- data/test/integration/tests/basic_computer_games/rocksp.input +9 -0
- data/test/integration/tests/basic_computer_games/rocksp.output +69 -0
- data/test/integration/tests/basic_computer_games/roulette.bas +239 -0
- data/test/integration/tests/basic_computer_games/roulette.input +9 -0
- data/test/integration/tests/basic_computer_games/roulette.output +98 -0
- data/test/integration/tests/basic_computer_games/rusrou.bas +26 -0
- data/test/integration/tests/basic_computer_games/rusrou.input +9 -0
- data/test/integration/tests/basic_computer_games/rusrou.output +50 -0
- data/test/integration/tests/basic_computer_games/salvo.bas +329 -0
- data/test/integration/tests/basic_computer_games/salvo.input +21 -0
- data/test/integration/tests/basic_computer_games/salvo.output +49 -0
- data/test/integration/tests/basic_computer_games/sinewave.bas +17 -0
- data/test/integration/tests/basic_computer_games/sinewave.input +0 -0
- data/test/integration/tests/basic_computer_games/sinewave.output +168 -0
- data/test/integration/tests/basic_computer_games/slalom.bas +165 -0
- data/test/integration/tests/basic_computer_games/slalom.input +20 -0
- data/test/integration/tests/basic_computer_games/slalom.output +122 -0
- data/test/integration/tests/basic_computer_games/slots.bas +134 -0
- data/test/integration/tests/basic_computer_games/slots.input +2 -0
- data/test/integration/tests/basic_computer_games/slots.output +20 -0
- data/test/integration/tests/basic_computer_games/splat.bas +128 -0
- data/test/integration/tests/basic_computer_games/splat.input +9 -0
- data/test/integration/tests/basic_computer_games/splat.output +61 -0
- data/test/integration/tests/basic_computer_games/stars.bas +54 -0
- data/test/integration/tests/basic_computer_games/stars.input +15 -0
- data/test/integration/tests/basic_computer_games/stars.output +70 -0
- data/test/integration/tests/basic_computer_games/stock.bas +232 -0
- data/test/integration/tests/basic_computer_games/stock.input +30 -0
- data/test/integration/tests/basic_computer_games/stock.output +156 -0
- data/test/integration/tests/basic_computer_games/superstartrek.bas +425 -0
- data/test/integration/tests/basic_computer_games/superstartrek.input +21 -0
- data/test/integration/tests/basic_computer_games/superstartrek.output +151 -0
- data/test/integration/tests/basic_computer_games/superstartrekins.bas +127 -0
- data/test/integration/tests/basic_computer_games/superstartrekins.input +1 -0
- data/test/integration/tests/basic_computer_games/superstartrekins.output +134 -0
- data/test/integration/tests/basic_computer_games/synonym.bas +53 -0
- data/test/integration/tests/basic_computer_games/synonym.input +13 -0
- data/test/integration/tests/basic_computer_games/synonym.output +57 -0
- data/test/integration/tests/basic_computer_games/target.bas +51 -0
- data/test/integration/tests/basic_computer_games/target.input +2 -0
- data/test/integration/tests/basic_computer_games/target.output +39 -0
- data/test/integration/tests/basic_computer_games/tictac1.bas +69 -0
- data/test/integration/tests/basic_computer_games/tictac1.input +10 -0
- data/test/integration/tests/basic_computer_games/tictac1.output +49 -0
- data/test/integration/tests/basic_computer_games/tictac2.bas +114 -0
- data/test/integration/tests/basic_computer_games/tictac2.input +6 -0
- data/test/integration/tests/basic_computer_games/tictac2.output +104 -0
- data/test/integration/tests/basic_computer_games/towers.bas +125 -0
- data/test/integration/tests/basic_computer_games/towers.input +9 -0
- data/test/integration/tests/basic_computer_games/towers.output +70 -0
- data/test/integration/tests/basic_computer_games/train.bas +24 -0
- data/test/integration/tests/basic_computer_games/train.input +4 -0
- data/test/integration/tests/basic_computer_games/train.output +23 -0
- data/test/integration/tests/basic_computer_games/trap.bas +49 -0
- data/test/integration/tests/basic_computer_games/trap.input +7 -0
- data/test/integration/tests/basic_computer_games/trap.output +40 -0
- data/test/integration/tests/basic_computer_games/war.bas +68 -0
- data/test/integration/tests/basic_computer_games/war.input +11 -0
- data/test/integration/tests/basic_computer_games/war.output +54 -0
- data/test/integration/tests/basic_computer_games/weekday.bas +150 -0
- data/test/integration/tests/basic_computer_games/weekday.input +2 -0
- data/test/integration/tests/basic_computer_games/weekday.output +28 -0
- data/test/integration/tests/basic_computer_games/word.bas +65 -0
- data/test/integration/tests/basic_computer_games/word.input +6 -0
- data/test/integration/tests/basic_computer_games/word.output +0 -0
- data/test/integration/tests/fast/abs.bas +5 -0
- data/test/integration/tests/fast/abs.input +0 -0
- data/test/integration/tests/fast/abs.output +5 -0
- data/test/integration/tests/fast/add.bas +5 -0
- data/test/integration/tests/fast/add.input +0 -0
- data/test/integration/tests/fast/add.output +5 -0
- data/test/integration/tests/fast/and.bas +5 -0
- data/test/integration/tests/fast/and.input +0 -0
- data/test/integration/tests/fast/and.output +5 -0
- data/test/integration/tests/fast/array.bas +11 -0
- data/test/integration/tests/fast/array.input +0 -0
- data/test/integration/tests/fast/array.output +6 -0
- data/test/integration/tests/fast/asc.bas +1 -0
- data/test/integration/tests/fast/asc.input +0 -0
- data/test/integration/tests/fast/asc.output +1 -0
- data/test/integration/tests/fast/chr.bas +1 -0
- data/test/integration/tests/fast/chr.input +0 -0
- data/test/integration/tests/fast/chr.output +1 -0
- data/test/integration/tests/fast/cos.bas +1 -0
- data/test/integration/tests/fast/cos.input +0 -0
- data/test/integration/tests/fast/cos.output +1 -0
- data/test/integration/tests/fast/def_fn.bas +9 -0
- data/test/integration/tests/fast/def_fn.input +0 -0
- data/test/integration/tests/fast/def_fn.output +5 -0
- data/test/integration/tests/fast/divide.bas +5 -0
- data/test/integration/tests/fast/divide.input +0 -0
- data/test/integration/tests/fast/divide.output +5 -0
- data/test/integration/tests/fast/end.bas +3 -0
- data/test/integration/tests/fast/end.input +0 -0
- data/test/integration/tests/fast/end.output +1 -0
- data/test/integration/tests/fast/eq.bas +3 -0
- data/test/integration/tests/fast/eq.input +0 -0
- data/test/integration/tests/fast/eq.output +3 -0
- data/test/integration/tests/fast/exp.bas +2 -0
- data/test/integration/tests/fast/exp.input +0 -0
- data/test/integration/tests/fast/exp.output +2 -0
- data/test/integration/tests/fast/float.bas +3 -0
- data/test/integration/tests/fast/float.input +0 -0
- data/test/integration/tests/fast/float.output +2 -0
- data/test/integration/tests/fast/for_next.bas +61 -0
- data/test/integration/tests/fast/for_next.input +0 -0
- data/test/integration/tests/fast/for_next.output +46 -0
- data/test/integration/tests/fast/ge.bas +3 -0
- data/test/integration/tests/fast/ge.input +0 -0
- data/test/integration/tests/fast/ge.output +3 -0
- data/test/integration/tests/fast/gosub_return.bas +10 -0
- data/test/integration/tests/fast/gosub_return.input +0 -0
- data/test/integration/tests/fast/gosub_return.output +4 -0
- data/test/integration/tests/fast/goto.bas +3 -0
- data/test/integration/tests/fast/goto.input +0 -0
- data/test/integration/tests/fast/goto.output +1 -0
- data/test/integration/tests/fast/gt.bas +3 -0
- data/test/integration/tests/fast/gt.input +0 -0
- data/test/integration/tests/fast/gt.output +3 -0
- data/test/integration/tests/fast/if.bas +25 -0
- data/test/integration/tests/fast/if.input +0 -0
- data/test/integration/tests/fast/if.output +8 -0
- data/test/integration/tests/fast/input.bas +24 -0
- data/test/integration/tests/fast/input.input +10 -0
- data/test/integration/tests/fast/input.output +28 -0
- data/test/integration/tests/fast/int.bas +5 -0
- data/test/integration/tests/fast/int.input +0 -0
- data/test/integration/tests/fast/int.output +5 -0
- data/test/integration/tests/fast/integer_plus_string.bas +1 -0
- data/test/integration/tests/fast/integer_plus_string.input +0 -0
- data/test/integration/tests/fast/integer_plus_string.output +1 -0
- data/test/integration/tests/fast/invalid_argument.bas +1 -0
- data/test/integration/tests/fast/invalid_argument.input +0 -0
- data/test/integration/tests/fast/invalid_argument.output +1 -0
- data/test/integration/tests/fast/le.bas +3 -0
- data/test/integration/tests/fast/le.input +0 -0
- data/test/integration/tests/fast/le.output +3 -0
- data/test/integration/tests/fast/left.bas +1 -0
- data/test/integration/tests/fast/left.input +0 -0
- data/test/integration/tests/fast/left.output +1 -0
- data/test/integration/tests/fast/len.bas +2 -0
- data/test/integration/tests/fast/len.input +0 -0
- data/test/integration/tests/fast/len.output +2 -0
- data/test/integration/tests/fast/let.bas +6 -0
- data/test/integration/tests/fast/let.input +0 -0
- data/test/integration/tests/fast/let.output +4 -0
- data/test/integration/tests/fast/log.bas +1 -0
- data/test/integration/tests/fast/log.input +0 -0
- data/test/integration/tests/fast/log.output +1 -0
- data/test/integration/tests/fast/lt.bas +3 -0
- data/test/integration/tests/fast/lt.input +0 -0
- data/test/integration/tests/fast/lt.output +3 -0
- data/test/integration/tests/fast/math.output +0 -0
- data/test/integration/tests/fast/mid.bas +2 -0
- data/test/integration/tests/fast/mid.input +0 -0
- data/test/integration/tests/fast/mid.output +2 -0
- data/test/integration/tests/fast/multiply.bas +5 -0
- data/test/integration/tests/fast/multiply.input +0 -0
- data/test/integration/tests/fast/multiply.output +5 -0
- data/test/integration/tests/fast/ne.bas +3 -0
- data/test/integration/tests/fast/ne.input +0 -0
- data/test/integration/tests/fast/ne.output +3 -0
- data/test/integration/tests/fast/negate.bas +4 -0
- data/test/integration/tests/fast/negate.input +0 -0
- data/test/integration/tests/fast/negate.output +3 -0
- data/test/integration/tests/fast/not.bas +4 -0
- data/test/integration/tests/fast/not.input +0 -0
- data/test/integration/tests/fast/not.output +4 -0
- data/test/integration/tests/fast/on_goto.bas +6 -0
- data/test/integration/tests/fast/on_goto.input +0 -0
- data/test/integration/tests/fast/on_goto.output +2 -0
- data/test/integration/tests/fast/or.bas +5 -0
- data/test/integration/tests/fast/or.input +0 -0
- data/test/integration/tests/fast/or.output +5 -0
- data/test/integration/tests/fast/parentheses.bas +1 -0
- data/test/integration/tests/fast/parentheses.input +0 -0
- data/test/integration/tests/fast/parentheses.output +1 -0
- data/test/integration/tests/fast/power.bas +4 -0
- data/test/integration/tests/fast/power.input +0 -0
- data/test/integration/tests/fast/power.output +4 -0
- data/test/integration/tests/fast/print.bas +6 -0
- data/test/integration/tests/fast/print.input +0 -0
- data/test/integration/tests/fast/print.output +4 -0
- data/test/integration/tests/fast/read_data.bas +15 -0
- data/test/integration/tests/fast/read_data.input +0 -0
- data/test/integration/tests/fast/read_data.output +4 -0
- data/test/integration/tests/fast/rem.bas +1 -0
- data/test/integration/tests/fast/rem.input +0 -0
- data/test/integration/tests/fast/rem.output +0 -0
- data/test/integration/tests/fast/right.bas +1 -0
- data/test/integration/tests/fast/right.input +0 -0
- data/test/integration/tests/fast/right.output +1 -0
- data/test/integration/tests/fast/rnd.bas +5 -0
- data/test/integration/tests/fast/rnd.input +0 -0
- data/test/integration/tests/fast/rnd.output +5 -0
- data/test/integration/tests/fast/sgn.bas +5 -0
- data/test/integration/tests/fast/sgn.input +0 -0
- data/test/integration/tests/fast/sgn.output +5 -0
- data/test/integration/tests/fast/sin.bas +1 -0
- data/test/integration/tests/fast/sin.input +0 -0
- data/test/integration/tests/fast/sin.output +1 -0
- data/test/integration/tests/fast/sqr.bas +2 -0
- data/test/integration/tests/fast/sqr.input +0 -0
- data/test/integration/tests/fast/sqr.output +2 -0
- data/test/integration/tests/fast/stop.bas +3 -0
- data/test/integration/tests/fast/stop.input +0 -0
- data/test/integration/tests/fast/stop.output +2 -0
- data/test/integration/tests/fast/str.bas +3 -0
- data/test/integration/tests/fast/str.input +0 -0
- data/test/integration/tests/fast/str.output +3 -0
- data/test/integration/tests/fast/string_addition.bas +1 -0
- data/test/integration/tests/fast/string_addition.input +0 -0
- data/test/integration/tests/fast/string_addition.output +1 -0
- data/test/integration/tests/fast/string_comparisons.bas +7 -0
- data/test/integration/tests/fast/string_comparisons.input +0 -0
- data/test/integration/tests/fast/string_comparisons.output +4 -0
- data/test/integration/tests/fast/string_plus_integer.bas +1 -0
- data/test/integration/tests/fast/string_plus_integer.input +0 -0
- data/test/integration/tests/fast/string_plus_integer.output +1 -0
- data/test/integration/tests/fast/subtract.bas +5 -0
- data/test/integration/tests/fast/subtract.input +0 -0
- data/test/integration/tests/fast/subtract.output +5 -0
- data/test/integration/tests/fast/tab.bas +4 -0
- data/test/integration/tests/fast/tab.input +0 -0
- data/test/integration/tests/fast/tab.output +3 -0
- data/test/integration/tests/fast/tan.bas +1 -0
- data/test/integration/tests/fast/tan.input +0 -0
- data/test/integration/tests/fast/tan.output +1 -0
- data/test/integration/tests/fast/val.bas +3 -0
- data/test/integration/tests/fast/val.input +0 -0
- data/test/integration/tests/fast/val.output +3 -0
- data/test/spec/argument_checker_spec.rb +128 -0
- data/test/spec/basic_array_spec.rb +100 -0
- data/test/spec/basic_float_spec.rb +168 -0
- data/test/spec/basic_integer_spec.rb +270 -0
- data/test/spec/basic_numeric_spec.rb +16 -0
- data/test/spec/basic_object_spec.rb +22 -0
- data/test/spec/basic_string_spec.rb +259 -0
- data/test/spec/for_stack_spec.rb +70 -0
- data/test/spec/input_reader_spec.rb +143 -0
- data/test/spec/input_spec.rb +102 -0
- data/test/spec/line_spec.rb +18 -0
- data/test/spec/output_spec.rb +153 -0
- data/test/spec/parser_spec.rb +562 -0
- data/test/spec/program_spec.rb +45 -0
- data/test/spec/spec_helper.rb +15 -0
- data/test/spec/support/basic_numeric_helpers.rb +327 -0
- data/test/spec/support/basic_object_helpers.rb +22 -0
- data/test/spec/transcript_spec.rb +37 -0
- data/test/spec/transform_spec.rb +513 -0
- metadata +742 -0
@@ -0,0 +1,100 @@
|
|
1
|
+
module Basic101
|
2
|
+
|
3
|
+
class Program
|
4
|
+
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
include Identity
|
8
|
+
|
9
|
+
attr_reader :statements
|
10
|
+
|
11
|
+
def self.load_file(source_path)
|
12
|
+
File.open(source_path, 'r') do |file|
|
13
|
+
load(file)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.load(source_file)
|
18
|
+
source = source_file.read
|
19
|
+
parser = Parser.new
|
20
|
+
transform = Transform.new
|
21
|
+
tree = parser.parse(source)
|
22
|
+
transform.apply(tree)
|
23
|
+
rescue Parslet::ParseFailed => error
|
24
|
+
line_number, column_number =
|
25
|
+
error.cause.source.line_and_column(error.cause.pos)
|
26
|
+
line = source.lines[line_number - 1]
|
27
|
+
raise SyntaxError.new(line, line_number, column_number, error.message)
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(lines = [])
|
31
|
+
@statements = []
|
32
|
+
@line_number_index = {}
|
33
|
+
lines.each do |line|
|
34
|
+
@line_number_index[line.line_number] = @statements.size
|
35
|
+
@statements += line.statements
|
36
|
+
end
|
37
|
+
set_statement_indices
|
38
|
+
link_if_statements
|
39
|
+
end
|
40
|
+
|
41
|
+
def statement_count
|
42
|
+
@statements.size
|
43
|
+
end
|
44
|
+
|
45
|
+
def [](i)
|
46
|
+
@statements[i]
|
47
|
+
end
|
48
|
+
|
49
|
+
def index_of_line(line_number)
|
50
|
+
index = @line_number_index[line_number]
|
51
|
+
unless index
|
52
|
+
raise UndefinedLineNumberError, "Undefined line number #{line_number}"
|
53
|
+
end
|
54
|
+
index
|
55
|
+
end
|
56
|
+
|
57
|
+
def data_items(starting_line_number = nil)
|
58
|
+
if starting_line_number
|
59
|
+
statements = @statements.select do |statement|
|
60
|
+
statement.line_number >= starting_line_number
|
61
|
+
end
|
62
|
+
else
|
63
|
+
statements = @statements
|
64
|
+
end
|
65
|
+
statements.flat_map(&:data_items)
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
def state
|
71
|
+
[@statements]
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def link_if_statements
|
77
|
+
stack = []
|
78
|
+
@statements.each do |statement|
|
79
|
+
case statement
|
80
|
+
when IfStatement
|
81
|
+
stack.push statement
|
82
|
+
when ElseStatement
|
83
|
+
if_statement = stack.last
|
84
|
+
if_statement.else_statement = statement
|
85
|
+
when EndifStatement
|
86
|
+
if_statement = stack.pop
|
87
|
+
if_statement.end_statement = statement
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def set_statement_indices
|
93
|
+
@statements.each.with_index do |statement, i|
|
94
|
+
statement.index = i
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Basic101
|
2
|
+
|
3
|
+
class ProgramCounter
|
4
|
+
|
5
|
+
def initialize(program)
|
6
|
+
@program = program
|
7
|
+
@index = 0
|
8
|
+
@stack = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def goto_next_statement
|
12
|
+
@index += 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def end?
|
16
|
+
@index >= @program.statement_count
|
17
|
+
end
|
18
|
+
|
19
|
+
def goto_index(index)
|
20
|
+
@index = index
|
21
|
+
end
|
22
|
+
|
23
|
+
def goto_index_after(index)
|
24
|
+
goto_index(index + 1)
|
25
|
+
end
|
26
|
+
|
27
|
+
def goto_line(line_number)
|
28
|
+
goto_index @program.index_of_line(line_number)
|
29
|
+
end
|
30
|
+
|
31
|
+
def gosub_line(line_number)
|
32
|
+
@stack.push @index
|
33
|
+
goto_line line_number
|
34
|
+
end
|
35
|
+
|
36
|
+
def goto_end
|
37
|
+
@index = @program.statement_count + 1
|
38
|
+
end
|
39
|
+
|
40
|
+
def return
|
41
|
+
index = @stack.pop
|
42
|
+
raise ReturnWithoutGosub unless index
|
43
|
+
@index = index
|
44
|
+
end
|
45
|
+
|
46
|
+
def current_statement
|
47
|
+
@program[@index]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'statement'
|
2
|
+
|
3
|
+
module Basic101
|
4
|
+
|
5
|
+
class ReadStatement < Statement
|
6
|
+
|
7
|
+
def initialize(references)
|
8
|
+
@references = references
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(runtime)
|
12
|
+
@references.each do |reference|
|
13
|
+
reference.assign(runtime, runtime.get_data_item)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def state
|
20
|
+
@references
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'identity'
|
2
|
+
|
3
|
+
module Basic101
|
4
|
+
|
5
|
+
class Reference
|
6
|
+
|
7
|
+
include Identity
|
8
|
+
|
9
|
+
def initialize(identifier)
|
10
|
+
@identifier = identifier
|
11
|
+
end
|
12
|
+
|
13
|
+
def input(input_reader)
|
14
|
+
@identifier.input(input_reader)
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def state
|
20
|
+
[@identifier]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'statement'
|
2
|
+
|
3
|
+
module Basic101
|
4
|
+
|
5
|
+
class RestoreStatement < Statement
|
6
|
+
|
7
|
+
def initialize(line_number)
|
8
|
+
@line_number = line_number
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(runtime)
|
12
|
+
runtime.restore(@line_number.to_i)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def state
|
18
|
+
[@line_number]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Basic101
|
2
|
+
|
3
|
+
class RightFunction < Function
|
4
|
+
|
5
|
+
def name
|
6
|
+
'RIGHT$'
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(runtime, args)
|
10
|
+
check_args args, [BasicString, BasicNumeric]
|
11
|
+
string, count = *args
|
12
|
+
string = string.eval(runtime).to_string
|
13
|
+
count = count.eval(runtime).to_integer
|
14
|
+
string.right(count)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Basic101
|
2
|
+
|
3
|
+
class RndFunction < Function
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@rand = 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
'RND'
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(runtime, args)
|
14
|
+
check_args args, [BasicNumeric]
|
15
|
+
new_number = args.first.eval(runtime).to_f > 0
|
16
|
+
if new_number
|
17
|
+
@rand = runtime.rand
|
18
|
+
end
|
19
|
+
BasicFloat.new(@rand)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module Basic101
|
2
|
+
|
3
|
+
class Runtime
|
4
|
+
|
5
|
+
attr_reader :input
|
6
|
+
attr_reader :output
|
7
|
+
attr_reader :for_stack
|
8
|
+
|
9
|
+
def initialize(args = {})
|
10
|
+
@output = Output.new(args.fetch(:output_file, $stdout))
|
11
|
+
@input = Input.new(@output, args.fetch(:input_file, $stdin))
|
12
|
+
@program = args.fetch(:program, Program.new)
|
13
|
+
@functions = Functions.new
|
14
|
+
@for_stack = ForStack.new
|
15
|
+
@random = Random.new(0)
|
16
|
+
@transcript = NullTranscript.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def transcript=(transcript)
|
20
|
+
@transcript = transcript
|
21
|
+
@output.transcript = @transcript
|
22
|
+
@input.transcript = @transcript
|
23
|
+
end
|
24
|
+
|
25
|
+
def randomize
|
26
|
+
@random = Random.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def rand
|
30
|
+
@random.rand
|
31
|
+
end
|
32
|
+
|
33
|
+
def goto_line(line_number)
|
34
|
+
@program_counter.goto_line(line_number)
|
35
|
+
end
|
36
|
+
|
37
|
+
def gosub_line(line_number)
|
38
|
+
@program_counter.gosub_line(line_number)
|
39
|
+
end
|
40
|
+
|
41
|
+
def return
|
42
|
+
@program_counter.return
|
43
|
+
end
|
44
|
+
|
45
|
+
def goto_index(index)
|
46
|
+
@program_counter.goto_index(index)
|
47
|
+
end
|
48
|
+
|
49
|
+
def goto_index_after(index)
|
50
|
+
@program_counter.goto_index_after(index)
|
51
|
+
end
|
52
|
+
|
53
|
+
def end_program
|
54
|
+
@program_counter.goto_end
|
55
|
+
end
|
56
|
+
|
57
|
+
def run
|
58
|
+
transcribe_errors do
|
59
|
+
reset
|
60
|
+
begin
|
61
|
+
while !@program_counter.end?
|
62
|
+
statement = @program_counter.current_statement
|
63
|
+
begin
|
64
|
+
@program_counter.goto_next_statement
|
65
|
+
statement.execute(self)
|
66
|
+
rescue StandardError => e
|
67
|
+
statement.raise_error_with_line_number(e)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def transcribe_errors
|
75
|
+
begin
|
76
|
+
yield
|
77
|
+
rescue Parslet::ParseFailed => e
|
78
|
+
@transcript.save_output_lines e
|
79
|
+
raise
|
80
|
+
rescue Basic101::Error => e
|
81
|
+
@transcript.save_output_lines e
|
82
|
+
raise
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def function_exists?(identifier)
|
87
|
+
@functions.has_function?(identifier)
|
88
|
+
end
|
89
|
+
|
90
|
+
def call_function(identifier, argument_values)
|
91
|
+
@functions.call(self, identifier, argument_values)
|
92
|
+
end
|
93
|
+
|
94
|
+
def add_function(function)
|
95
|
+
@functions.add_function(function)
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_scalar(identifier)
|
99
|
+
@scalars[identifier.to_s] ||= BasicInteger.new(0)
|
100
|
+
end
|
101
|
+
|
102
|
+
def set_scalar(identifier, value)
|
103
|
+
@scalars[identifier.to_s] = value
|
104
|
+
end
|
105
|
+
|
106
|
+
def get_array(identifier, num_dimensions)
|
107
|
+
@arrays[identifier.to_s] ||=
|
108
|
+
BasicArray.new(num_dimensions, identifier.default)
|
109
|
+
end
|
110
|
+
|
111
|
+
def get_data_item
|
112
|
+
data_item = @data_items.shift
|
113
|
+
raise OutOfDataError unless data_item
|
114
|
+
data_item
|
115
|
+
end
|
116
|
+
|
117
|
+
def restore(line_number = nil)
|
118
|
+
@data_items = @program.data_items(line_number)
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def reset
|
124
|
+
@scalars = {}
|
125
|
+
@arrays = {}
|
126
|
+
@program_counter = ProgramCounter.new(@program)
|
127
|
+
restore
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Basic101
|
2
|
+
|
3
|
+
class ScalarReference < Reference
|
4
|
+
|
5
|
+
def eval(runtime)
|
6
|
+
if runtime.function_exists?(@identifier)
|
7
|
+
runtime.call_function(@identifier, [])
|
8
|
+
else
|
9
|
+
runtime.get_scalar(@identifier)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def assign(runtime, value)
|
14
|
+
runtime.set_scalar(@identifier, value)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'identity'
|
2
|
+
|
3
|
+
module Basic101
|
4
|
+
|
5
|
+
class Statement
|
6
|
+
|
7
|
+
include Identity
|
8
|
+
|
9
|
+
attr_writer :index
|
10
|
+
attr_writer :line
|
11
|
+
|
12
|
+
def raise_error_with_line_number(exception)
|
13
|
+
message = "Error on line #{@line.line_number}: #{exception}"
|
14
|
+
raise exception, message, exception.backtrace
|
15
|
+
end
|
16
|
+
|
17
|
+
def data_items
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
|
21
|
+
def line_number
|
22
|
+
@line.line_number
|
23
|
+
end
|
24
|
+
|
25
|
+
def exec(runtime)
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def state
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/lib/basic101/tab.rb
ADDED