all repos — min @ b3373bcf448301a1c575888dfba0981701998164

A small but practical concatenative programming language.

minim.nim

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
import streams, tables, parseopt2
import interpreter, primitives


const version* = "0.1.0"

let usage* = "  MiNiM v" & version & " - a minimalist concatenative programming language" & """

  (c) 2014 Fabio Cevasco
  
  Usage:
    minim [options] filename

  Arguments:
    filename  A minim file to interpret.
  Options:
    -e, --evaluate    Evaluate a minim program inline
    -h, --help        Print this help
    -v, --version     Print the program version"""

var file, str: string = ""

for kind, key, val in getopt():
  case kind:
    of cmdArgument:
      file = key
    of cmdLongOption, cmdShortOption:
      case key:
        of "evaluate", "e":
          str = val
        of "help", "h":
          echo usage
        of "version", "v":
          echo version
    else:
      discard

if str != "":
  minimString(str)
elif file != "":
  minimFile(file)
else:
  echo usage