-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinterpreter.min.js
More file actions
2 lines (2 loc) · 19.2 KB
/
Copy pathinterpreter.min.js
File metadata and controls
2 lines (2 loc) · 19.2 KB
1
2
/*! SmallBasicInterpreter: 10-11-2013 */
!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){function analyze(input){for(token="",state=1,tokens=[],Machine.Line++,pointer=0;pointer<input.length;pointer++){if(currentChar=input[pointer],token+=currentChar,column=Machine.Columns.indexOf(currentChar)+2,2>column)if(-1!=Machine.Letters.indexOf(currentChar.toUpperCase()))column=0;else if(-1!=Machine.Numbers.indexOf(currentChar.toUpperCase()))column=1;else if(10!=state&&12!=state)throw new LexerException("Unidentified character on line: "+Machine.Line+", char: "+(pointer+1));state=Machine.LexTable[state][column];var backup=checkForToken(!1);1==state&&(backup&&pointer--,token="")}if(state=Machine.LexTable[state][19],checkForToken(!0),1!=state)throw new LexerException("Unexpected end of line at line "+Machine.Line);return tokens.length>0&&tokens.push({Type:Tokens.EndOfLine,Literal:"$"}),tokens}function checkForToken(endofline){switch(state){case 3:return endofline||(token=token.substr(0,token.length-1)),-1!=Machine.Keywords.indexOf(token)?tokens.push({Type:Tokens.Keyword,Literal:token}):-1!=Machine.Operators.indexOf(token)?tokens.push({Type:Tokens.Operator,Literal:token}):(-1==Machine.Symbols.indexOf(token)&&Machine.Symbols.push(token),tokens.push({Type:Tokens.Identifier,Literal:token})),state=1,!0;case 5:return endofline||(token=token.substr(0,token.length-1)),tokens.push({Type:Tokens.NumberLiteral,Literal:token}),state=1,!0;case 6:case 8:return tokens.push({Type:Tokens.Operator,Literal:token}),state=1,!1;case 9:return endofline||(token=token.substr(0,token.length-1)),tokens.push({Type:Tokens.Operator,Literal:token}),state=1,!0;case 11:return tokens.push({Type:Tokens.StringLiteral,Literal:token}),state=1,!1;case 13:return state=1,!1;case 14:return tokens.push({Type:Tokens.Label,Literal:token}),state=1,!1;case 15:return tokens.push({Type:Tokens.Separator,Literal:token}),state=1,!1;case 18:return endofline||(token=token.substr(0,token.length-1)),tokens.push({Type:Tokens.DecimalLiteral,Literal:token}),state=1,!0}return!1}var LexerException=function(){function LexerException(errorMessage){this.name="LexerException",this.message=errorMessage}return LexerException}(),Machine=require("./State"),Tokens=require("./Tokens"),pointer=0,column=0,currentChar="",state=1,token="",tokens=[];exports.analyze=analyze},{"./State":4,"./Tokens":5}],2:[function(require,module,exports){function parse(input){Machine.State=0,Machine.Stack=[{State:0,Node:null}];for(var x=0;x<input.length;x++){var action=getParseAction(input[x]);if("r"==action.substr(0,1))handleReduce(parseInt(action.substr(1))),x--;else{if("acc"==action){if("undefined"==typeof Machine.Stack)throw new ParserException("No tokens in parser input at line "+Machine.Line);return Machine.Stack[1].Node}if(""==action)throw"$"==input[x].Literal?new ParserException("Unexpected end of line at line "+Machine.Line):new ParserException("Unexpected token '"+input[x].Literal+"' at line "+Machine.Line);Machine.State=parseInt(action),Machine.Stack.push({State:Machine.State,Node:{Type:input[x].Type,Literal:input[x].Literal}})}}if(1==Machine.Stack.length)throw new ParserException("Incomplete input at line "+Machine.Line);return null}function getParseAction(token){return token.Type==Tokens.Identifier?Machine.GetParseAction("Iden"):token.Type==Tokens.Label?Machine.GetParseAction("Lab"):token.Type==Tokens.DecimalLiteral||token.Type==Tokens.NumberLiteral||token.Type==Tokens.StringLiteral?Machine.GetParseAction("Lit"):Machine.GetParseAction(token.Literal)}function handleReduce(action){switch(action){case 1:break;case 2:ParserHandler.HandleSingleRightSideProduction(2,"S");break;case 3:ParserHandler.HandleSingleRightSideProduction(3,"S");break;case 4:ParserHandler.HandleSingleRightSideProduction(4,"S");break;case 5:break;case 6:ParserHandler.HandleSingleRightSideProduction(6,"S");break;case 7:ParserHandler.HandleDoubleRightSideProduction(7,"R");break;case 8:ParserHandler.HandleDoubleRightSideProduction(8,"S");break;case 9:ParserHandler.HandleSingleRightSideProduction(9,"S");break;case 10:ParserHandler.HandleDoubleRightSideProduction(10,"S");break;case 11:ParserHandler.HandleSingleRightSideProduction(11,"S");break;case 12:ParserHandler.HandleDoubleRightSideProduction(12,"S");break;case 13:ParserHandler.HandleProduction13();break;case 14:ParserHandler.HandleProduction14();break;case 15:ParserHandler.HandleSingleRightSideProduction(15,"S");break;case 16:ParserHandler.HandleSingleRightSideProduction(16,"A");break;case 18:ParserHandler.HandleOperationProduction(18,"B");break;case 19:ParserHandler.HandleOperationProduction(19,"E");break;case 20:ParserHandler.HandleOperationProduction(20,"E");break;case 21:ParserHandler.HandleOperationProduction(21,"E");break;case 22:ParserHandler.HandleOperationProduction(22,"E");break;case 23:ParserHandler.HandleSingleRightSideProduction(23,"E");break;case 24:ParserHandler.HandleOperationProduction(24,"T");break;case 25:ParserHandler.HandleOperationProduction(25,"T");break;case 26:ParserHandler.HandleSingleRightSideProduction(26,"T");break;case 27:ParserHandler.HandleParenthesisExpression(27,"F");break;case 28:ParserHandler.HandleSingleRightSideProduction(28,"F");break;case 29:ParserHandler.HandleSingleRightSideProduction(29,"F");break;case 30:ParserHandler.HandleSingleRightSideProduction(30,"G");break;case 31:ParserHandler.HandleSingleRightSideProduction(31,"G");break;case 32:ParserHandler.HandleSingleRightSideProduction(32,"G");break;case 33:ParserHandler.HandleSingleRightSideProduction(33,"G");break;case 34:ParserHandler.HandleSingleRightSideProduction(34,"G");break;case 35:ParserHandler.HandleSingleRightSideProduction(35,"S")}}var ParserException=function(){function ParserException(errorMessage){this.name="ParserException",this.message=errorMessage}return ParserException}(),Tokens=require("./Tokens"),Machine=require("./State"),ParserHandler=require("./ParserHandler");exports.parse=parse},{"./ParserHandler":3,"./State":4,"./Tokens":5}],3:[function(require,module,exports){function HandleSingleRightSideProduction(production,leftSide){var records=popRecordsFromStack(1);pushNewNode({Type:Tokens.Production,Literal:production,Left:records[0].Node},leftSide)}function HandleDoubleRightSideProduction(production,leftSide){var records=popRecordsFromStack(2);pushNewNode({Type:Tokens.Production,Literal:production,Left:records[0].Node,Right:records[1].Node},leftSide)}function HandleOperationProduction(production,leftSide){var records=popRecordsFromStack(3);pushNewNode({Type:Tokens.Production,Literal:production,Left:records[2].Node,Operator:records[1].Node.Literal,Right:records[0].Node},leftSide)}function HandleParenthesisExpression(production,leftSide){var records=popRecordsFromStack(3);pushNewNode({Type:Tokens.Production,Literal:production,Left:records[1].Node},leftSide)}function HandleProduction13(){var records=popRecordsFromStack(1),arguments=null,node={Type:Tokens.Production,Literal:13};if("("!=peekLastNode().Literal){do records=popRecordsFromStack(2),arguments={Type:Tokens.Argument,Literal:null,Left:records[0].Node,Right:arguments};while("("!=records[1].Node.Literal)}else popRecordsFromStack(1);records=popRecordsFromStack(3),node.Left=records[2].Node,node.Right=records[0].Node,node.Right.Right=arguments,node.Operator=".",pushNewNode(node,"S")}function HandleProduction14(){var records=popRecordsFromStack(3),node={Type:Tokens.Production,Literal:14};if("("==records[2].Node.Literal){var record4=popRecordsFromStack(1);record4[0].Node.Left=records[1].Node,node.Left=record4[0].Node}else node.Left=records[2].Node;pushNewNode(node,"S")}function pushNewNode(node,leftSide){Machine.State=Machine.GetParseGoto(getLastState(),leftSide),Machine.Stack.push({State:Machine.State,Node:node})}function getLastState(){return Machine.Stack[Machine.Stack.length-1].State}function peekLastNode(){return Machine.Stack[Machine.Stack.length-1].Node}function popRecordsFromStack(amount){for(var records=[],x=0;amount>x;x++)records.push(Machine.Stack.pop());return records}var Tokens=require("./Tokens"),Machine=require("./State");exports.HandleSingleRightSideProduction=HandleSingleRightSideProduction,exports.HandleDoubleRightSideProduction=HandleDoubleRightSideProduction,exports.HandleOperationProduction=HandleOperationProduction,exports.HandleParenthesisExpression=HandleParenthesisExpression,exports.HandleProduction13=HandleProduction13,exports.HandleProduction14=HandleProduction14},{"./State":4,"./Tokens":5}],4:[function(require,module,exports){function GetParseAction(terminal){return ParseActions[this.State][parseActions[terminal]]}function GetParseGoto(state,production){return ParseGoto[state][parseGoto[production]]}exports.Columns="+-*/().=,<>\":[]' ",exports.Operators=["Or","And"],exports.Letters="_ABCDEFGHIJKLMNOPQRSTUVWXYZ",exports.Numbers="0123456789",exports.Symbols=[],exports.Line=0,exports.Keywords=["For","To","Step","EndFor","If","Then","Else","EndIf","Goto","While","EndWhile","Sub","EndSub","ElseIf"],exports.Stack,exports.State,exports.LexTable=[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[2,4,6,19,6,6,15,15,6,6,6,7,21,10,6,6,6,12,1,1,0],[2,2,3,3,3,3,3,3,3,3,3,3,3,3,14,3,3,3,3,3,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[5,4,5,5,5,5,5,5,16,5,5,5,5,5,5,5,5,5,5,5,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],[9,9,9,9,9,9,9,9,9,8,9,9,8,9,9,9,9,9,9,9,1],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,10,10,10,10,10,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],[12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],[0,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[18,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[9,20,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,0],[5,4,5,5,5,5,5,5,16,5,5,5,5,5,5,5,5,5,5,5,0],[9,9,9,9,9,9,9,9,9,8,9,9,9,9,9,9,9,9,9,9,1]];var parseActions={If:0,Then:1,Else:2,ElseIf:3,EndIf:4,For:5,To:6,EndFor:7,Step:8,While:9,EndWhile:10,Sub:11,EndSub:12,Goto:13,Iden:14,Lab:15,Lit:16,".":17,",":18,"=":19,"+":20,"-":21,"/":22,"*":23,"(":24,")":25,"<":26,">":27,"<>":28,">=":29,"<=":30,$:31};exports.GetParseAction=GetParseAction;var ParseActions=[["2","","3","4","5","6","","7","","8","9","10","11","12","13","65","","","","","","","","","","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","acc"],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r2"],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r3"],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r4"],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r6"],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r9"],["","","","","","","","","","","","","","","23","","","","","","","","","","","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r11"],["","","","","","","","","","","","","","","","","24","","","","","","","","","","","","","","",""],["","","","","","","","","","","","","","","","","","25","","27","","","","","26","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r15"],["","28","","","","","","","","","","","","","","","","","","51","29","30","","","","","45","64","32","33","46",""],["","r23","","","","","r23","","r23","","","","","","","","","","","r23","r23","r23","35","34","","r23","r23","r23","r23","r23","r23","r23"],["","r26","","","","","r26","","r26","","","","","","","","","","","r26","r26","r26","r26","r26","","r26","r26","r26","r26","r26","r26","r26"],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","r28","","","","","r28","","r28","","","","","","","","","","","r28","r28","r28","r28","r28","","r28","r28","r28","r28","r28","r28","r28"],["","r29","","","","","r29","","r29","","","","","","","","","","","r29","r29","r29","r29","r29","","r29","r29","r29","r29","r29","r29","r29"],["","","","","","","37","","","","","","","","","","","","","51","29","30","","","","","45","64","32","33","46",""],["","","","","","","","","","","","","","","","","","","","51","29","30","","","","","45","64","32","33","46","r8"],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r10"],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r12"],["","","","","","","","","","","","","","","38","","","","","","","","","","","","","","","","",""],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","54","","","","","",""],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r1"],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","r30","","r30","","","","","","","","r30","","","","","","",""],["","","","","","","","","","","","","","","r32","","r32","","","","","","","","r32","","","","","","",""],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","","","","","","51","29","30","","","","50","45","64","32","33","46",""],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","53","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","r16","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","r16","","","","","",""],["","","","","","","","","","","","","","","","","","","","51","29","30","","","","50","45","64","32","33","46","r18"],["","r19","","","","","r19","","r19","","","","","","","","","","","r19","r19","r19","35","34","","","r19","r19","r19","r19","r19","r19"],["","r20","","","","","r20","","r20","","","","","","","","","","","r20","r20","r20","35","34","","","r20","r20","r20","r20","r20","r20"],["","r22","","","","","r22","","r22","","","","","","","","","","","r22","r22","r22","35","34","","","r22","r22","r22","r22","r22","r22"],["","","","","","","","","","","","","","","r34","","r34","","","","","","","","r34","","","","","","",""],["","","","","","","","","","","","","","","r31","","r31","","","","","","","","r31","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""],["","r24","","","","","r24","","r24","","","","","","","","","","","r24","r24","r24","r24","r24","","","r24","r24","r24","r24","r24","r24"],["","r25","","","","","r25","","r25","","","","","","","","","","","r25","r25","r25","r25","r25","","","r25","r25","r25","r25","r25","r25"],["","r27","","","","","r27","","r27","","","","","","","","","","","r27","r27","r27","r27","r27","","r27","r27","r27","r27","r27","r27","r27"],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","59","","","","","","","","","","","","","","","","","","","","","","",""],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","63","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r14"],["","","","","","","","","","","","","","","","","","","","","","","","","","r16","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","54","","","","","",""],["","r21","","","","","r21","","r21","","","","","","","","","","","r21","r21","r21","","","","","r21","r21","r21","r21","r21","r21"],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r5"],["","","","","","","","","","","","","","","20","","19","","","","","","","","18","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","63","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r17"],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r7"],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r13"],["","","","","","","","","","","","","","","r33","","r33","","","","","","","","r33","","","","","","",""],["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","r35"]],parseGoto={E:0,R:1,T:2,F:3,G:4,A:5,B:6,S:7,C:8};exports.GetParseGoto=GetParseGoto;var ParseGoto=[[0,0,0,0,0,0,14,1,0],[0,0,0,0,0,0,0,0,0],[15,0,16,17,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[21,0,16,17,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[22,0,16,17,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,31,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[36,0,16,17,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,31,0,0,0,0],[0,0,0,0,31,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[39,0,16,17,0,39,0,0,0],[41,0,16,17,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,42,17,0,0,0,0,0],[0,0,43,17,0,0,0,0,0],[0,0,44,17,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,48,0,0,0,0,0],[0,0,0,49,0,0,0,0,0],[0,0,0,0,31,0,0,0,0],[52,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,55],[0,0,0,0,31,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,16,17,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[40,0,16,17,0,60,0,0,0],[0,58,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,61,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[62,0,16,17,0,0,0,0,0]]},{}],5:[function(require,module,exports){exports.Identifier="id",exports.NumberLiteral="num",exports.Operator="op",exports.StringLiteral="str",exports.Label="lbl",exports.Separator="sep",exports.DecimalLiteral="dec",exports.EndOfLine="eol",exports.Keyword="kwd",exports.Production="pro",exports.Argument="arg"},{}]},{},[1,2,3,4,5]);