Advertisement
Guest User

Untitled

a guest
Mar 16th, 2024
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 7.91 KB | None | 0 0
  1. type expression
  2. type compound_statement
  3. type accessor
  4. type scope_type
  5.  
  6. type regexp_flags =
  7.   | Global
  8.   | IgnoreCase
  9.   | Multiline
  10.   | Unicode
  11.   | Sticky
  12.   | DotAll
  13.   | HasIndices
  14.  
  15. type simple_literal =
  16.   | String of string
  17.   | Float of float
  18.   | Integer of int
  19.   | BigInt of string
  20.   | Boolean of bool
  21.   | Null
  22.   | Undefined
  23.  
  24. type regexp_literal = {
  25.   pattern : string;
  26.   flags : regexp_flags list;
  27. }
  28.  
  29. type literal =
  30.   | Simple of simple_literal
  31.   | RegExp of regexp_literal
  32.   | Object of object_literal
  33.   | Array of array_literal
  34.   | Lambda of lambda_literal
  35.   | Template of template_literal
  36.  
  37. and object_literal_entry =
  38.   | Property of string * expression
  39.   | SpreadProperty of expression
  40.  
  41. and object_literal = object_literal_entry list
  42.  
  43. and array_literal = {
  44.   num_items : int;
  45.   items : expression list;
  46. }
  47.  
  48. and lambda_params =
  49.   | NamedParams of accessor list
  50.   | RestParam of string
  51.  
  52. and template_literal_quasi =
  53.   | Text of string list
  54.   | EmbExpr of expression list
  55.  
  56.  
  57. and template_literal =
  58.   template_literal_quasi list
  59.  
  60. and lambda_literal = {
  61.   params : lambda_params;
  62.   body : compound_statement;
  63. }
  64.  
  65. type built_in_variable =
  66.   | Self
  67.   | This
  68.  
  69. type built_in_function =
  70.   | Eval
  71.   | Exec
  72.   | IsNaN
  73.   | ParseFloat
  74.   | ParseInt
  75.   | DecodeURI
  76.   | DecodeURIComponent
  77.   | EncodeURI
  78.   | EncodeURIComponent
  79.  
  80. type identifier =
  81.   | VariableName of string
  82.   | ConstructorName of string
  83.   | FunctionName of string
  84.   | ParameterName of string
  85.   | ClassName of string
  86.   | PrototypeName of string
  87.   | BuiltInVariable of built_in_variable
  88.   | BuiltInFunction of built_in_function
  89.  
  90. type subscript =
  91.   | Invoke of expression list
  92.   | Index of expression list
  93.  
  94. type access = {
  95.   name: identifier;
  96.   subscript : subscript option;
  97. }
  98.  
  99. type accessor = access list
  100.  
  101. type primary_expression =
  102.   | Literal of literal
  103.   | Accessor of accessor
  104.   | NestedExpr of expression
  105.  
  106. type unary_expression =
  107.   | Primary of primary_expression
  108.   | Plus of primary_expression
  109.   | Minus of primary_expression
  110.   | Incr of primary_expression
  111.   | Decr of primary_expression
  112.   | Not of expression
  113.   | OnesCompl of expression
  114.   | TwosCompl of expression
  115.   | Typeof of expression
  116.   | Void of expression
  117.   | Delete of expression
  118.   | Spread of expression
  119.   | Rest of expression
  120.   | Yield of expression
  121.   | New of expression
  122.  
  123. type arithmetic_expression =
  124.   | Add of expression * expression
  125.   | Sub of expression * expression
  126.   | Mul of expression * expression
  127.   | Div of expression * expression
  128.   | Mod of expression * expression
  129.   | Pow of expression * expression
  130.  
  131. type bitwise_expression =
  132.   | And of expression * expression
  133.   | Or of expression * expression
  134.   | Xor of expression * expression
  135.   | Shl of expression * expression
  136.   | Shr of expression * expression
  137.   | Ror of expression * expression
  138.  
  139. type relational_expression =
  140.   | Le of expression * expression
  141.   | Lt of expression * expression
  142.   | Gt of expression * expression
  143.   | Ge of expression * expression
  144.   | Instanceof of expression * expression
  145.   | In of expression * expression
  146.  
  147. type equality_expression =
  148.   | Eq of expression * expression
  149.   | Ne of expression * expression
  150.   | StrictEq of expression * expression
  151.   | StrictNe of expression * expression
  152.   | Nullish of expression * expression
  153.  
  154. type assignment_expression =
  155.   | ValAssignment of accessor * expression
  156.   | AddAssignment of accessor * expression
  157.   | SubAssignment of accessor * expression
  158.   | DivAssignment of accessor * expression
  159.   | ModAssignment of accessor * expression
  160.   | PowAssignment of accessor * expression
  161.   | ShrAssignment of accessor * expression
  162.   | ShlAssignment of accessor * expression
  163.   | RorAssignment of accessor * expression
  164.   | AndAssignment of accessor * expression
  165.   | OrAssignment of accessor * expression
  166.  
  167. type binary_expression =
  168.   | Arithmetic of arithmetic_expression
  169.   | Bitwise of bitwise_expression
  170.   | Relational of relational_expression
  171.   | Equality of equality_expression
  172.   | Assignment of assignment_expression
  173.  
  174. type ternary_expression = {
  175.   cond : expression;
  176.   if_true : expression;
  177.   if_false : expression;
  178. }
  179.  
  180. type function_expression = {
  181.   params : accessor list;
  182.   body : compound_statement;
  183. }
  184.  
  185. type arrow_function_expr = {
  186.   params: lambda_params;
  187.   body: expression; (* Can be an expression or a block *)
  188. }
  189.  
  190. type function_argument =
  191.   | Unnamed of expression
  192.   | Named of string * expression
  193.  
  194. type function_call = {
  195.   callee : expression;
  196.   arguments : function_argument list;
  197. }
  198.  
  199. type class_expression = {
  200.   name: string option;
  201.   extends: expression option;
  202.   body: class_body list;
  203. }
  204.  
  205. and class_body =
  206.   | Method of string * function_expression
  207.   | Property of string * expression option
  208.  
  209. type expression =
  210.   | Literal of literal
  211.   | Identifier of identifier
  212.   | FunctionCall of function_call
  213.   | Unary of unary_expression
  214.   | Binary of binary_expression
  215.   | Ternary of ternary_expression
  216.   | FunctionExpr of function_expression
  217.   | ClassExpr of class_expression
  218.   | ArrowFuncExpr of arrow_function_expr
  219.  
  220. type spread_element = expression
  221.  
  222. type destructuring_assignment = {
  223.   target: destructuring_target;
  224.   source: expression;
  225. }
  226.  
  227. and destructuring_target =
  228.   | ObjectTarget of (string * string option) list
  229.   | ArrayTarget of string list
  230.  
  231. type async_function_expr = {
  232.   params: accessor list; (* Adjusted from string list to accessor list for consistency *)
  233.   body: compound_statement;
  234. }
  235.  
  236. (* Statements *)
  237. type if_statement = {
  238.   condition: expression;
  239.   then_branch: compound_statement;
  240.   else_branch: compound_statement option;
  241. }
  242.  
  243. type switch_statement = {
  244.   discriminant: expression;
  245.   cases: (expression option * compound_statement) list; (* None for default case *)
  246. }
  247.  
  248. type for_statement = {
  249.   init: expression option;
  250.   condition: expression option;
  251.   update: expression option;
  252.   body: compound_statement;
  253. }
  254.  
  255. type while_statement = {
  256.   condition: expression;
  257.   body: compound_statement;
  258. }
  259.  
  260. type do_while_statement = {
  261.   body: compound_statement;
  262.   condition: expression;
  263. }
  264.  
  265. type try_catch_finally_statement = {
  266.   try_block: compound_statement;
  267.   catch_block: (accessor option * compound_statement) option; (* Catch parameter may be an accessor *)
  268.   finally_block: compound_statement option;
  269. }
  270.  
  271. type control_flow_statement =
  272.   | Break
  273.   | Continue
  274.   | Return of expression option
  275.   | Throw of expression
  276.  
  277. type statement =
  278.   | ExpressionStatement of expression
  279.   | CompoundExpressionStatement of expression list
  280.   | IfStatement of if_statement
  281.   | SwitchStatement of switch_statement
  282.   | ForStatement of for_statement
  283.   | WhileStatement of while_statement
  284.   | DoWhileStatement of do_while_statement
  285.   | TryCatchFinallyStatement of try_catch_finally_statement
  286.   | ControlFlowStatement of control_flow_statement
  287.   | VariableDeclarationStatement of variable_declaration
  288.   | FunctionDeclarationStatement of function_declaration
  289.   | ClassDeclarationStatement of class_declaration
  290.   | DestructureAssignment of destructuring_assignment
  291.   | Block of compound_statement
  292.  
  293. and compound_statement = statement list
  294.  
  295. (* Declarations *)
  296. and variable_declaration = {
  297.   kind: string; (* "var", "let", "const" *)
  298.   declarations: (accessor * expression option) list;
  299. }
  300.  
  301. and function_declaration = {
  302.   name: string;
  303.   params: accessor list; (* Adjusted from function_param list for consistency *)
  304.   body: compound_statement;
  305. }
  306.  
  307. and class_declaration = {
  308.   name: string;
  309.   extends: expression option;
  310.   body: class_body list;
  311. }
  312.  
  313. type declaration =
  314.   | VariableDeclaration of variable_declaration
  315.   | FunctionDeclaration of function_declaration
  316.   | ClassDeclaration of class_declaration
  317.  
  318. type es_scope = {
  319.   scope_type: scope_type;
  320.   declarations: declaration list;
  321.   statements: statement list;
  322. }
  323.  
  324. type scope_type =
  325.   | Global
  326.   | FunctionScope of function_declaration
  327.   | ClassScope of class_declaration
  328.   | BlockScope
  329.  
  330. type es_program = es_scope list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement