From e93083a3a6d8216956519b07c6ed83404a2ff749 Mon Sep 17 00:00:00 2001 From: Won-hee Cho <89635107+wcho21@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:37:45 +0900 Subject: [PATCH 1/3] support curried function call (#62) --- src/evaluator/index.test.ts | 5 ++ src/index.test.ts | 12 ++++ src/lexer/index.test.ts | 69 ++++++++++++++++++++++ src/parser/index.test.ts | 34 +++++++++++ src/parser/index.ts | 4 +- src/parser/syntax-node/expression/index.ts | 2 +- 6 files changed, 123 insertions(+), 3 deletions(-) diff --git a/src/evaluator/index.test.ts b/src/evaluator/index.test.ts index 2e8e497..960b8a5 100644 --- a/src/evaluator/index.test.ts +++ b/src/evaluator/index.test.ts @@ -363,6 +363,11 @@ describe("evaluate()", () => { input: "더하기 = 함수(숫자1) { 결과 함수(숫자2) { 결과 숫자1+숫자2 } } 하나더하기 = 더하기(1) 하나더하기(4)", expected: 5, }, + { + name: "curried function call", + input: "더하기 = 함수(숫자1) { 결과 함수(숫자2) { 결과 숫자1+숫자2 } } 더하기(4)(7)", + expected: 11, + }, ]; it.each(cases)("evaluate $name", testEvaluatingPrimitive); diff --git a/src/index.test.ts b/src/index.test.ts index 26d817d..5e349c4 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -64,3 +64,15 @@ it("execute builtin function 쓰기()", () => { expect(stdouts).toEqual(["사과", "포도 바나나"]); }); + +it("execute function", () => { + expect(execute("사과 = 함수(포도) { 결과 포도+1 } 사과(42)")).toBe("43"); +}); + +it("execute closure", () => { + expect(execute("사과 = 함수(포도) { 결과 함수(바나나) { 결과 포도 + 바나나 } } 수박 = 사과(42) 수박(99)")).toBe("141"); +}); + +it("execute curried function", () => { + expect(execute("사과 = 함수(포도) { 결과 함수(바나나) { 결과 포도 + 바나나 } } 사과(42)(99)")).toBe("141"); +}); diff --git a/src/lexer/index.test.ts b/src/lexer/index.test.ts index a069362..0b46dcd 100644 --- a/src/lexer/index.test.ts +++ b/src/lexer/index.test.ts @@ -547,6 +547,75 @@ describe("getSourceToken()", () => { }, ] }, + { + input: "사과(1)(2)", + expectedTokens: [ + { + type: "identifier", + value: "사과", + range: { + begin: { row: 0, col: 0 }, + end: { row: 0, col: 1 }, + }, + }, + { + type: "group delimiter", + value: "(", + range: { + begin: { row: 0, col: 2 }, + end: { row: 0, col: 2 }, + }, + }, + { + type: "number literal", + value: "1", + range: { + begin: { row: 0, col: 3 }, + end: { row: 0, col: 3 }, + }, + }, + { + type: "group delimiter", + value: ")", + range: { + begin: { row: 0, col: 4 }, + end: { row: 0, col: 4 }, + }, + }, + { + type: "group delimiter", + value: "(", + range: { + begin: { row: 0, col: 5 }, + end: { row: 0, col: 5 }, + }, + }, + { + type: "number literal", + value: "2", + range: { + begin: { row: 0, col: 6 }, + end: { row: 0, col: 6 }, + }, + }, + { + type: "group delimiter", + value: ")", + range: { + begin: { row: 0, col: 7 }, + end: { row: 0, col: 7 }, + }, + }, + { + type: "end", + value: "$end", + range: { + begin: { row: 0, col: 8 }, + end: { row: 0, col: 8 }, + }, + }, + ] + }, ]; it.each(cases)("get tokens from input '$input'", ({ input, expectedTokens }) => { diff --git a/src/parser/index.test.ts b/src/parser/index.test.ts index e8a788c..26eddc1 100644 --- a/src/parser/index.test.ts +++ b/src/parser/index.test.ts @@ -596,6 +596,40 @@ describe("parseSource()", () => { ], }, }, + { + name: "call curried function", + input: "사과(1)(2)", + expected: { + type: "program", + statements: [ + { + type: "expression statement", + expression: { + type: "call", + func: { + type: "call", + func: { + type: "identifier", + value: "사과", + }, + args: [ + { + type: "number", + value: 1, + }, + ], + }, + args: [ + { + type: "number", + value: 2, + }, + ], + }, + }, + ], + }, + }, ]; it.each(cases)("$name", testSuccess); diff --git a/src/parser/index.ts b/src/parser/index.ts index ab4a025..3e64382 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -184,7 +184,7 @@ export default class Parser { const { type, value } = this.reader.read(); if (type === "group delimiter" && value === "(") { - if (left.type !== "function" && left.type !== "identifier") { + if (left.type !== "function" && left.type !== "identifier" && left.type !== "call") { return null; } @@ -202,7 +202,7 @@ export default class Parser { return null; } - private parseCall(left: Node.FunctionNode | Node.IdentifierNode): Node.CallNode { + private parseCall(left: Node.FunctionNode | Node.IdentifierNode | Node.CallNode): Node.CallNode { this.advanceOrThrow("group delimiter", "(", BadGroupDelimiterError); const secondToken = this.reader.read(); diff --git a/src/parser/syntax-node/expression/index.ts b/src/parser/syntax-node/expression/index.ts index 9bfb3d9..94e7eda 100644 --- a/src/parser/syntax-node/expression/index.ts +++ b/src/parser/syntax-node/expression/index.ts @@ -41,7 +41,7 @@ export interface FunctionNode extends SyntaxNodeBase<"function"> { body: BlockNode, }; export interface CallNode extends SyntaxNodeBase<"call"> { - func: IdentifierNode | FunctionNode, + func: IdentifierNode | FunctionNode | CallNode, args: ExpressionNode[], }; export interface AssignmentNode extends SyntaxNodeBase<"assignment"> { From 78713ed7bd591f7d0421cd2d647643d03f8a4812 Mon Sep 17 00:00:00 2001 From: Won-hee Cho <89635107+wcho21@users.noreply.github.com> Date: Sun, 11 Feb 2024 17:11:13 +0900 Subject: [PATCH 2/3] document currying (#64) --- README.md | 10 ++++++---- docs/README.ko.md | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7612a8b..4ca535f 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ _KALANG: Korean Programming Language_. - < 0.03 MB. -- Tested with >250 cases -- Written in JavaScript, natively runs on web browsers. +- Tested with >250 cases. +- JavaScript-implemented, which runs natively on web browsers. - Minimal syntax with Korean keywords. Try _KALANG_ at [Playground][playground]. @@ -81,7 +81,7 @@ Defining and calling function: ``` which yields `52`. -Closure: +Closure and currying: ``` 더하기 = 함수(숫자1) { 결과 함수(숫자2) { @@ -92,8 +92,10 @@ Closure: 하나더하기 = 더하기(1) 하나더하기(42) + +더하기(1)(42) ``` -which yields `43`. +which yields `43` twice. diff --git a/docs/README.ko.md b/docs/README.ko.md index 76a83d8..a3d486f 100644 --- a/docs/README.ko.md +++ b/docs/README.ko.md @@ -83,7 +83,7 @@ kal.execute("쓰기('사과')", stdout => stdouts.push(stdout)); // stdout === [ ``` 결과는 `52`입니다. -클로저: +클로저 및 커링: ``` 더하기 = 함수(숫자1) { 결과 함수(숫자2) { @@ -94,8 +94,10 @@ kal.execute("쓰기('사과')", stdout => stdouts.push(stdout)); // stdout === [ 하나더하기 = 더하기(1) 하나더하기(42) + +더하기(1)(42) ``` -결과는 `42`입니다. +결과는 둘 다 `42`입니다. From 989efdc60449b4cb49df82783e24205fc65d583a Mon Sep 17 00:00:00 2001 From: Won-hee Cho <89635107+wcho21@users.noreply.github.com> Date: Sun, 11 Feb 2024 17:13:40 +0900 Subject: [PATCH 3/3] build (#65) --- dist/index.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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