diff --git a/dist/index.min.js b/dist/index.min.js index 8420e0b..02d6be3 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -1 +1 @@ -(()=>{"use strict";var e={44:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&n(r,e,t);return a(r,e),r};Object.defineProperty(r,"__esModule",{value:!0});const o=i(t(994)),s=e=>{const r=e[0];if("string"===r.type){const e=r.value.length;return o.createNumberValue({value:e},String(e),r.range)}throw new Error},u=(e,r)=>{if(0===e.length)throw new Error;const t=e.map((e=>e.representation)).join(" ");void 0!==r&&r(t);const n={begin:e[0].range.begin,end:e[e.length-1].range.end};return o.createEmptyValue({value:null},"(없음)",n)},c={get(e){switch(e){case"길이":return s;case"쓰기":return u;default:return null}}};r.default=c},404:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.default=class{constructor(e=null){this.superEnvironment=e,this.table=new Map}get(e){const r=this.table.get(e);return void 0!==r?r:null===this.superEnvironment?null:this.superEnvironment.get(e)}set(e,r){this.table.set(e,r)}}},673:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&n(r,e,t);return a(r,e),r},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.Environment=r.BadIdentifierError=r.BadInfixExpressionError=r.BadPrefixExpressionError=r.BadAssignmentLeftError=r.BadPredicateError=r.TopLevelReturnError=r.EvalError=void 0;const s=i(t(994)),u=o(t(44)),c=o(t(404));class l extends Error{constructor(e,r){super(),this.range=e,this.received=r}}r.EvalError=l;class d extends l{}r.TopLevelReturnError=d;class h extends l{}r.BadPredicateError=h;class p extends l{}r.BadAssignmentLeftError=p;class f extends l{}r.BadPrefixExpressionError=f;class g extends l{}r.BadInfixExpressionError=g;class v extends l{}r.BadIdentifierError=v,r.default=class{evaluate(e,r){return this.evaluateProgram(e,r)}onStdout(e){this.callbackOnStdout=e}evaluateProgram(e,r){const{statements:t}=e;let n=null;for(let a=0;athis.evaluateExpression(e,r)))}evaluateFunctionCall(e,r){const t=this.createExtendedEnvironment(e.environment,e.parameters,r),n=this.evaluateBlock(e.body,t);if("return"!==n.type)throw new Error("expected return value in function but it didn't");return n.value}evaluateBuiltinFunctionCall(e,r){const t=void 0===this.callbackOnStdout?void 0:this.callbackOnStdout.bind(this);return e.body(r,t)}getBooleanComparisonInfixOperationValue(e,r,t){return this.getComparisonInfixOperationValue(e,r,t)}getNumericComparisonInfixOperationValue(e,r,t){return this.getComparisonInfixOperationValue(e,r,t)}getStringComparisonInfixOperationValue(e,r,t){return this.getComparisonInfixOperationValue(e,r,t)}getComparisonInfixOperationValue(e,r,t){return"=="===t?e===r:"!="===t?e!==r:">"===t?e>r:"<"===t?e="===t?e>=r:"<="===t?e<=r:t}getArithmeticInfixOperationValue(e,r,t){return"+"===t?e+r:"-"===t?e-r:"*"===t?e*r:"/"===t?e/r:t}evaluatePrefixNumberExpression(e,r){return"+"===e?this.createNumberValue(r.value,r.range):"-"===e?this.createNumberValue(-r.value,r.range):e}evaluatePrefixBooleanExpression(e,r){return"!"===e?this.createBooleanValue(!r.value,r.range):e}createExtendedEnvironment(e,r,t){const n=new c.default(e);for(let e=0;er===e))}isComparisonInfixOperator(e){return["==","!=",">","<",">=","<="].some((r=>r===e))}};var b=t(404);Object.defineProperty(r,"Environment",{enumerable:!0,get:function(){return o(b).default}})},994:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createReturnValue=r.createBuiltinFunctionValue=r.createFunctionValue=r.createEmptyValue=r.createStringValue=r.createBooleanValue=r.createNumberValue=void 0;const n=t(548),a=e=>(r,t,a)=>Object.assign({type:e,range:(0,n.copyRange)(a.begin,a.end),representation:t},r);r.createNumberValue=a("number"),r.createBooleanValue=a("boolean"),r.createStringValue=a("string"),r.createEmptyValue=a("empty"),r.createFunctionValue=a("function"),r.createBuiltinFunctionValue=a("builtin function"),r.createReturnValue=e=>({type:"return",value:e})},436:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&n(r,e,t);return a(r,e),r},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.execute=void 0;const s=o(t(439)),u=o(t(522)),c=i(t(673));r.execute=(e,r)=>{const t=new s.default(e),n=new u.default(t).parseSource(),a=new c.default;void 0!==r&&a.onStdout(r);const i=new c.Environment,o=a.evaluate(n,i);return String(o.representation)}},545:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.default=class{constructor(e,r){this.chars=e,this.fallbackChar=r,this.index=0,this.row=0,this.col=0}readChar(){if(this.index===this.chars.length)return{value:this.fallbackChar,position:{row:this.row,col:this.col}};const e=this.peekNewLine();return null!==e?{value:e,position:{row:this.row,col:this.col}}:{value:this.chars[this.index],position:{row:this.row,col:this.col}}}advance(){if(this.index===this.chars.length)return;const e=this.peekNewLine();if(null!==e)return this.index+=e.length,++this.row,void(this.col=0);++this.index,++this.col}peekNewLine(){if(this.index===this.chars.length)return null;const e=this.chars[this.index];if("\r"!==e&&"\n"!==e)return null;if(this.index+1===this.chars.length)return e;const r=this.chars[this.index+1];return"\r"!==r&&"\n"!==r?e:e+r}}},197:function(e,r,t){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0});const a=n(t(545));class i{constructor(e){this.reader=new a.default(e,i.END_OF_INPUT)}popChar(){const e=this.reader.readChar();return this.reader.advance(),e}peekChar(){return this.reader.readChar()}}i.END_OF_INPUT="\0",r.default=i},439:function(e,r,t){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0});const a=n(t(197)),i=t(562),o=t(352);r.default=class{constructor(e){this.charBuffer=new a.default(e)}getSourceToken(){this.skipWhitespaceChars();const e=this.charBuffer.peekChar();switch(e.value){case"+":case"-":case"*":case"/":{const{position:r}=this.charBuffer.popChar(),t=e.value;return(0,i.createOperatorToken)(t,r,r)}case"(":case")":{const{position:r}=this.charBuffer.popChar(),t=e.value;return(0,i.createGroupDelimiterToken)(t,r,r)}case"{":case"}":{const{position:r}=this.charBuffer.popChar(),t=e.value;return(0,i.createBlockDelimiterToken)(t,r,r)}case",":{const{position:r}=this.charBuffer.popChar(),t=e.value;return(0,i.createSeparatorToken)(t,r,r)}case"!":{const{position:e}=this.charBuffer.popChar();return this.lexCharsStartingWithBang(e)}case"=":{const{position:e}=this.charBuffer.popChar();return this.lexCharsStartingWithEqual(e)}case">":{const{position:e}=this.charBuffer.popChar();return this.lexCharsStartingWithGreaterThan(e)}case"<":{const{position:e}=this.charBuffer.popChar();return this.lexCharsStartingWithLessThan(e)}case"'":{const{position:e}=this.charBuffer.popChar();return this.lexCharsStartingWithSingleQuote(e)}case a.default.END_OF_INPUT:{const{position:e}=this.charBuffer.popChar();return(0,i.createEndToken)("$end",e,e)}default:{if((0,o.isDigit)(e.value))return this.lexNumberLiteral();if((0,o.isLetter)(e.value))return this.lexLetters();const{position:r}=this.charBuffer.popChar();return(0,i.createIllegalToken)(e.value,r,r)}}}skipWhitespaceChars(){for(;;){const e=this.charBuffer.peekChar();if(!(0,o.isWhitespace)(e.value))break;this.charBuffer.popChar()}}lexCharsStartingWithBang(e){if("="===this.charBuffer.peekChar().value){const{position:r}=this.charBuffer.popChar();return(0,i.createOperatorToken)("!=",e,r)}return(0,i.createOperatorToken)("!",e,e)}lexCharsStartingWithEqual(e){if("="===this.charBuffer.peekChar().value){const{position:r}=this.charBuffer.popChar();return(0,i.createOperatorToken)("==",e,r)}return(0,i.createOperatorToken)("=",e,e)}lexCharsStartingWithGreaterThan(e){if("="===this.charBuffer.peekChar().value){const{position:r}=this.charBuffer.popChar();return(0,i.createOperatorToken)(">=",e,r)}return(0,i.createOperatorToken)(">",e,e)}lexCharsStartingWithLessThan(e){if("="===this.charBuffer.peekChar().value){const{position:r}=this.charBuffer.popChar();return(0,i.createOperatorToken)("<=",e,r)}return(0,i.createOperatorToken)("<",e,e)}lexCharsStartingWithSingleQuote(e){const r=[];for(;;){const t=this.charBuffer.popChar(),n=r.map((e=>e.value)).join(""),o=e,s=t.position;if("'"===t.value)return(0,i.createStringLiteralToken)(n,o,s);if(t.value===a.default.END_OF_INPUT)return(0,i.createIllegalStringLiteralToken)(n,o,s);r.push(t)}}lexNumberLiteral(){const e=this.readDigitChars(),r=this.readDecimalChars(),t=e.concat(r),n=t.map((e=>e.value)).join(""),a=t[0].position,o=t[t.length-1].position;return(0,i.createNumberLiteralToken)(n,a,o)}lexLetters(){const e=this.readLetterChars(),r=e.map((e=>e.value)).join(""),t=e[0].position,n=e[e.length-1].position;switch(r){case"참":case"거짓":return(0,i.createBooleanLiteralToken)(r,t,n);case"만약":case"아니면":case"함수":case"결과":return(0,i.createKeywordToken)(r,t,n);default:return(0,i.createIdentifierToken)(r,t,n)}}readDigitChars(){const e=[];for(;;){const r=this.charBuffer.peekChar();if(!(0,o.isDigit)(r.value))break;e.push(this.charBuffer.popChar())}return e}readDecimalChars(){if("."!==this.charBuffer.peekChar().value)return[];const e=this.charBuffer.popChar(),r=this.readDigitChars();return[e].concat(r)}readLetterChars(){const e=[];for(;;){const r=this.charBuffer.peekChar();if(!(0,o.isLetter)(r.value)&&!(0,o.isDigit)(r.value))break;e.push(this.charBuffer.popChar())}return e}}},854:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createTokenCreator=void 0,r.createTokenCreator=function(e){return function(r,t,n){return void 0!==n?{type:e,value:r,range:{begin:t,end:n}}:{type:e,value:r,range:t}}}},287:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createSeparatorToken=r.createBlockDelimiterToken=r.createGroupDelimiterToken=void 0;const n=t(854);r.createGroupDelimiterToken=(0,n.createTokenCreator)("group delimiter"),r.createBlockDelimiterToken=(0,n.createTokenCreator)("block delimiter"),r.createSeparatorToken=(0,n.createTokenCreator)("separator")},762:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createKeywordToken=r.createIdentifierToken=void 0;const n=t(854);r.createIdentifierToken=(0,n.createTokenCreator)("identifier"),r.createKeywordToken=(0,n.createTokenCreator)("keyword")},562:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),a(t(547),r),a(t(762),r),a(t(768),r),a(t(287),r),a(t(763),r)},768:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createStringLiteralToken=r.createBooleanLiteralToken=r.createNumberLiteralToken=void 0;const n=t(854);r.createNumberLiteralToken=(0,n.createTokenCreator)("number literal"),r.createBooleanLiteralToken=(0,n.createTokenCreator)("boolean literal"),r.createStringLiteralToken=(0,n.createTokenCreator)("string literal")},547:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createOperatorToken=void 0;const n=t(854);r.createOperatorToken=(0,n.createTokenCreator)("operator")},763:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createEndToken=r.createIllegalStringLiteralToken=r.createIllegalToken=r.END_VALUE=void 0;const n=t(854);r.END_VALUE="$end",r.createIllegalToken=(0,n.createTokenCreator)("illegal"),r.createIllegalStringLiteralToken=(0,n.createTokenCreator)("illegal string"),r.createEndToken=(0,n.createTokenCreator)("end")},352:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.isWhitespace=r.isDigit=r.isLetter=void 0,r.isLetter=e=>1===e.length&&/^[a-zA-Z가-힣_]$/.test(e),r.isDigit=e=>1===e.length&&/^[0-9]$/.test(e),r.isWhitespace=e=>!(e.length>2)&&/^(\r\n|[ \t\r\n])$/.test(e)},817:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.getInfixBindingPower=r.bindingPowers=void 0,r.bindingPowers={lowest:{left:0,right:1},assignment:{left:31,right:30},comparison:{left:41,right:40},summative:{left:50,right:51},productive:{left:60,right:61},prefix:{left:70,right:71},call:{left:80,right:81}},r.getInfixBindingPower=e=>{switch(e){case"=":return r.bindingPowers.assignment;case"==":case"!=":case">":case"<":case">=":case"<=":return r.bindingPowers.comparison;case"+":case"-":return r.bindingPowers.summative;case"*":case"/":return r.bindingPowers.productive;case"(":return r.bindingPowers.call;default:return r.bindingPowers.lowest}}},522:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&n(r,e,t);return a(r,e),r},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.BadSeparatorError=r.BadIdentifierError=r.BadFunctionKeywordError=r.BadAssignmentError=r.BadBlockDelimiterError=r.BadGroupDelimiterError=r.BadExpressionError=r.BadInfixError=r.BadPrefixError=r.BadBooleanLiteralError=r.BadNumberLiteralError=r.ParserError=void 0;const s=i(t(39)),u=t(817),c=t(548);class l extends Error{constructor(e,r,t){super(),this.received=e,this.expected=r,this.range=t}}r.ParserError=l;class d extends l{}r.BadNumberLiteralError=d;class h extends l{}r.BadBooleanLiteralError=h;class p extends l{}r.BadPrefixError=p;class f extends l{}r.BadInfixError=f;class g extends l{}r.BadExpressionError=g;class v extends l{}r.BadGroupDelimiterError=v;class b extends l{}r.BadBlockDelimiterError=b;class x extends l{}r.BadAssignmentError=x;class m extends l{}r.BadFunctionKeywordError=m;class y extends l{}r.BadIdentifierError=y;class _ extends l{}r.BadSeparatorError=_;const w=o(t(405));class E{constructor(e){this.reader=new w.default(e)}parseSource(){const e=[];for(;!this.reader.isEnd();)e.push(this.parseStatement());const r={row:0,col:0},t=e.length>0?e[0].range.begin:r,n=e.length>0?e[e.length-1].range.end:r;return s.createProgramNode({statements:e},t,n)}parseBlock(){const e=this.reader.read();this.advanceOrThrow("block delimiter","{",b);const r=[];for(;;){const t=this.reader.read();if("block delimiter"===t.type&&"}"===t.value){this.reader.advance();const n=(0,c.copyRange)(e.range.begin,t.range.end);return s.createBlockNode({statements:r},n)}const n=this.parseStatement();r.push(n)}}parseStatement(){const e=this.reader.read(),{type:r,value:t}=e;return"keyword"===r&&"만약"===t?this.parseBranchStatement():"keyword"===r&&"결과"===t?this.parseReturnStatement():this.parseExpressionStatement()}parseBranchStatement(){const e=this.reader.read();this.reader.advance();const r=this.parseExpression(u.bindingPowers.lowest),t=this.parseBlock(),n=this.reader.read();if("keyword"!==n.type||"아니면"!==n.value){const n={begin:e.range.begin,end:t.range.end};return s.createBranchNode({predicate:r,consequence:t},n)}this.reader.advance();const a=this.parseBlock(),i={begin:e.range.begin,end:a.range.end};return s.createBranchNode({predicate:r,consequence:t,alternative:a},i)}parseReturnStatement(){const e=this.reader.read();this.reader.advance();const r=this.parseExpression(u.bindingPowers.lowest),t={begin:e.range.begin,end:r.range.end};return s.createReturnNode({expression:r},t)}parseExpressionStatement(){const e=this.parseExpression(u.bindingPowers.lowest),r=e.range;return s.createExpressionStatementNode({expression:e},r)}parseExpression(e){let r=this.parseExpressionStart();for(;!((0,u.getInfixBindingPower)(this.reader.read().value).left<=e.right);){const e=this.parseExpressionMiddle(r);if(null===e)break;r=e}return r}parseExpressionStart(){const{type:e,value:r,range:t}=this.reader.read();if("number literal"===e)return this.parseNumberLiteral();if("boolean literal"===e)return this.parseBooleanLiteral();if("string literal"===e)return this.parseStringLiteral();if("identifier"===e)return this.parseIdentifier();if("operator"===e&&this.isPrefixOperator(r))return this.parsePrefix();if("keyword"===e&&"함수"===r)return this.parseFunction();if("group delimiter"===e&&"("===r)return this.parseGroupedExpression();throw new g(e,"expression",t)}parseExpressionMiddle(e){const{type:r,value:t}=this.reader.read();return"group delimiter"===r&&"("===t?"function"!==e.type&&"identifier"!==e.type?null:this.parseCall(e):"operator"===r&&this.isInfixOperator(t)?this.parseInfix(e):"operator"===r&&"="===t&&"identifier"===e.type?this.parseAssignment(e):null}parseCall(e){this.advanceOrThrow("group delimiter","(",v);const r=this.reader.read();if("group delimiter"===r.type&&")"===r.value){this.reader.advance();const t=(0,c.copyRange)(e.range.begin,r.range.end);return s.createCallNode({func:e,args:[]},t)}const t=[this.parseExpression(u.bindingPowers.lowest)];for(;"separator"===this.reader.read().type;)this.reader.advance(),t.push(this.parseExpression(u.bindingPowers.lowest));const n=this.reader.read();this.advanceOrThrow("group delimiter",")",v);const a=(0,c.copyRange)(e.range.begin,n.range.end);return s.createCallNode({func:e,args:t},a)}parseAssignment(e){const{value:r,range:t}=this.reader.read();if(this.reader.advance(),"="!==r)throw new x(r,"=",t);const n=r,a=(0,u.getInfixBindingPower)(n),i=this.parseExpression(a),o={begin:e.range.begin,end:i.range.end};return s.createAssignmentNode({left:e,right:i},o)}parseNumberLiteral(){const{value:e,range:r}=this.reader.read();this.reader.advance();const t=Number(e);if(Number.isNaN(t))throw new d(e,"non NaN",r);return s.createNumberNode({value:t},r)}parseBooleanLiteral(){const{value:e,range:r}=this.reader.read();let t;if(this.reader.advance(),"참"===e)t=!0;else{if("거짓"!==e)throw new h(e,"참, 거짓",r);t=!1}return s.createBooleanNode({value:t},r)}parseStringLiteral(){const{value:e,range:r}=this.reader.read();return this.reader.advance(),s.createStringNode({value:e},r)}parseIdentifier(){const{type:e,value:r,range:t}=this.reader.read();if(this.reader.advance(),"identifier"!==e)throw new y(e,"identifier",t);return s.createIdentifierNode({value:r},t)}parsePrefix(){const{value:e,range:r}=this.reader.read();if(this.reader.advance(),!this.isPrefixOperator(e))throw new p(e,"prefix operator",r);const t=e,n=this.parseExpression(u.bindingPowers.prefix);return s.createPrefixNode({prefix:t,right:n},r)}parseInfix(e){const{value:r,range:t}=this.reader.read();if(this.reader.advance(),!this.isInfixOperator(r))throw new f(r,"infix operator",t);const n=r,a=(0,u.getInfixBindingPower)(n),i=this.parseExpression(a),o=(0,c.copyRange)(e.range.begin,i.range.end);return s.createInfixNode({infix:n,left:e,right:i},o)}parseFunction(){const e=this.reader.read();this.advanceOrThrow("keyword","함수",m);const r=this.parseParameters(),t=this.parseBlock(),n=(0,c.copyRange)(e.range.begin,t.range.end);return s.createFunctionNode({parameters:r,body:t},n)}parseParameters(){this.advanceOrThrow("group delimiter","(",v);const e=this.reader.read();if("group delimiter"===e.type&&")"===e.value)return this.reader.advance(),[];const r=[this.parseIdentifier()];for(;;){const e=this.reader.read();if(this.reader.advance(),"group delimiter"===e.type&&")"===e.value)return r;if("separator"!==e.type)throw new _(e.type,",",e.range);r.push(this.parseIdentifier())}}parseGroupedExpression(){this.advanceOrThrow("group delimiter","(",v);const e=this.parseExpression(u.bindingPowers.lowest);this.advanceOrThrow("group delimiter",")",v);const r=(0,c.copyRange)(e.range.begin,e.range.end,{begin:{row:0,col:-1},end:{row:0,col:1}});return Object.assign(Object.assign({},e),{range:r})}advanceOrThrow(e,r,t){const n=this.reader.read();if(this.reader.advance(),n.type!==e||n.value!==r)throw new t(n.value,r,n.range)}isPrefixOperator(e){return E.PREFIX_OPERATORS.some((r=>r===e))}isInfixOperator(e){return E.INFIX_OPERATORS.some((r=>r===e))}}E.PREFIX_OPERATORS=["+","-","!"],E.INFIX_OPERATORS=["+","-","*","/","!=","==",">","<",">=","<="],r.default=E},405:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.default=class{constructor(e){this.lexer=e,this.token=e.getSourceToken()}read(){return this.token}advance(){this.token=this.lexer.getSourceToken()}isEnd(){return"end"===this.token.type}}},662:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createNodeCreator=void 0;const n=t(548);r.createNodeCreator=function(e){return function(r,t,a){if(void 0!==a)return Object.assign({type:e,range:(0,n.copyRange)(t,a)},r);const i=t;return Object.assign({type:e,range:(0,n.copyRange)(i.begin,i.end)},r)}}},878:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createAssignmentNode=r.createCallNode=r.createFunctionNode=r.createInfixNode=r.createPrefixNode=r.createStringNode=r.createBooleanNode=r.createNumberNode=r.createIdentifierNode=void 0;const n=t(662);r.createIdentifierNode=(0,n.createNodeCreator)("identifier"),r.createNumberNode=(0,n.createNodeCreator)("number"),r.createBooleanNode=(0,n.createNodeCreator)("boolean"),r.createStringNode=(0,n.createNodeCreator)("string"),r.createPrefixNode=(0,n.createNodeCreator)("prefix"),r.createInfixNode=(0,n.createNodeCreator)("infix"),r.createFunctionNode=(0,n.createNodeCreator)("function"),r.createCallNode=(0,n.createNodeCreator)("call"),r.createAssignmentNode=(0,n.createNodeCreator)("assignment")},701:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createBlockNode=r.createProgramNode=void 0;const n=t(662);r.createProgramNode=(0,n.createNodeCreator)("program"),r.createBlockNode=(0,n.createNodeCreator)("block")},39:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),a(t(701),r),a(t(234),r),a(t(878),r)},234:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createExpressionStatementNode=r.createReturnNode=r.createBranchNode=void 0;const n=t(662);r.createBranchNode=(0,n.createNodeCreator)("branch"),r.createReturnNode=(0,n.createNodeCreator)("return"),r.createExpressionStatementNode=(0,n.createNodeCreator)("expression statement")},548:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.copyRange=r.copyPosition=void 0,r.copyPosition=(e,r)=>{var t,n;return{row:e.row+(null!==(t=null==r?void 0:r.row)&&void 0!==t?t:0),col:e.col+(null!==(n=null==r?void 0:r.col)&&void 0!==n?n:0)}},r.copyRange=(e,t,n)=>({begin:(0,r.copyPosition)(e,null==n?void 0:n.begin),end:(0,r.copyPosition)(t,null==n?void 0:n.end)})}},r={},t=function t(n){var a=r[n];if(void 0!==a)return a.exports;var i=r[n]={exports:{}};return e[n].call(i.exports,i,i.exports,t),i.exports}(436);window.kal=t})(); \ No newline at end of file +(()=>{"use strict";var e={44:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&n(r,e,t);return a(r,e),r};Object.defineProperty(r,"__esModule",{value:!0});const o=i(t(994)),s=e=>{const r=e[0];if("string"===r.type){const e=r.value.length;return o.createNumberValue({value:e},String(e),r.range)}throw new Error},u=(e,r)=>{if(0===e.length)throw new Error;const t=e.map((e=>e.representation)).join(" ");void 0!==r&&r(t);const n={begin:e[0].range.begin,end:e[e.length-1].range.end};return o.createEmptyValue({value:null},"(없음)",n)},c={get(e){switch(e){case"길이":return s;case"쓰기":return u;default:return null}}};r.default=c},404:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.default=class{constructor(e=null){this.superEnvironment=e,this.table=new Map}get(e){const r=this.table.get(e);return void 0!==r?r:null===this.superEnvironment?null:this.superEnvironment.get(e)}set(e,r){this.table.set(e,r)}}},673:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&n(r,e,t);return a(r,e),r},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.Environment=r.BadIdentifierError=r.BadInfixExpressionError=r.BadPrefixExpressionError=r.BadAssignmentLeftError=r.BadPredicateError=r.TopLevelReturnError=r.EvalError=void 0;const s=i(t(994)),u=o(t(44)),c=o(t(404));class l extends Error{constructor(e,r){super(),this.range=e,this.received=r}}r.EvalError=l;class d extends l{}r.TopLevelReturnError=d;class p extends l{}r.BadPredicateError=p;class h extends l{}r.BadAssignmentLeftError=h;class f extends l{}r.BadPrefixExpressionError=f;class g extends l{}r.BadInfixExpressionError=g;class v extends l{}r.BadIdentifierError=v,r.default=class{evaluate(e,r){return this.evaluateProgram(e,r)}onStdout(e){this.callbackOnStdout=e}evaluateProgram(e,r){const{statements:t}=e;let n=null;for(let a=0;athis.evaluateExpression(e,r)))}evaluateFunctionCall(e,r){const t=this.createExtendedEnvironment(e.environment,e.parameters,r),n=this.evaluateBlock(e.body,t);if("return"!==n.type)throw new Error("expected return value in function but it didn't");return n.value}evaluateBuiltinFunctionCall(e,r){const t=void 0===this.callbackOnStdout?void 0:this.callbackOnStdout.bind(this);return e.body(r,t)}getBooleanComparisonInfixOperationValue(e,r,t){return this.getComparisonInfixOperationValue(e,r,t)}getNumericComparisonInfixOperationValue(e,r,t){return this.getComparisonInfixOperationValue(e,r,t)}getStringComparisonInfixOperationValue(e,r,t){return this.getComparisonInfixOperationValue(e,r,t)}getComparisonInfixOperationValue(e,r,t){return"=="===t?e===r:"!="===t?e!==r:">"===t?e>r:"<"===t?e="===t?e>=r:"<="===t?e<=r:t}getArithmeticInfixOperationValue(e,r,t){return"+"===t?e+r:"-"===t?e-r:"*"===t?e*r:"/"===t?e/r:t}evaluatePrefixNumberExpression(e,r){return"+"===e?this.createNumberValue(r.value,r.range):"-"===e?this.createNumberValue(-r.value,r.range):e}evaluatePrefixBooleanExpression(e,r){return"!"===e?this.createBooleanValue(!r.value,r.range):e}createExtendedEnvironment(e,r,t){const n=new c.default(e);for(let e=0;er===e))}isComparisonInfixOperator(e){return["==","!=",">","<",">=","<="].some((r=>r===e))}};var b=t(404);Object.defineProperty(r,"Environment",{enumerable:!0,get:function(){return o(b).default}})},994:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createReturnValue=r.createBuiltinFunctionValue=r.createFunctionValue=r.createEmptyValue=r.createStringValue=r.createBooleanValue=r.createNumberValue=void 0;const n=t(548),a=e=>(r,t,a)=>Object.assign({type:e,range:(0,n.copyRange)(a.begin,a.end),representation:t},r);r.createNumberValue=a("number"),r.createBooleanValue=a("boolean"),r.createStringValue=a("string"),r.createEmptyValue=a("empty"),r.createFunctionValue=a("function"),r.createBuiltinFunctionValue=a("builtin function"),r.createReturnValue=e=>({type:"return",value:e})},436:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&n(r,e,t);return a(r,e),r},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.execute=void 0;const s=o(t(439)),u=o(t(522)),c=i(t(673));r.execute=(e,r)=>{const t=new s.default(e),n=new u.default(t).parseSource(),a=new c.default;void 0!==r&&a.onStdout(r);const i=new c.Environment,o=a.evaluate(n,i);return String(o.representation)}},545:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.default=class{constructor(e,r){this.chars=e,this.fallbackChar=r,this.index=0,this.row=0,this.col=0}readChar(){if(this.index===this.chars.length)return{value:this.fallbackChar,position:{row:this.row,col:this.col}};const e=this.peekNewLine();return null!==e?{value:e,position:{row:this.row,col:this.col}}:{value:this.chars[this.index],position:{row:this.row,col:this.col}}}advance(){if(this.index===this.chars.length)return;const e=this.peekNewLine();if(null!==e)return this.index+=e.length,++this.row,void(this.col=0);++this.index,++this.col}peekNewLine(){if(this.index===this.chars.length)return null;const e=this.chars[this.index];if("\r"!==e&&"\n"!==e)return null;if(this.index+1===this.chars.length)return e;const r=this.chars[this.index+1];return"\r"!==r&&"\n"!==r?e:e+r}}},197:function(e,r,t){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0});const a=n(t(545));class i{constructor(e){this.reader=new a.default(e,i.END_OF_INPUT)}popChar(){const e=this.reader.readChar();return this.reader.advance(),e}peekChar(){return this.reader.readChar()}}i.END_OF_INPUT="\0",r.default=i},439:function(e,r,t){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0});const a=n(t(197)),i=t(562),o=t(352);r.default=class{constructor(e){this.charBuffer=new a.default(e)}getSourceToken(){this.skipWhitespaceChars();const e=this.charBuffer.peekChar();switch(e.value){case"+":case"-":case"*":case"/":{const{position:r}=this.charBuffer.popChar(),t=e.value;return(0,i.createOperatorToken)(t,r,r)}case"(":case")":{const{position:r}=this.charBuffer.popChar(),t=e.value;return(0,i.createGroupDelimiterToken)(t,r,r)}case"{":case"}":{const{position:r}=this.charBuffer.popChar(),t=e.value;return(0,i.createBlockDelimiterToken)(t,r,r)}case",":{const{position:r}=this.charBuffer.popChar(),t=e.value;return(0,i.createSeparatorToken)(t,r,r)}case"!":{const{position:e}=this.charBuffer.popChar();return this.lexCharsStartingWithBang(e)}case"=":{const{position:e}=this.charBuffer.popChar();return this.lexCharsStartingWithEqual(e)}case">":{const{position:e}=this.charBuffer.popChar();return this.lexCharsStartingWithGreaterThan(e)}case"<":{const{position:e}=this.charBuffer.popChar();return this.lexCharsStartingWithLessThan(e)}case"'":{const{position:e}=this.charBuffer.popChar();return this.lexCharsStartingWithSingleQuote(e)}case a.default.END_OF_INPUT:{const{position:e}=this.charBuffer.popChar();return(0,i.createEndToken)("$end",e,e)}default:{if((0,o.isDigit)(e.value))return this.lexNumberLiteral();if((0,o.isLetter)(e.value))return this.lexLetters();const{position:r}=this.charBuffer.popChar();return(0,i.createIllegalToken)(e.value,r,r)}}}skipWhitespaceChars(){for(;;){const e=this.charBuffer.peekChar();if(!(0,o.isWhitespace)(e.value))break;this.charBuffer.popChar()}}lexCharsStartingWithBang(e){if("="===this.charBuffer.peekChar().value){const{position:r}=this.charBuffer.popChar();return(0,i.createOperatorToken)("!=",e,r)}return(0,i.createOperatorToken)("!",e,e)}lexCharsStartingWithEqual(e){if("="===this.charBuffer.peekChar().value){const{position:r}=this.charBuffer.popChar();return(0,i.createOperatorToken)("==",e,r)}return(0,i.createOperatorToken)("=",e,e)}lexCharsStartingWithGreaterThan(e){if("="===this.charBuffer.peekChar().value){const{position:r}=this.charBuffer.popChar();return(0,i.createOperatorToken)(">=",e,r)}return(0,i.createOperatorToken)(">",e,e)}lexCharsStartingWithLessThan(e){if("="===this.charBuffer.peekChar().value){const{position:r}=this.charBuffer.popChar();return(0,i.createOperatorToken)("<=",e,r)}return(0,i.createOperatorToken)("<",e,e)}lexCharsStartingWithSingleQuote(e){const r=[];for(;;){const t=this.charBuffer.popChar(),n=r.map((e=>e.value)).join(""),o=e,s=t.position;if("'"===t.value)return(0,i.createStringLiteralToken)(n,o,s);if(t.value===a.default.END_OF_INPUT)return(0,i.createIllegalStringLiteralToken)(n,o,s);r.push(t)}}lexNumberLiteral(){const e=this.readDigitChars(),r=this.readDecimalChars(),t=e.concat(r),n=t.map((e=>e.value)).join(""),a=t[0].position,o=t[t.length-1].position;return(0,i.createNumberLiteralToken)(n,a,o)}lexLetters(){const e=this.readLetterChars(),r=e.map((e=>e.value)).join(""),t=e[0].position,n=e[e.length-1].position;switch(r){case"참":case"거짓":return(0,i.createBooleanLiteralToken)(r,t,n);case"만약":case"아니면":case"함수":case"결과":return(0,i.createKeywordToken)(r,t,n);default:return(0,i.createIdentifierToken)(r,t,n)}}readDigitChars(){const e=[];for(;;){const r=this.charBuffer.peekChar();if(!(0,o.isDigit)(r.value))break;e.push(this.charBuffer.popChar())}return e}readDecimalChars(){if("."!==this.charBuffer.peekChar().value)return[];const e=this.charBuffer.popChar(),r=this.readDigitChars();return[e].concat(r)}readLetterChars(){const e=[];for(;;){const r=this.charBuffer.peekChar();if(!(0,o.isLetter)(r.value)&&!(0,o.isDigit)(r.value))break;e.push(this.charBuffer.popChar())}return e}}},854:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createTokenCreator=void 0,r.createTokenCreator=function(e){return function(r,t,n){return void 0!==n?{type:e,value:r,range:{begin:t,end:n}}:{type:e,value:r,range:t}}}},287:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createSeparatorToken=r.createBlockDelimiterToken=r.createGroupDelimiterToken=void 0;const n=t(854);r.createGroupDelimiterToken=(0,n.createTokenCreator)("group delimiter"),r.createBlockDelimiterToken=(0,n.createTokenCreator)("block delimiter"),r.createSeparatorToken=(0,n.createTokenCreator)("separator")},762:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createKeywordToken=r.createIdentifierToken=void 0;const n=t(854);r.createIdentifierToken=(0,n.createTokenCreator)("identifier"),r.createKeywordToken=(0,n.createTokenCreator)("keyword")},562:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),a(t(547),r),a(t(762),r),a(t(768),r),a(t(287),r),a(t(763),r)},768:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createStringLiteralToken=r.createBooleanLiteralToken=r.createNumberLiteralToken=void 0;const n=t(854);r.createNumberLiteralToken=(0,n.createTokenCreator)("number literal"),r.createBooleanLiteralToken=(0,n.createTokenCreator)("boolean literal"),r.createStringLiteralToken=(0,n.createTokenCreator)("string literal")},547:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createOperatorToken=void 0;const n=t(854);r.createOperatorToken=(0,n.createTokenCreator)("operator")},763:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createEndToken=r.createIllegalStringLiteralToken=r.createIllegalToken=r.END_VALUE=void 0;const n=t(854);r.END_VALUE="$end",r.createIllegalToken=(0,n.createTokenCreator)("illegal"),r.createIllegalStringLiteralToken=(0,n.createTokenCreator)("illegal string"),r.createEndToken=(0,n.createTokenCreator)("end")},352:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.isWhitespace=r.isDigit=r.isLetter=void 0,r.isLetter=e=>1===e.length&&/^[a-zA-Z가-힣_]$/.test(e),r.isDigit=e=>1===e.length&&/^[0-9]$/.test(e),r.isWhitespace=e=>!(e.length>2)&&/^(\r\n|[ \t\r\n])$/.test(e)},817:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.getInfixBindingPower=r.bindingPowers=void 0,r.bindingPowers={lowest:{left:0,right:1},assignment:{left:31,right:30},comparison:{left:41,right:40},summative:{left:50,right:51},productive:{left:60,right:61},prefix:{left:70,right:71},call:{left:80,right:81}},r.getInfixBindingPower=e=>{switch(e){case"=":return r.bindingPowers.assignment;case"==":case"!=":case">":case"<":case">=":case"<=":return r.bindingPowers.comparison;case"+":case"-":return r.bindingPowers.summative;case"*":case"/":return r.bindingPowers.productive;case"(":return r.bindingPowers.call;default:return r.bindingPowers.lowest}}},522:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&n(r,e,t);return a(r,e),r},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.BadSeparatorError=r.BadIdentifierError=r.BadFunctionKeywordError=r.BadAssignmentError=r.BadBlockDelimiterError=r.BadGroupDelimiterError=r.BadExpressionError=r.BadInfixError=r.BadPrefixError=r.BadBooleanLiteralError=r.BadNumberLiteralError=r.ParserError=void 0;const s=i(t(39)),u=t(817),c=t(548);class l extends Error{constructor(e,r,t){super(),this.received=e,this.expected=r,this.range=t}}r.ParserError=l;class d extends l{}r.BadNumberLiteralError=d;class p extends l{}r.BadBooleanLiteralError=p;class h extends l{}r.BadPrefixError=h;class f extends l{}r.BadInfixError=f;class g extends l{}r.BadExpressionError=g;class v extends l{}r.BadGroupDelimiterError=v;class b extends l{}r.BadBlockDelimiterError=b;class x extends l{}r.BadAssignmentError=x;class m extends l{}r.BadFunctionKeywordError=m;class y extends l{}r.BadIdentifierError=y;class _ extends l{}r.BadSeparatorError=_;const w=o(t(405));class E{constructor(e){this.reader=new w.default(e)}parseSource(){const e=[];for(;!this.reader.isEnd();)e.push(this.parseStatement());const r={row:0,col:0},t=e.length>0?e[0].range.begin:r,n=e.length>0?e[e.length-1].range.end:r;return s.createProgramNode({statements:e},t,n)}parseBlock(){const e=this.reader.read();this.advanceOrThrow("block delimiter","{",b);const r=[];for(;;){const t=this.reader.read();if("block delimiter"===t.type&&"}"===t.value){this.reader.advance();const n=(0,c.copyRange)(e.range.begin,t.range.end);return s.createBlockNode({statements:r},n)}const n=this.parseStatement();r.push(n)}}parseStatement(){const e=this.reader.read(),{type:r,value:t}=e;return"keyword"===r&&"만약"===t?this.parseBranchStatement():"keyword"===r&&"결과"===t?this.parseReturnStatement():this.parseExpressionStatement()}parseBranchStatement(){const e=this.reader.read();this.reader.advance();const r=this.parseExpression(u.bindingPowers.lowest),t=this.parseBlock(),n=this.reader.read();if("keyword"!==n.type||"아니면"!==n.value){const n={begin:e.range.begin,end:t.range.end};return s.createBranchNode({predicate:r,consequence:t},n)}this.reader.advance();const a=this.parseBlock(),i={begin:e.range.begin,end:a.range.end};return s.createBranchNode({predicate:r,consequence:t,alternative:a},i)}parseReturnStatement(){const e=this.reader.read();this.reader.advance();const r=this.parseExpression(u.bindingPowers.lowest),t={begin:e.range.begin,end:r.range.end};return s.createReturnNode({expression:r},t)}parseExpressionStatement(){const e=this.parseExpression(u.bindingPowers.lowest),r=e.range;return s.createExpressionStatementNode({expression:e},r)}parseExpression(e){let r=this.parseExpressionStart();for(;!((0,u.getInfixBindingPower)(this.reader.read().value).left<=e.right);){const e=this.parseExpressionMiddle(r);if(null===e)break;r=e}return r}parseExpressionStart(){const{type:e,value:r,range:t}=this.reader.read();if("number literal"===e)return this.parseNumberLiteral();if("boolean literal"===e)return this.parseBooleanLiteral();if("string literal"===e)return this.parseStringLiteral();if("identifier"===e)return this.parseIdentifier();if("operator"===e&&this.isPrefixOperator(r))return this.parsePrefix();if("keyword"===e&&"함수"===r)return this.parseFunction();if("group delimiter"===e&&"("===r)return this.parseGroupedExpression();throw new g(e,"expression",t)}parseExpressionMiddle(e){const{type:r,value:t}=this.reader.read();return"group delimiter"===r&&"("===t?"function"!==e.type&&"identifier"!==e.type&&"call"!==e.type?null:this.parseCall(e):"operator"===r&&this.isInfixOperator(t)?this.parseInfix(e):"operator"===r&&"="===t&&"identifier"===e.type?this.parseAssignment(e):null}parseCall(e){this.advanceOrThrow("group delimiter","(",v);const r=this.reader.read();if("group delimiter"===r.type&&")"===r.value){this.reader.advance();const t=(0,c.copyRange)(e.range.begin,r.range.end);return s.createCallNode({func:e,args:[]},t)}const t=[this.parseExpression(u.bindingPowers.lowest)];for(;"separator"===this.reader.read().type;)this.reader.advance(),t.push(this.parseExpression(u.bindingPowers.lowest));const n=this.reader.read();this.advanceOrThrow("group delimiter",")",v);const a=(0,c.copyRange)(e.range.begin,n.range.end);return s.createCallNode({func:e,args:t},a)}parseAssignment(e){const{value:r,range:t}=this.reader.read();if(this.reader.advance(),"="!==r)throw new x(r,"=",t);const n=r,a=(0,u.getInfixBindingPower)(n),i=this.parseExpression(a),o={begin:e.range.begin,end:i.range.end};return s.createAssignmentNode({left:e,right:i},o)}parseNumberLiteral(){const{value:e,range:r}=this.reader.read();this.reader.advance();const t=Number(e);if(Number.isNaN(t))throw new d(e,"non NaN",r);return s.createNumberNode({value:t},r)}parseBooleanLiteral(){const{value:e,range:r}=this.reader.read();let t;if(this.reader.advance(),"참"===e)t=!0;else{if("거짓"!==e)throw new p(e,"참, 거짓",r);t=!1}return s.createBooleanNode({value:t},r)}parseStringLiteral(){const{value:e,range:r}=this.reader.read();return this.reader.advance(),s.createStringNode({value:e},r)}parseIdentifier(){const{type:e,value:r,range:t}=this.reader.read();if(this.reader.advance(),"identifier"!==e)throw new y(e,"identifier",t);return s.createIdentifierNode({value:r},t)}parsePrefix(){const{value:e,range:r}=this.reader.read();if(this.reader.advance(),!this.isPrefixOperator(e))throw new h(e,"prefix operator",r);const t=e,n=this.parseExpression(u.bindingPowers.prefix);return s.createPrefixNode({prefix:t,right:n},r)}parseInfix(e){const{value:r,range:t}=this.reader.read();if(this.reader.advance(),!this.isInfixOperator(r))throw new f(r,"infix operator",t);const n=r,a=(0,u.getInfixBindingPower)(n),i=this.parseExpression(a),o=(0,c.copyRange)(e.range.begin,i.range.end);return s.createInfixNode({infix:n,left:e,right:i},o)}parseFunction(){const e=this.reader.read();this.advanceOrThrow("keyword","함수",m);const r=this.parseParameters(),t=this.parseBlock(),n=(0,c.copyRange)(e.range.begin,t.range.end);return s.createFunctionNode({parameters:r,body:t},n)}parseParameters(){this.advanceOrThrow("group delimiter","(",v);const e=this.reader.read();if("group delimiter"===e.type&&")"===e.value)return this.reader.advance(),[];const r=[this.parseIdentifier()];for(;;){const e=this.reader.read();if(this.reader.advance(),"group delimiter"===e.type&&")"===e.value)return r;if("separator"!==e.type)throw new _(e.type,",",e.range);r.push(this.parseIdentifier())}}parseGroupedExpression(){this.advanceOrThrow("group delimiter","(",v);const e=this.parseExpression(u.bindingPowers.lowest);this.advanceOrThrow("group delimiter",")",v);const r=(0,c.copyRange)(e.range.begin,e.range.end,{begin:{row:0,col:-1},end:{row:0,col:1}});return Object.assign(Object.assign({},e),{range:r})}advanceOrThrow(e,r,t){const n=this.reader.read();if(this.reader.advance(),n.type!==e||n.value!==r)throw new t(n.value,r,n.range)}isPrefixOperator(e){return E.PREFIX_OPERATORS.some((r=>r===e))}isInfixOperator(e){return E.INFIX_OPERATORS.some((r=>r===e))}}E.PREFIX_OPERATORS=["+","-","!"],E.INFIX_OPERATORS=["+","-","*","/","!=","==",">","<",">=","<="],r.default=E},405:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.default=class{constructor(e){this.lexer=e,this.token=e.getSourceToken()}read(){return this.token}advance(){this.token=this.lexer.getSourceToken()}isEnd(){return"end"===this.token.type}}},662:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createNodeCreator=void 0;const n=t(548);r.createNodeCreator=function(e){return function(r,t,a){if(void 0!==a)return Object.assign({type:e,range:(0,n.copyRange)(t,a)},r);const i=t;return Object.assign({type:e,range:(0,n.copyRange)(i.begin,i.end)},r)}}},878:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createAssignmentNode=r.createCallNode=r.createFunctionNode=r.createInfixNode=r.createPrefixNode=r.createStringNode=r.createBooleanNode=r.createNumberNode=r.createIdentifierNode=void 0;const n=t(662);r.createIdentifierNode=(0,n.createNodeCreator)("identifier"),r.createNumberNode=(0,n.createNodeCreator)("number"),r.createBooleanNode=(0,n.createNodeCreator)("boolean"),r.createStringNode=(0,n.createNodeCreator)("string"),r.createPrefixNode=(0,n.createNodeCreator)("prefix"),r.createInfixNode=(0,n.createNodeCreator)("infix"),r.createFunctionNode=(0,n.createNodeCreator)("function"),r.createCallNode=(0,n.createNodeCreator)("call"),r.createAssignmentNode=(0,n.createNodeCreator)("assignment")},701:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createBlockNode=r.createProgramNode=void 0;const n=t(662);r.createProgramNode=(0,n.createNodeCreator)("program"),r.createBlockNode=(0,n.createNodeCreator)("block")},39:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,a)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),a=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),a(t(701),r),a(t(234),r),a(t(878),r)},234:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createExpressionStatementNode=r.createReturnNode=r.createBranchNode=void 0;const n=t(662);r.createBranchNode=(0,n.createNodeCreator)("branch"),r.createReturnNode=(0,n.createNodeCreator)("return"),r.createExpressionStatementNode=(0,n.createNodeCreator)("expression statement")},548:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.copyRange=r.copyPosition=void 0,r.copyPosition=(e,r)=>{var t,n;return{row:e.row+(null!==(t=null==r?void 0:r.row)&&void 0!==t?t:0),col:e.col+(null!==(n=null==r?void 0:r.col)&&void 0!==n?n:0)}},r.copyRange=(e,t,n)=>({begin:(0,r.copyPosition)(e,null==n?void 0:n.begin),end:(0,r.copyPosition)(t,null==n?void 0:n.end)})}},r={},t=function t(n){var a=r[n];if(void 0!==a)return a.exports;var i=r[n]={exports:{}};return e[n].call(i.exports,i,i.exports,t),i.exports}(436);window.kal=t})(); \ No newline at end of file