AST.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. export class Program {
  2. constructor() {
  3. this.body = [];
  4. this.isProgram = true;
  5. }
  6. }
  7. export class VariableDeclaration {
  8. constructor( type, name, value = null, next = null, immutable = false ) {
  9. this.type = type;
  10. this.name = name;
  11. this.value = value;
  12. this.next = next;
  13. this.immutable = immutable;
  14. this.isVariableDeclaration = true;
  15. }
  16. }
  17. export class FunctionParameter {
  18. constructor( type, name, qualifier = null, immutable = true ) {
  19. this.type = type;
  20. this.name = name;
  21. this.qualifier = qualifier;
  22. this.immutable = immutable;
  23. this.isFunctionParameter = true;
  24. }
  25. }
  26. export class FunctionDeclaration {
  27. constructor( type, name, params = [] ) {
  28. this.type = type;
  29. this.name = name;
  30. this.params = params;
  31. this.body = [];
  32. this.isFunctionDeclaration = true;
  33. }
  34. }
  35. export class Expression {
  36. constructor( expression ) {
  37. this.expression = expression;
  38. this.isExpression = true;
  39. }
  40. }
  41. export class Ternary {
  42. constructor( cond, left, right ) {
  43. this.cond = cond;
  44. this.left = left;
  45. this.right = right;
  46. this.isTernary = true;
  47. }
  48. }
  49. export class Operator {
  50. constructor( type, left, right ) {
  51. this.type = type;
  52. this.left = left;
  53. this.right = right;
  54. this.isOperator = true;
  55. }
  56. }
  57. export class Unary {
  58. constructor( type, expression, after = false ) {
  59. this.type = type;
  60. this.expression = expression;
  61. this.after = after;
  62. this.isUnary = true;
  63. }
  64. }
  65. export class Number {
  66. constructor( value, type = 'float' ) {
  67. this.type = type;
  68. this.value = value;
  69. this.isNumber = true;
  70. }
  71. }
  72. export class Conditional {
  73. constructor( cond = null ) {
  74. this.cond = cond;
  75. this.body = [];
  76. this.elseConditional = null;
  77. this.isConditional = true;
  78. }
  79. }
  80. export class FunctionCall {
  81. constructor( name, params = [] ) {
  82. this.name = name;
  83. this.params = params;
  84. this.isFunctionCall = true;
  85. }
  86. }
  87. export class Return {
  88. constructor( value ) {
  89. this.value = value;
  90. this.isReturn = true;
  91. }
  92. }
  93. export class Accessor {
  94. constructor( property ) {
  95. this.property = property;
  96. this.isAccessor = true;
  97. }
  98. }
  99. export class StaticElement {
  100. constructor( value ) {
  101. this.value = value;
  102. this.isStaticElement = true;
  103. }
  104. }
  105. export class DynamicElement {
  106. constructor( value ) {
  107. this.value = value;
  108. this.isDynamicElement = true;
  109. }
  110. }
  111. export class AccessorElements {
  112. constructor( property, elements = [] ) {
  113. this.property = property;
  114. this.elements = elements;
  115. this.isAccessorElements = true;
  116. }
  117. }
  118. export class For {
  119. constructor( initialization, condition, afterthought ) {
  120. this.initialization = initialization;
  121. this.condition = condition;
  122. this.afterthought = afterthought;
  123. this.body = [];
  124. this.isFor = true;
  125. }
  126. }