This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (p *Parser) parseExpression(precedence int) ast.Expression { | |
| prefix := p.prefixParseFns[p.curToken.Type] | |
| if prefix == nil { | |
| p.noPrefixParseFnError(p.curToken.Type) | |
| return nil | |
| } | |
| leftExp := prefix() | |
| for !p.peekTokenIs(token.SEMICOLON) && precedence < p.peekPrecedence() { | |
| infix := p.infixParseFns[p.peekToken.Type] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const ( | |
| LOWEST iota + 1 | |
| EQUALS // == | |
| LESSGRETER // > or < | |
| SUM // + | |
| PRODUCT // * | |
| PREFIX // -X or !X | |
| CALL // myFunction(X) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (p *Parser) parseExpression(precedence int) ast.Expression { | |
| prefix := p.prefixParseFns[p.curToken.Type] | |
| if prefix == nil { | |
| p.noPrefixParseFnError(p.curToken.Type) | |
| return nil | |
| } | |
| leftExp := prefix() | |
| for !p.peekTokenIs(token.SEMICOLON) && precedence < p.peekPrecedence() { | |
| infix := p.infixParseFns[p.peekToken.Type] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (p *Parser) parseExpressionStatement() *ast.ExpressionStatement { | |
| stmt := &ast.ExpressionStatement{Token: p.curToken} | |
| stmt.Expression = p.parseExpression(LOWEST) | |
| if p.peekTokenIs(token.SEMICOLON) { | |
| p.nextToken() | |
| } | |
| return stmt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (p *Parser) parseInfixExpression(left ast.Expression) ast.Expression { | |
| expression := &ast.InfixExpression{ | |
| Token: p.curToken, | |
| Operator: p.curToken.Literal, | |
| Left: left, | |
| } | |
| precedence := p.curPrecedence() | |
| p.nextToken() | |
| expression.Right = p.parseExpression(precedence) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (p *Parser) parsePrefixExpression() ast.Expression { | |
| expression := &ast.PrefixExpression{ | |
| Token: p.curToken, | |
| Operator: p.curToken.Literal, | |
| } | |
| p.nextToken() | |
| expression.Right = p.parseExpression(PREFIX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (p *Parser) parseIntegerLiteral() ast.Expression { | |
| lit := &ast.IntegerLiteral{Token: p.curToken} | |
| value, err := strconv.ParseInt(p.curToken.Literal, 0, 64) | |
| if err != nil { | |
| msg := fmt.Sprintf("could not parse %q as integer", p.curToken.Literal) | |
| p.errors = append(p.errors, msg) | |
| return nil | |
| } | |
| lit.Value = value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BEGIN parseExpresssionStatement | |
| BEGIN parseExpresssion | |
| BEGIN parseIntegerLiteral | |
| END parseIntegerLiteral | |
| BEGIN parseInfixExpression | |
| BEGIN parseExpresssion | |
| BEGIN parseIntegerLiteral | |
| END parseIntegerLiteral | |
| END parseExpresssion | |
| END parseInfixExpression |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var precedences = map[token.TokenType]int{ | |
| token.EQ: EQUALS, | |
| token.NOT_EQ: EQUALS, | |
| token.LT: LESSGRETER, | |
| token.GT: LESSGRETER, | |
| token.PLUS: SUM, | |
| token.MINUS: SUM, | |
| token.SLASH: PRODUCT, | |
| token.ASTERISK: PRODUCT, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: "3" | |
| services: | |
| node: | |
| image: node:13 | |
| volumes: | |
| - ./app:/app:cached | |
| working_dir: /app | |
| env_file: | |
| - .env | |
| tty: true |
OlderNewer