How to use AstBinaryOperation method in wpt

Best JavaScript code snippet using wpt

function.js

Source:function.js Github

copy

Full Screen

...724 AstLiteral.prototype = Object.create(AstNode.prototype);725 AstLiteral.prototype.visit = function (visitor) {726 visitor.visitLiteral(this);727 };728 function AstBinaryOperation(op, arg1, arg2, min, max) {729 AstNode.call(this, 'binary');730 this.op = op;731 this.arg1 = arg1;732 this.arg2 = arg2;733 this.min = min;734 this.max = max;735 }736 AstBinaryOperation.prototype = Object.create(AstNode.prototype);737 AstBinaryOperation.prototype.visit = function (visitor) {738 visitor.visitBinaryOperation(this);739 };740 function AstMin(arg, max) {741 AstNode.call(this, 'max');742 this.arg = arg;743 this.min = arg.min;744 this.max = max;745 }746 AstMin.prototype = Object.create(AstNode.prototype);747 AstMin.prototype.visit = function (visitor) {748 visitor.visitMin(this);749 };750 function AstVariable(index, min, max) {751 AstNode.call(this, 'var');752 this.index = index;753 this.min = min;754 this.max = max;755 }756 AstVariable.prototype = Object.create(AstNode.prototype);757 AstVariable.prototype.visit = function (visitor) {758 visitor.visitVariable(this);759 };760 function AstVariableDefinition(variable, arg) {761 AstNode.call(this, 'definition');762 this.variable = variable;763 this.arg = arg;764 }765 AstVariableDefinition.prototype = Object.create(AstNode.prototype);766 AstVariableDefinition.prototype.visit = function (visitor) {767 visitor.visitVariableDefinition(this);768 };769 function ExpressionBuilderVisitor() {770 this.parts = [];771 }772 ExpressionBuilderVisitor.prototype = {773 visitArgument: function (arg) {774 this.parts.push('Math.max(', arg.min, ', Math.min(',775 arg.max, ', src[srcOffset + ', arg.index, ']))');776 },777 visitVariable: function (variable) {778 this.parts.push('v', variable.index);779 },780 visitLiteral: function (literal) {781 this.parts.push(literal.number);782 },783 visitBinaryOperation: function (operation) {784 this.parts.push('(');785 operation.arg1.visit(this);786 this.parts.push(' ', operation.op, ' ');787 operation.arg2.visit(this);788 this.parts.push(')');789 },790 visitVariableDefinition: function (definition) {791 this.parts.push('var ');792 definition.variable.visit(this);793 this.parts.push(' = ');794 definition.arg.visit(this);795 this.parts.push(';');796 },797 visitMin: function (max) {798 this.parts.push('Math.min(');799 max.arg.visit(this);800 this.parts.push(', ', max.max, ')');801 },802 toString: function () {803 return this.parts.join('');804 }805 };806 function buildAddOperation(num1, num2) {807 if (num2.type === 'literal' && num2.number === 0) {808 // optimization: second operand is 0809 return num1;810 }811 if (num1.type === 'literal' && num1.number === 0) {812 // optimization: first operand is 0813 return num2;814 }815 if (num2.type === 'literal' && num1.type === 'literal') {816 // optimization: operands operand are literals817 return new AstLiteral(num1.number + num2.number);818 }819 return new AstBinaryOperation('+', num1, num2,820 num1.min + num2.min, num1.max + num2.max);821 }822 function buildMulOperation(num1, num2) {823 if (num2.type === 'literal') {824 // optimization: second operands is a literal...825 if (num2.number === 0) {826 return new AstLiteral(0); // and it's 0827 } else if (num2.number === 1) {828 return num1; // and it's 1829 } else if (num1.type === 'literal') {830 // ... and first operands is a literal too831 return new AstLiteral(num1.number * num2.number);832 }833 }834 if (num1.type === 'literal') {835 // optimization: first operands is a literal...836 if (num1.number === 0) {837 return new AstLiteral(0); // and it's 0838 } else if (num1.number === 1) {839 return num2; // and it's 1840 }841 }842 var min = Math.min(num1.min * num2.min, num1.min * num2.max,843 num1.max * num2.min, num1.max * num2.max);844 var max = Math.max(num1.min * num2.min, num1.min * num2.max,845 num1.max * num2.min, num1.max * num2.max);846 return new AstBinaryOperation('*', num1, num2, min, max);847 }848 function buildSubOperation(num1, num2) {849 if (num2.type === 'literal') {850 // optimization: second operands is a literal...851 if (num2.number === 0) {852 return num1; // ... and it's 0853 } else if (num1.type === 'literal') {854 // ... and first operands is a literal too855 return new AstLiteral(num1.number - num2.number);856 }857 }858 if (num2.type === 'binary' && num2.op === '-' &&859 num1.type === 'literal' && num1.number === 1 &&860 num2.arg1.type === 'literal' && num2.arg1.number === 1) {861 // optimization for case: 1 - (1 - x)862 return num2.arg2;863 }864 return new AstBinaryOperation('-', num1, num2,865 num1.min - num2.max, num1.max - num2.min);866 }867 function buildMinOperation(num1, max) {868 if (num1.min >= max) {869 // optimization: num1 min value is not less than required max870 return new AstLiteral(max); // just returning max871 } else if (num1.max <= max) {872 // optimization: num1 max value is not greater than required max873 return num1; // just returning an argument874 }875 return new AstMin(num1, max);876 }877 function PostScriptCompiler() {}878 PostScriptCompiler.prototype = {...

Full Screen

Full Screen

semantics.js

Source:semantics.js Github

copy

Full Screen

1class ASTNode {2 toJSONStringRecursive() { return ""; };3}4class ASTFormula extends ASTNode {5 constructor(expression) {6 super();7 this.expression = expression;8 }9 toJSONStringRecursive() {10 return '{"formula": ' + this.expression.toJSONStringRecursive() + '}';11 }12}13class ASTText extends ASTNode {14 constructor(text) {15 super();16 this.text = text;17 }18 toJSONStringRecursive() {19 return '{"text": "' + this.text + '"}';20 }21}22class ASTExpression extends ASTNode {23 constructor() {24 super();25 }26}27class ASTBinaryOperation extends ASTExpression {28 constructor(operation, lhs, rhs) {29 super();30 this.operation = operation;31 this.lhs = lhs;32 this.rhs = rhs;33 }34 toJSONStringRecursive() {35 var jsonString =36 '{"binaryOperation": {' +37 '"operation": "' + this.operation + '",' +38 '"operands": [' +39 this.lhs.toJSONStringRecursive() + ',' +40 this.rhs.toJSONStringRecursive() + ']}}';41 return jsonString;42 }43}44class ASTUnaryOperation extends ASTExpression {45 constructor(operation, operand) {46 super();47 this.operation = operation;48 this.operand = operand;49 }50 toJSONStringRecursive() {51 var jsonString =52 '{"unaryOperation": {' +53 '"operation": "' + this.operation + '",' +54 '"operand": [' + this.operand.toJSONStringRecursive() + ']}}';55 return jsonString;56 }57}58class ASTCall extends ASTExpression {59 constructor(receiver, args) {60 super();61 this.receiver = receiver;62 this.args = args;63 }64 toJSONStringRecursive() {65 var jsonString =66 '{"functionCall": {' +67 '"functionName": "' + this.receiver.toLowerCase() + '",' +68 '"args": [';69 for (var i in this.args) {70 jsonString = jsonString + this.args[i].toJSONStringRecursive() + ',';71 }72 if (jsonString.slice(-1) === ',') {73 jsonString = jsonString.slice(0, -1); // remove last comma74 }75 jsonString = jsonString + ']}}';76 return jsonString;77 }78}79class ASTRange extends ASTExpression {80 constructor(sheetName, columnStart, rowStart, columnEnd, rowEnd) {81 super();82 this.sheetName = sheetName;83 this.columnStart = columnStart;84 this.rowStart = rowStart;85 this.columnEnd = columnEnd;86 this.rowEnd = rowEnd;87 }88 toJSONStringRecursive() {89 var jsonString =90 '{"cellRange": {' +91 '"sheetName": "' + this.sheetName + '",' +92 '"columnStart": "' + this.columnStart + '",' +93 '"rowStart": "' + this.rowStart + '",' +94 '"columnEnd": "' + this.columnEnd + '",' +95 '"rowEnd": "' + this.rowEnd + '"' +96 '}}';97 return jsonString;98 }99}100class ASTInteger extends ASTExpression {101 constructor(value) {102 super();103 this.value = value; // JS int104 }105 toJSONStringRecursive() {106 var jsonString = '{"int": "' + this.value + '"}';107 return jsonString;108 }109}110class ASTFloat extends ASTExpression {111 constructor(value) {112 super();113 this.value = value; // JS float114 }115 toJSONStringRecursive() {116 var jsonString = '{"float": "' + this.value + '"}';117 return jsonString;118 }119}120class ASTBoolean extends ASTExpression {121 constructor(value) {122 super();123 this.value = value; // JS bool124 }125 toJSONStringRecursive() {126 var jsonString = '{"boolean": "' + this.value + '"}';127 return jsonString;128 }129}130class ASTString extends ASTExpression {131 constructor(value) {132 super();133 this.value = value; // JS string134 }135 toJSONStringRecursive() {136 var jsonString = '{"string": ' + this.value + '}';137 return jsonString;138 }139}140var astSemantics = {141 operation: "toAST",142 semantics: {143 Formula_expression: function(_equal, expression) {144 return new ASTFormula(expression.toAST());145 },146 Formula_text: function(text) {147 return new ASTText(text.sourceString);148 },149 ComparisonExpression_eq: function(x, op, y) {150 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());151 },152 ComparisonExpression_neq: function(x, op, y) {153 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());154 },155 ComparisonExpression_lt: function(x, op, y) {156 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());157 },158 ComparisonExpression_gt: function(x, op, y) {159 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());160 },161 ComparisonExpression_le: function(x, op, y) {162 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());163 },164 ComparisonExpression_ge: function(x, op, y) {165 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());166 },167 StringConcatExpression_concat: function(x, op, y) {168 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());169 },170 AdditiveExpression_add: function(x, op, y) {171 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());172 },173 AdditiveExpression_sub: function(x, op, y) {174 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());175 },176 MultiplicativeExpression_mul: function(x, op, y) {177 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());178 },179 MultiplicativeExpression_div: function(x, op, y) {180 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());181 },182 PowerExpression_pow: function(x, op, y) {183 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());184 },185 PercentExpression_percent: function(x, op) {186 return new ASTUnaryOperation(op.sourceString, x.toAST());187 },188 UnaryExpression_unaryPlus: function(op, x) {189 return new ASTUnaryOperation(op.sourceString, x.toAST());190 },191 UnaryExpression_unaryMinus: function(op, x) {192 return new ASTUnaryOperation(op.sourceString, x.toAST());193 },194 UnaryExpression_primaryExp: function(exp) {195 return exp.toAST();196 },197 UnaryExpression_refExp: function(exp) {198 return exp.toAST();199 },200 ReferenceUnionExpression_union: function(x, op, y) {201 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());202 },203 ReferenceIntersectionExpression_intersection: function(x, op, y) {204 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());205 },206 RangeExpression_range: function(x, op, y) {207 return new ASTBinaryOperation(op.sourceString, x.toAST(), y.toAST());208 },209 PrimaryExpression_callExp: function(x) {210 return x.toAST();211 },212 PrimaryExpression_lit: function(x) {213 return x.toAST();214 },215 PrimaryExpression_parens: function(_openParen, x, _closeParen) {216 return x.toAST();217 },218 PrimaryReferenceExpression_callExp: function(x) {219 return x.toAST();220 },221 PrimaryReferenceExpression_ref: function(x) {222 return x.toAST();223 },224 PrimaryReferenceExpression_parens: function(_openParen, x, _closeParen) {225 return x.toAST();226 },227 CallExpression: function(receiver, args) {228 return new ASTCall(receiver.toAST(), args.toAST());229 },230 Arguments: function(_openParen, args, _closeParen) {231 return args.toAST();232 },233 Reference_cell: function(optSheetName, column, row) {234 return new ASTRange(optSheetName.toAST(), column.toAST(), row.toAST(), '', '');235 },236 Reference_fullRange: function(optSheetName, columnStart, rowStart, _colon, columnEnd, rowEnd) {237 return new ASTRange(optSheetName.toAST(), columnStart.toAST(), rowStart.toAST(), columnEnd.toAST(), rowEnd.toAST());238 },239 Reference_verticalRange: function(optSheetName, columnStart, _colon, columnEnd) {240 return new ASTRange(optSheetName.toAST(), columnStart.toAST(), null, columnEnd.toAST(), null);241 },242 Reference_horizontalRange: function(optSheetName, rowStart, _colon, rowEnd) {243 return new ASTRange(optSheetName.toAST(), null, rowStart.toAST(), null, rowEnd.toAST());244 },245 Reference_sheetFullRange: function(sheetNameStart, columnStart, rowStart, _colon, sheetNameEnd, columnEnd, rowEnd) {246 return new ASTRange(sheetNameStart.toAST(), columnStart.toAST(), rowStart.toAST(), columnEnd.toAST(), rowEnd.toAST());247 },248 Reference_sheetVerticalRange: function(sheetNameStart, columnStart, _colon, sheetNameEnd, columnEnd) {249 return new ASTRange(sheetNameStart.toAST(), columnStart.toAST(), null, columnEnd.toAST(), null);250 },251 Reference_sheetHorizontalRange: function(sheetNameStart, rowStart, _colon, sheetNameEnd, rowEnd) {252 return new ASTRange(optSheetName.toAST(), null, rowStart.toAST(), null, rowEnd.toAST());253 },254 column: function(optDollar, x) {255 return this.sourceString;256 },257 row: function(optDollar, x) {258 return this.sourceString;259 },260 sheetName: function(x, exclamationMark) {261 return x.sourceString;262 },263 booleanLiteral: function(x) {264 return new ASTBoolean(this.sourceString === "true");265 },266 intLiteral: function(x) {267 return new ASTInteger(parseInt(this.sourceString));268 },269 floatLiteral: function(a, _dot, b) {270 return new ASTFloat(parseFloat(this.sourceString));271 },272 stringLiteral: function(_openQuote, x, _closeQuote) {273 return new ASTString(this.sourceString);274 },275 functionName: function(_name) {276 return this.sourceString;277 },278 text: function(_text) {279 return this.sourceString;280 },281 NonemptyListOf: function(arg, _separator, args) {282 return [arg.toAST()].concat(args.toAST());283 },284 EmptyListOf: function() {285 return [];286 }287 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var ast = wptools.ast;3var astBinaryOperation = ast.AstBinaryOperation;4var astVariable = ast.AstVariable;5var astNumber = ast.AstNumber;6var astBinaryOperation = new astBinaryOperation(new astVariable('a'), '+', new astNumber(3));7console.log(astBinaryOperation.toString());8var wptools = require('wptools');9var ast = wptools.ast;10var astBinaryOperation = ast.AstBinaryOperation;11var astVariable = ast.AstVariable;12var astNumber = ast.AstNumber;13var astBinaryOperation = new astBinaryOperation(new astVariable('a'), '+', new astNumber(3));14console.log(astBinaryOperation.toString());15var wptools = require('wptools');16var ast = wptools.ast;17var astBinaryOperation = ast.AstBinaryOperation;18var astVariable = ast.AstVariable;19var astNumber = ast.AstNumber;20var astBinaryOperation = new astBinaryOperation(new astVariable('a'), '+', new astNumber(3));21console.log(astBinaryOperation.toString());22var wptools = require('wptools');23var ast = wptools.ast;24var astBinaryOperation = ast.AstBinaryOperation;25var astVariable = ast.AstVariable;26var astNumber = ast.AstNumber;27var astBinaryOperation = new astBinaryOperation(new astVariable('a'), '+', new astNumber(3));28console.log(astBinaryOperation.toString());29var wptools = require('wptools');30var ast = wptools.ast;31var astBinaryOperation = ast.AstBinaryOperation;32var astVariable = ast.AstVariable;33var astNumber = ast.AstNumber;34var astBinaryOperation = new astBinaryOperation(new astVariable('a'), '+', new astNumber(3));35console.log(astBinaryOperation.toString());

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var ast = new wpt.AstBinaryOperation();3ast.setLeft(new wpt.AstNumber(10));4ast.setRight(new wpt.AstNumber(20));5ast.setOperation('+');6console.log(ast.evaluate());7var wpt = require('wpt');8var ast = new wpt.AstUnaryOperation();9ast.setOperand(new wpt.AstNumber(10));10ast.setOperation('-');11console.log(ast.evaluate());12var wpt = require('wpt');13var ast = new wpt.AstVariable();14ast.setName('x');15ast.setValue(new wpt.AstNumber(10));16console.log(ast.evaluate());17var wpt = require('wpt');18var ast = new wpt.AstAssignment();19ast.setVariable(new wpt.AstVariable('x', new wpt.AstNumber(10)));20ast.setExpression(new wpt.AstNumber(20));21console.log(ast.evaluate());22var wpt = require('wpt');23var ast = new wpt.AstBlock();24ast.addStatement(new wpt.AstAssignment(new wpt.AstVariable('x', new wpt.AstNumber(10)), new wpt.AstNumber(20)));25ast.addStatement(new wpt.AstAssignment(new wpt.AstVariable('y', new wpt.AstNumber(30)), new wpt.AstNumber(40)));26console.log(ast.evaluate());27var wpt = require('wpt');28var ast = new wpt.AstIf();29ast.setCondition(new wpt.AstBinaryOperation(new wpt.AstNumber(10), new wpt.AstNumber(20), '=='));30ast.setIfBlock(new wpt.AstBlock(new wpt.AstAssignment(new wpt.AstVariable('x', new wpt.AstNumber(10)), new wpt.AstNumber(20))));31ast.setElseBlock(new wpt.AstBlock(new wpt.AstAssignment(new wpt.AstVariable('y

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var ast = wptools.ast;3var binaryOp = ast.binaryOp;4var binaryOp1 = binaryOp('+', 1, 2);5var binaryOp2 = binaryOp('-', 3, 4);6var binaryOp3 = binaryOp('*', binaryOp1, binaryOp2);7var binaryOp4 = binaryOp('/', binaryOp3, 5);8console.log(binaryOp4);9var wptools = require('wptools');10var ast = wptools.ast;11var functionCall = ast.functionCall;12var functionCall1 = functionCall('f', [1, 2, 3]);13var functionCall2 = functionCall('g', [4, 5, 6]);14console.log(functionCall1);15console.log(functionCall2);16var wptools = require('wptools');17var ast = wptools.ast;18var identifier = ast.identifier;19var identifier1 = identifier('x');20var identifier2 = identifier('y');21console.log(identifier1);22console.log(identifier2);23var wptools = require('wptools');24var ast = wptools.ast;25var literal = ast.literal;26var literal1 = literal('string');27var literal2 = literal(123);28console.log(literal1);29console.log(literal2);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var ast = wptools.ast;3var astBinaryOperation = new ast.AstBinaryOperation();4 .setOperator('+')5 .setLeftOperand('2')6 .setRightOperand('2');7console.log(astBinaryOperation.toSource());8var wptools = require('wptools');9var ast = wptools.ast;10var astBinaryOperation = new ast.AstBinaryOperation();11 .setOperator('+')12 .setLeftOperand('2')13 .setRightOperand('2');14console.log(astBinaryOperation.toSource());15var wptools = require('wptools');16var ast = wptools.ast;17var astCall = new ast.AstCall();18 .setFunctionName('myFunction')19 .addArgument('2')20 .addArgument('2');21console.log(astCall.toSource());22var wptools = require('wptools');23var ast = wptools.ast;24var astCall = new ast.AstCall();25 .setFunctionName('myFunction')26 .addArgument('2')27 .addArgument('2');28console.log(astCall.toSource());29var wptools = require('wptools');30var ast = wptools.ast;31var astCall = new ast.AstCall();32 .setFunctionName('myFunction')33 .addArgument('2')34 .addArgument('2');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpage').create();2var page = require('webpage').create();3var ast = wpt.evaluate(function() {4 var ast = new AstBinaryOperation(5 new AstNumber(2),6 new AstBinaryOperation(7 new AstNumber(3),8 new AstNumber(4)9 );10 return ast;11});12var result = page.evaluate(function(ast) {13 return ast.evaluate();14}, ast);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var a = "2+2";3var b = "2+2*2";4var c = "2+2*2+2";5var d = "2+2*2+2*2";6var e = "2+2*2+2*2*2";7var f = "2+2*2+2*2*2+2";8var g = "2+2*2+2*2*2+2*2";9var h = "2+2*2+2*2*2+2*2*2";10var i = "2+2*2+2*2*2+2*2*2+2";11var j = "2+2*2+2*2*2+2*2*2+2*2";12var k = "2+2*2+2*2*2+2*2*2+2*2*2";13var l = "2+2*2+2*2*2+2*2*2+2*2*2+2";14var m = "2+2*2+2*2*2+2*2*2+2*2*2+2*2";15var n = "2+2*2+2*2*2+2*2*2+2*2*2+2*2*2";16var o = "2+2*2+2*2*2+2*2*2+2*2*2+2*2*2+2";

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful