{"id":24920,"library":"arith2js-calculator","title":"arith2js – Calculator Transpiler with Scope Analysis","description":"A transpiler that converts calculator expressions (supporting complex numbers, min/max operators, variables, and print statements) into executable JavaScript code. Built on jison and extended from a basic arithmetic calculator, version 1.0.0 adds scope analysis to enforce variable declaration before use, reference semantics for complex objects, and comma-separated expression sequences. Key differentiators: full complex arithmetic transpilation, meticulous error reporting with line/column, and avoidance of primitive method calls via explicit Complex() wrapping.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/ULL-ESIT-PL-2425/arith2js-adrian-grassin-luis-alu0101349480","tags":["javascript","calculator","jison","parser","compiler","complex numbers","scope analysis","transpiler"],"install":[{"cmd":"npm install arith2js-calculator","lang":"bash","label":"npm"},{"cmd":"yarn add arith2js-calculator","lang":"bash","label":"yarn"},{"cmd":"pnpm add arith2js-calculator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Parser generator used to define the calculator grammar and produce the AST","package":"jison","optional":false}],"imports":[{"note":"Package is ESM-only; CommonJS require will fail with ERR_REQUIRE_ESM.","wrong":"const { transpile } = require('arith2js-calculator')","symbol":"transpile","correct":"import { transpile } from 'arith2js-calculator'"},{"note":"Default export is the transpiler function; named export does not exist.","wrong":"import { arith2js } from 'arith2js-calculator'","symbol":"arith2js","correct":"import arith2js from 'arith2js-calculator'"},{"note":"Complex is a named export, not default.","wrong":"import Complex from 'arith2js-calculator'","symbol":"Complex","correct":"import { Complex } from 'arith2js-calculator'"}],"quickstart":{"code":"import arith2js from 'arith2js-calculator';\n\nconst expr = 'a=2+3i; b=4-1i; print(a*b);';\ntry {\n  const jsCode = arith2js(expr);\n  console.log('Generated JS:');\n  console.log(jsCode);\n  // Evaluate the generated code (requires Complex class in scope)\n  const { Complex } = await import('arith2js-calculator');\n  const evalResult = eval(jsCode);\n  console.log('Result:', evalResult);\n} catch (err) {\n  console.error('Transpilation error:', err.message);\n}","lang":"typescript","description":"Transpile a complex expression with variables and print, then evaluate the generated JS."},"warnings":[{"fix":"Use dynamic import() or set \"type\": \"module\" in package.json.","message":"Package is ESM-only; using require() will throw ERR_REQUIRE_ESM.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to >=1.0.0 to avoid primitive method call errors.","message":"The direct use of Complex methods on primitives (e.g., (4-2).sub()) is no longer supported; always wrap in Complex().","severity":"deprecated","affected_versions":"<1.0.0"},{"fix":"Use explicit cloning (e.g., Complex($a).add(0)) if copy semantics are needed.","message":"Variables use reference semantics for complex numbers; mutations through aliases affect the original.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Declare variables without $ in the input; the transpiler adds the prefix automatically.","message":"Variable names must be prefixed with $ in the generated code, but the parser accepts unprefixed declarations.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure all variables are declared with an assignment before use.","message":"The transpile function now throws on undeclared variable usage; previously it would silently generate possibly broken code.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Add semicolons: e.g., 'a=1; b=2;' instead of 'a=1 b=2;'.","cause":"Missing semicolon between consecutive expressions.","error":"SyntaxError: Unexpected token, expected \";\""},{"fix":"Assign a value to the variable before use: e.g., '$x = 5; print($x);'.","cause":"Using a variable that was not declared (no prior assignment).","error":"ReferenceError: $x is not defined"},{"fix":"Upgrade to arith2js-calculator@1.0.0 or later.","cause":"Using an older version (<1.0.0) that did not wrap primitives in Complex().","error":"TypeError: Complex(...).sub is not a function"},{"fix":"Declare the variable before its first use: e.g., 'y=1; print(y);'.","cause":"Referencing a variable that has not been assigned earlier in the input.","error":"Error: Line 1, col 10: Variable 'y' used before declaration"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}