Added lexing of LAMBDA to monkey1 version

main
oabrivard 2 years ago
parent 60ee2d266f
commit 8a5d7ab5d3

@ -33,7 +33,14 @@ func (l *Lexer) NextToken() token.Token {
case '+':
tok = newToken(token.PLUS, l.ch)
case '-':
tok = newToken(token.MINUS, l.ch)
if l.peekChar() == '>' {
ch := l.ch
l.readChar()
literal := string(ch) + string(l.ch)
tok = token.Token{Type: token.LAMBDA, Literal: literal}
} else {
tok = newToken(token.MINUS, l.ch)
}
case '!':
if l.peekChar() == '=' {
ch := l.ch

@ -14,6 +14,8 @@ let add = fn(x, y) {
x + y;
};
let addlambda = fn(x,y) -> x + y;
let result = add(five, ten);
!-/*5;
5 < 10 > 5;
@ -59,6 +61,20 @@ if (5 < 10) {
{token.RBRACE, "}"},
{token.SEMICOLON, ";"},
{token.LET, "let"},
{token.IDENT, "addlambda"},
{token.ASSIGN, "="},
{token.FUNCTION, "fn"},
{token.LPAREN, "("},
{token.IDENT, "x"},
{token.COMMA, ","},
{token.IDENT, "y"},
{token.RPAREN, ")"},
{token.LAMBDA, "->"},
{token.IDENT, "x"},
{token.PLUS, "+"},
{token.IDENT, "y"},
{token.SEMICOLON, ";"},
{token.LET, "let"},
{token.IDENT, "result"},
{token.ASSIGN, "="},
{token.IDENT, "add"},

@ -33,6 +33,8 @@ const (
LBRACE = "{"
RBRACE = "}"
LAMBDA = "->"
// Keywords
FUNCTION = "FUNCTION"
LET = "LET"

Loading…
Cancel
Save