Parsing and testing boolean literals.
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
5fa7b2481a
commit
c417e90f36
3 changed files with 170 additions and 21 deletions
|
|
@ -35,6 +35,8 @@ func New(l *lexer.Lexer) *Parser {
|
|||
p.registerPrefix(token.INT, p.parseIntegerLiteral)
|
||||
p.registerPrefix(token.MINUS, p.parsePrefixExpression)
|
||||
p.registerPrefix(token.BANG, p.parsePrefixExpression)
|
||||
p.registerPrefix(token.TRUE, p.parseBoolean)
|
||||
p.registerPrefix(token.FALSE, p.parseBoolean)
|
||||
// Infix registrations
|
||||
p.registerInfix(token.PLUS, p.parseInfixExpression)
|
||||
p.registerInfix(token.MINUS, p.parseInfixExpression)
|
||||
|
|
@ -148,6 +150,10 @@ func (p *Parser) parseIntegerLiteral() ast.Expression {
|
|||
return exp
|
||||
}
|
||||
|
||||
func (p *Parser) parseBoolean() ast.Expression {
|
||||
return &ast.Boolean{Token: p.curToken, Value: p.curTokenIs(token.TRUE)}
|
||||
}
|
||||
|
||||
func (p *Parser) parsePrefixExpression() ast.Expression {
|
||||
exp := &ast.PrefixExpression{
|
||||
Token: p.curToken,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue