/src/org/ooc/frontend/model/IntLiteral.java

http://github.com/nddrylliog/ooc · Java · 66 lines · 50 code · 16 blank · 0 comment · 0 complexity · 2986013db90ba06845c9b83c4ec4636c MD5 · raw file

  1. package org.ooc.frontend.model;
  2. import java.io.IOException;
  3. import java.math.BigInteger;
  4. import org.ooc.frontend.Visitor;
  5. import org.ooc.frontend.model.tokens.Token;
  6. public class IntLiteral extends Literal {
  7. public static enum Format {
  8. DEC,
  9. OCT,
  10. HEX,
  11. BIN,
  12. }
  13. protected BigInteger value;
  14. protected Format format;
  15. public static Type type = new Type("Int", Token.defaultToken);
  16. public IntLiteral(long value, Format format, Token startToken) {
  17. this(new BigInteger(String.valueOf(value)), format, startToken);
  18. }
  19. public IntLiteral(BigInteger value, Format format, Token startToken) {
  20. super(startToken);
  21. this.value = value;
  22. this.format = format;
  23. }
  24. public Type getType() {
  25. return type;
  26. }
  27. public BigInteger getValue() {
  28. return value;
  29. }
  30. public Format getFormat() {
  31. return format;
  32. }
  33. public void accept(Visitor visitor) throws IOException {
  34. visitor.visit(this);
  35. }
  36. public boolean hasChildren() {
  37. return true;
  38. }
  39. public void acceptChildren(Visitor visitor) throws IOException {
  40. visitor.visit(type);
  41. }
  42. @Override
  43. public boolean replace(Node oldie, Node kiddo) {
  44. return false;
  45. }
  46. @Override
  47. public String toString() {
  48. return String.valueOf(value);
  49. }
  50. }