parser_int.go 545 B

123456789101112131415161718192021222324252627
  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. defer untrace(trace("parseIntegerLiteral"))
  9. lit := &ast.IntegerLiteral{
  10. Token: p.curToken,
  11. }
  12. // Base 0 allows straight interpretation of octal 0755 or hex 0xABCD.
  13. value, err := strconv.ParseInt(p.curToken.Literal, 0, 64)
  14. if err != nil {
  15. msg := fmt.Sprintf("could not parse %q as integer",
  16. p.curToken.Literal)
  17. p.errors = append(p.errors, msg)
  18. return nil
  19. }
  20. lit.Value = value
  21. return lit
  22. }