Skip to content

Commit

Permalink
add current_time_millis, _ as identifier char, and fix arity of < and <=
Browse files Browse the repository at this point in the history
  • Loading branch information
burakemir committed Aug 14, 2015
1 parent 8224982 commit 3ef776b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/interpreter.dart
Expand Up @@ -260,7 +260,9 @@ class InterpreterImpl extends InterpreterInterface {
return new ListNode.cons(result, nodes);
}
break;

case Primitive.CURRENT_TIME_MILLIS:
return new ListNode.cons(
new NumberNode.int(new DateTime.now().millisecondsSinceEpoch), nodes);
case Primitive.UNIT:
break;

Expand Down
8 changes: 5 additions & 3 deletions lib/nodes.dart
Expand Up @@ -261,6 +261,7 @@ class Primitive extends Node {
static const CLEARSCREEN = const Primitive(0, "cs", "clearscreen");
static const CLEARTEXT = const Primitive(0, "ct", "cleartext");
static const CONS = const Primitive(2, "_cons");
static const CURRENT_TIME_MILLIS = const Primitive(0, "current_time_millis");
static const SELECT = const Primitive(2, "#", "select");
static const DRAWTEXT = const Primitive(1, "drawtext");
static const EDALL = const Primitive(0, "edall");
Expand All @@ -278,8 +279,8 @@ class Primitive extends Node {
static const IFELSE = const Primitive(3, "ifelse");
static const ITEM = const Primitive(2, "item");
static const LEFT = const Primitive(1, "lt", "left");
static const LESSTHAN = const Primitive(1, "<", "lessthan");
static const LESSOREQUAL = const Primitive(1, "<=", "lessorequal");
static const LESSTHAN = const Primitive(2, "<", "lessthan");
static const LESSOREQUAL = const Primitive(2, "<=", "lessorequal");
static const LOCAL = const Primitive(1, "local");
static const LPUT = const Primitive(2, "lput");
static const DIFFERENCE = const Primitive(2, "-", "difference");
Expand Down Expand Up @@ -341,7 +342,8 @@ class Primitive extends Node {
SHOWTURTLE, STOP, TRACE, TURTLE_GET_STATE, UNTRACE ];

static const List<Primitive> operatorList = const [
APPLY, BUTFIRST, DIFFERENCE, SELECT, FALSE, FPUT, LESSOREQUAL, LESSTHAN, FIRST,
APPLY, BUTFIRST, CURRENT_TIME_MILLIS,
DIFFERENCE, SELECT, FALSE, FPUT, LESSOREQUAL, LESSTHAN, FIRST,
GPROP, GREATEROREQUAL,
GREATERTHAN, ITEM, LPUT, OUTPUT, PLIST, PRODUCT, QUOTE, QUOTIENT, POWER, PI,
REMAINDER,
Expand Down
16 changes: 10 additions & 6 deletions lib/parser.dart
Expand Up @@ -194,14 +194,18 @@ class Scanner {
static const int CHAR_NEWLINE = 10;
static const int CHAR_COLON = 58;
static const int CHAR_SEMI = 59;

static const int CHAR_UNDERSCORE = 95;

static bool isAlpha(int charCode) =>
(CHAR_a <= charCode && charCode <= CHAR_z)
|| (CHAR_A <= charCode && charCode <= CHAR_Z);

static bool isDigit(int charCode) =>
(CHAR_0 <= charCode && charCode <= CHAR_9);


static bool isUnderscore(int charCode) =>
CHAR_UNDERSCORE == charCode;

static bool isDigitOrDot(int charCode) =>
CHAR_DOT == charCode || isDigit(charCode);

Expand All @@ -215,8 +219,8 @@ class Scanner {
CHAR_BLANK == charCode || CHAR_TAB == charCode
|| CHAR_NEWLINE == charCode;

static bool isAlphaOrDigit(int charCode) =>
isAlpha(charCode) || isDigit(charCode);
static bool isAlphaOrDigitOrUnderscore(int charCode) =>
isAlpha(charCode) || isDigit(charCode) || isUnderscore(charCode);

static bool notNewLine(int charCode) =>
CHAR_NEWLINE != charCode;
Expand Down Expand Up @@ -281,7 +285,7 @@ class Scanner {
if (!isAlpha(text.codeUnitAt(pos))) {
throw new Exception("expected alphabetical");
}
advanceWhile(isAlphaOrDigit);
advanceWhile(isAlphaOrDigitOrUnderscore);
String word = text.substring(i, pos);
token.setVar(new WordNode(word));
}
Expand All @@ -306,7 +310,7 @@ class Scanner {
/** @post token.kind \in {TOKEN_TO, TOKEN_END, TOKEN_WORD, TOKEN_PRIM} */
void tokenizeWord() {
int i = pos;
advanceWhile(isAlphaOrDigit);
advanceWhile(isAlphaOrDigitOrUnderscore);
String word = text.substring(i, pos);
if (word == "to") {
token.kind = Token.TOKEN_TO;
Expand Down

0 comments on commit 3ef776b

Please sign in to comment.