etng-r2/calc.tng
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Wed, 16 Jan 2019 17:15:58 +0000
changeset 438 1fe179d53161
parent 285 034958cf32d9
permissions -rw-r--r--
Add missing primitive implementation for the plain interpreter.
define expr = {
  number:n1 "+" expr:n2 -> n1 + n2;
};

define number = {
  spaces digit+:digits -> digits |listToString |stringToNumber;
};

define token xs -> {
  spaces <{xs}>;
};

define digit = {
  c -> (charNumeric c) { .true -> c; .false -> error("expected", "charNumeric", c); };
};

spaces = {
  (c -> (charWhitespace c) { .true -> c; .false -> error("expected", "charWhitespace", c) };)+
    spaces;

  $- $- ...

  -> #t;
};


expr 1 + 2 + 3;