summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/brainfuck/brainfuck.cr2
-rw-r--r--src/flint.cr55
2 files changed, 53 insertions, 4 deletions
diff --git a/src/brainfuck/brainfuck.cr b/src/brainfuck/brainfuck.cr
index 25f3bdf..78c504c 100644
--- a/src/brainfuck/brainfuck.cr
+++ b/src/brainfuck/brainfuck.cr
@@ -1,6 +1,8 @@
require "./*"
module Brainfuck
+ DEFAULT_TAPE_SIZE = 30_000
+
enum Opcode
PtrRight
PtrLeft
diff --git a/src/flint.cr b/src/flint.cr
index 271c39f..39d8363 100644
--- a/src/flint.cr
+++ b/src/flint.cr
@@ -1,5 +1,7 @@
# TODO: Write documentation for `Flint`
+require "option_parser"
+
require "./brainfuck/*"
require "./brainfuck/parser.cr"
@@ -7,10 +9,55 @@ module Flint
VERSION = "0.1.0"
def self.main
- puts "Hello world!"
- parser = Brainfuck::Parser.new
- puts parser
- puts Brainfuck::Opcode::PtrRight
+ execution_mode = :interpret
+ chosen_language = nil
+ memory_size = nil
+ source_file = nil
+
+ parser = OptionParser.new do |parser|
+ parser.banner = "Basic usage: flint [LANGUAGE] [OPTIONS] [FILE]"
+
+ parser.on("brainfuck", "select brainfuck as the language") do
+ chosen_language = :brainfuck
+ memory_size = Brainfuck::DEFAULT_TAPE_SIZE
+
+ parser.banner = "Useage: flint brainfuck [OPTIONS] [FILE]"
+ parser.on("-t CELLS", "--tape-size=CELLS", "specify the number of memory cells in the tape, defaults to 30,000") { nil }
+ end
+
+ parser.on("-h", "--help", "show this help and exit") do
+ puts parser
+ exit(0)
+ end
+ parser.on("-i", "--interpet", "interpet the provided source code, implied by default, overridden by '-c' or '--compile'") { nil }
+ parser.on("-c", "--compile", "produce a binary or different source code file instead of interpeting the code, overrides an explicit '-i' or '--intepret' flag") do
+ execution_mode = :compile
+ end
+
+ parser.unknown_args do |_args|
+ source_file = _args[0] unless _args.empty?
+ end
+ end
+
+ parser.parse
+
+ if chosen_language.nil?
+ puts "ERROR: No language chosen"
+ puts parser
+ exit(1)
+ end
+
+ if source_file.nil?
+ puts "ERROR: No source file chosen"
+ puts parser
+ exit(1)
+ end
+
+ # temporary
+ puts execution_mode
+ puts chosen_language
+ puts memory_size
+ puts source_file
end
end