parser_int.go 500 B

1234567891011121314151617181920212223242526
  1. package parser
  2. import (
  3. "fmt"
  4. "strconv"
  5. "code.osinet.fr/fgm/waiig15/ast"
  6. )
  7. func (p *Parser) parseIntegerLiteral() ast.Expression {
  8. lit := &ast.IntegerLiteral{
  9. Token: p.curToken,
  10. }
  11. // Base 0 allows straight interpretation of octal 0755 or hex 0xABCD.
  12. value, err := strconv.ParseInt(p.curToken.Literal, 0, 64)
  13. if err != nil {
  14. msg := fmt.Sprintf("could not parse %q as integer",
  15. p.curToken.Literal)
  16. p.errors = append(p.errors, msg)
  17. return nil
  18. }
  19. lit.Value = value
  20. return lit
  21. }