From 2c4068a5be7f60e8d0376720f70791d23a8c3ef1 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Sat, 11 Jan 2020 14:26:19 +0100 Subject: token: support more keywords Add support for a few more keywords (`true`, `false`, `if`, `else`, `return`). All keywords are grouped together in the constant declaration. --- users/fcuny/exp/monkey/pkg/token/token.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'users/fcuny/exp/monkey/pkg/token') diff --git a/users/fcuny/exp/monkey/pkg/token/token.go b/users/fcuny/exp/monkey/pkg/token/token.go index 6937595..a211c55 100644 --- a/users/fcuny/exp/monkey/pkg/token/token.go +++ b/users/fcuny/exp/monkey/pkg/token/token.go @@ -24,8 +24,14 @@ const ( LBRACE = "{" RBRACE = "}" + // The following tokens are keywords FUNCTION = "FUNCTION" LET = "LET" + TRUE = "TRUE" + FALSE = "FALSE" + IF = "IF" + ELSE = "ELSE" + RETURN = "RETURN" // The following tokens are for operators ASSIGN = "=" @@ -40,8 +46,13 @@ const ( // List of our keywords for the language var keywords = map[string]TokenType{ - "fn": FUNCTION, - "let": LET, + "fn": FUNCTION, + "let": LET, + "true": TRUE, + "false": FALSE, + "if": IF, + "else": ELSE, + "return": RETURN, } // LookupIdent returns the token type for a given identifier. -- cgit 1.4.1