From c3816b3c38d5b1d7afc1dd9fa879acb6c53fb2f6 Mon Sep 17 00:00:00 2001 From: masiljangajji Date: Fri, 22 Sep 2023 15:53:04 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/nhnacademy/lsj/Parser.java | 274 ++++++++++++++ .../java/org/nhnacademy/lsj/Problem1.java | 14 +- .../java/org/nhnacademy/lsj/Problem2.java | 4 +- .../java/org/nhnacademy/lsj/Problem3.java | 52 ++- .../java/org/nhnacademy/lsj/Problem6.java | 338 ++++++++++++++++++ ...6\240\353\247\210\355\203\200\353\236\200" | 32 ++ ...\355\204\2609\352\260\234\353\205\220.txt" | 1 + ...\355\204\2609\355\200\264\354\246\210.txt" | 14 +- 8 files changed, 704 insertions(+), 25 deletions(-) create mode 100644 src/main/java/org/nhnacademy/lsj/Parser.java create mode 100644 src/main/java/org/nhnacademy/lsj/Problem6.java create mode 100644 "src/main/java/org/nhnacademy/lsj/\354\230\244\355\206\240\353\247\210\355\203\200\353\236\200" diff --git a/src/main/java/org/nhnacademy/lsj/Parser.java b/src/main/java/org/nhnacademy/lsj/Parser.java new file mode 100644 index 0000000..30b6cf7 --- /dev/null +++ b/src/main/java/org/nhnacademy/lsj/Parser.java @@ -0,0 +1,274 @@ +package org.nhnacademy.lsj; + +import textio.TextIO; + +/** + This program reads standard expressions typed in by the user. + The program constructs an expression tree to represent the + expression. It then prints the value of the tree. It also uses + the tree to print out a list of commands that could be used + on a stack machine to evaluate the expression. + The expressions can use positive real numbers and + the binary operators +, -, *, and /. The unary minus operation + is supported. The expressions are defined by the BNF rules: + + ::= [ "-" ] [ [ "+" | "-" ] ]... + + ::= [ [ "*" | "/" ] ]... + + ::= | "(" ")" + + A number must begin with a digit (i.e., not a decimal point). + A line of input must contain exactly one such expression. If extra + data is found on a line after an expression has been read, it is + considered an error. + + In addition to the main program class, SimpleParser3, this program + defines a set of four nested classes for implementing expression trees. + + */ + +public class Parser { + + // -------------------- Nested classes for Expression Trees ------------------------------ + + + /** + * An abstract class representing any node in an expression tree. + * The three concrete node classes are concrete subclasses. + * Two instance methods are specified, so that they can be used with + * any ExpNode. The value() method returns the value of the + * expression. The printStackCommands() method prints a list + * of commands that could be used to evaluate the expression on + * a stack machine (assuming that the value of the expression is + * to be left on the stack). + */ + abstract private static class ExpNode { + abstract double value(); + abstract void printStackCommands(); + } + + /** + * Represents an expression node that holds a number. + */ + private static class ConstNode extends ExpNode { + double number; // The number. + ConstNode(double val) { + // Construct a ConstNode containing the specified number. + number = val; + } + double value() { + // The value of the node is the number that it contains. + return number; + } + void printStackCommands() { + // On a stack machine, just push the number onto the stack. + System.out.println(" Push " + number); + } + } + + + /** + * An expression node representing a binary operator. + */ + private static class BinOpNode extends ExpNode { + char op; // The operator. + ExpNode left; // The expression for its left operand. + ExpNode right; // The expression for its right operand. + BinOpNode(char op, ExpNode left, ExpNode right) { + // Construct a BinOpNode containing the specified data. + assert op == '+' || op == '-' || op == '*' || op == '/'; + assert left != null && right != null; + this.op = op; + this.left = left; + this.right = right; + } + double value() { + // The value is obtained by evaluating the left and right + // operands and combining the values with the operator. + double x = left.value(); + double y = right.value(); + switch (op) { + case '+': return x + y; + case '-': return x - y; + case '*': return x * y; + case '/': return x / y; + default: return Double.NaN; // Bad operator! + } + } + void printStackCommands() { + // To evaluate the expression on a stack machine, first do + // whatever is necessary to evaluate the left operand, leaving + // the answer on the stack. Then do the same thing for the + // second operand. Then apply the operator (which means popping + // the operands, applying the operator, and pushing the result). + left.printStackCommands(); + right.printStackCommands(); + System.out.println(" Operator " + op); + } + } + + + /** + * An expression node to represent a unary minus operator. + */ + private static class UnaryMinusNode extends ExpNode { + ExpNode operand; // The operand to which the unary minus applies. + UnaryMinusNode(ExpNode operand) { + // Construct a UnaryMinusNode with the specified operand. + assert operand != null; + this.operand = operand; + } + double value() { + // The value is the negative of the value of the operand. + double neg = operand.value(); + return -neg; + } + void printStackCommands() { + // To evaluate this expression on a stack machine, first do + // whatever is necessary to evaluate the operand, leaving the + // operand on the stack. Then apply the unary minus (which means + // popping the operand, negating it, and pushing the result). + operand.printStackCommands(); + System.out.println(" Unary minus"); + } + } + + + // ------------------------------------------------------------------------------- + + + /** + * An object of type ParseError represents a syntax error found in + * the user's input. + */ + private static class ParseError extends Exception { + ParseError(String message) { + super(message); + } + } // end nested class ParseError + + + public static void main(String[] args) { + + while (true) { + System.out.println("\n\nEnter an expression, or press return to end."); + System.out.print("\n? "); + TextIO.skipBlanks(); + if ( TextIO.peek() == '\n' ) + break; + try { + ExpNode exp = expressionTree(); + TextIO.skipBlanks(); + if ( TextIO.peek() != '\n' ) + throw new ParseError("Extra data after end of expression."); + TextIO.getln(); + System.out.println("\nValue is " + exp.value()); + System.out.println("\nOrder of postfix evaluation is:\n"); + exp.printStackCommands(); + } + catch (ParseError e) { + System.out.println("\n*** Error in input: " + e.getMessage()); + System.out.println("*** Discarding input: " + TextIO.getln()); + } + } + + System.out.println("\n\nDone."); + + } // end main() + + + /** + * Reads an expression from the current line of input and builds + * an expression tree that represents the expression. + * @return an ExpNode which is a pointer to the root node of the + * expression tree + * @throws ParseError if a syntax error is found in the input + */ + private static ExpNode expressionTree() throws ParseError { + TextIO.skipBlanks(); + boolean negative; // True if there is a leading minus sign. + negative = false; + if (TextIO.peek() == '-') { + TextIO.getAnyChar(); + negative = true; + } + ExpNode exp; // The expression tree for the expression. + exp = termTree(); // Start with the first term. + if (negative) + exp = new UnaryMinusNode(exp); + TextIO.skipBlanks(); + while ( TextIO.peek() == '+' || TextIO.peek() == '-' ) { + // Read the next term and combine it with the + // previous terms into a bigger expression tree. + char op = TextIO.getAnyChar(); + ExpNode nextTerm = termTree(); + exp = new BinOpNode(op, exp, nextTerm); + TextIO.skipBlanks(); + } + return exp; + } // end expressionTree() + + + /** + * Reads a term from the current line of input and builds + * an expression tree that represents the expression. + * @return an ExpNode which is a pointer to the root node of the + * expression tree + * @throws ParseError if a syntax error is found in the input + */ + private static ExpNode termTree() throws ParseError { + TextIO.skipBlanks(); + ExpNode term; // The expression tree representing the term. + term = factorTree(); + TextIO.skipBlanks(); + while ( TextIO.peek() == '*' || TextIO.peek() == '/' ) { + // Read the next factor, and combine it with the + // previous factors into a bigger expression tree. + char op = TextIO.getAnyChar(); + ExpNode nextFactor = factorTree(); + term = new BinOpNode(op,term,nextFactor); + TextIO.skipBlanks(); + } + return term; + } // end termValue() + + + /** + * Reads a factor from the current line of input and builds + * an expression tree that represents the expression. + * @return an ExpNode which is a pointer to the root node of the + * expression tree + * @throws ParseError if a syntax error is found in the input + */ + private static ExpNode factorTree() throws ParseError { + TextIO.skipBlanks(); + char ch = TextIO.peek(); + if ( Character.isDigit(ch) ) { + // The factor is a number. Return a ConstNode. + double num = TextIO.getDouble(); + return new ConstNode(num); + } + else if ( ch == '(' ) { + // The factor is an expression in parentheses. + // Return a tree representing that expression. + TextIO.getAnyChar(); // Read the "(" + ExpNode exp = expressionTree(); + TextIO.skipBlanks(); + if ( TextIO.peek() != ')' ) + throw new ParseError("Missing right parenthesis."); + TextIO.getAnyChar(); // Read the ")" + return exp; + } + else if ( ch == '\n' ) + throw new ParseError("End-of-line encountered in the middle of an expression."); + else if ( ch == ')' ) + throw new ParseError("Extra right parenthesis."); + else if ( ch == '+' || ch == '-' || ch == '*' || ch == '/' ) + throw new ParseError("Misplaced operator."); + else + throw new ParseError("Unexpected character \"" + ch + "\" encountered."); + } // end factorTree() + + +} // end class SimpleParser3 \ No newline at end of file diff --git a/src/main/java/org/nhnacademy/lsj/Problem1.java b/src/main/java/org/nhnacademy/lsj/Problem1.java index a8ec2d3..ed165c5 100644 --- a/src/main/java/org/nhnacademy/lsj/Problem1.java +++ b/src/main/java/org/nhnacademy/lsj/Problem1.java @@ -16,22 +16,24 @@ public class Problem1 { /** * 재귀로 구현한 피보나치 함수. * - * @param N 피보나치 함수 f(N). + * @param number 피보나치 함수 f(N). * @return f(N)의 리턴값. */ - public static BigInteger fibonacci(BigInteger N) { + public static BigInteger fibonacci(BigInteger number) { - if (N.equals(BigInteger.ZERO)) { + if (number.equals(BigInteger.ZERO)) { return BigInteger.ONE; - } else if (N.equals(BigInteger.ONE)) { + } else if (number.equals(BigInteger.ONE)) { return BigInteger.ONE; } - return fibonacci(N.subtract(BigInteger.ONE)) - .add(fibonacci(N.subtract(BigInteger.TWO))); + return fibonacci(number.subtract(BigInteger.ONE)) + .add(fibonacci(number.subtract(BigInteger.TWO))); } + + /** * f(1) ... f(10) 까지의 피보나치 . */ diff --git a/src/main/java/org/nhnacademy/lsj/Problem2.java b/src/main/java/org/nhnacademy/lsj/Problem2.java index 46f150f..9789c84 100644 --- a/src/main/java/org/nhnacademy/lsj/Problem2.java +++ b/src/main/java/org/nhnacademy/lsj/Problem2.java @@ -22,7 +22,6 @@ public static void problem2() { BinarySearchTree bst = null; - boolean flag = true; try (BufferedReader br = new BufferedReader(new FileReader("src/main/resources/lsj.txt"))) { @@ -35,9 +34,8 @@ public static void problem2() { String str = stk.nextToken(); - if (flag) { + if (bst == null) { bst = new BinarySearchTree(str); - flag = false; continue; } diff --git a/src/main/java/org/nhnacademy/lsj/Problem3.java b/src/main/java/org/nhnacademy/lsj/Problem3.java index 7ff5582..91cdf29 100644 --- a/src/main/java/org/nhnacademy/lsj/Problem3.java +++ b/src/main/java/org/nhnacademy/lsj/Problem3.java @@ -21,19 +21,22 @@ public class Problem3 { public static void problem3() { - ListNode listNode = new ListNode(0); + // ListNode listNode = new ListNode(0); - for (int i = 1; i <= 10; i++) { - addNode(listNode, new ListNode(i)); - } +// for (int i = 1; i <= 10; i++) { +// addNode(listNode, new ListNode(i)); +// } - printListNode(listNode); + ListNode listNode = addAllNode(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - System.out.println(listNode.getCount()); + printListNode(listNode); ListNode answer = reverseListNode(listNode); + + System.out.println("\n"); + printListNode(answer); @@ -52,7 +55,7 @@ public static ListNode reverseListNode(ListNode listNode) { int index = listNode.getCount(); - for (int i = index; i >= 0; i--) { + for (int i = index; i > 0; i--) { if (answer == null) { answer = getNodeByIndex(listNode, i); @@ -62,6 +65,7 @@ public static ListNode reverseListNode(ListNode listNode) { addNode(answer, getNodeByIndex(listNode, i)); } + return answer; } @@ -75,10 +79,13 @@ public static ListNode reverseListNode(ListNode listNode) { */ public static ListNode getNodeByIndex(ListNode listNode, int index) { - for (int i = 0; i < index; i++) { + + for (int i = 0; i < index - 1; i++) { listNode = listNode.getNext(); } + return new ListNode(listNode.getItem()); + } /** @@ -111,8 +118,37 @@ public static void printListNode(ListNode listNode) { } + + public static ListNode addAllNode(int... num) { + + ListNode head = null; + ListNode start = null; + + for (int i = 0; i < num.length; i++) { + + if (head == null) { + head = new ListNode(num[i]); + start = head; + start.addCount(); + continue; + } + + while (head.getNext() != null) { + head = head.getNext(); + } + + head.setNext(new ListNode(num[i])); + start.addCount(); + + } + return start; + + } + + } + class ListNode { private int item; diff --git a/src/main/java/org/nhnacademy/lsj/Problem6.java b/src/main/java/org/nhnacademy/lsj/Problem6.java new file mode 100644 index 0000000..bb1d0f9 --- /dev/null +++ b/src/main/java/org/nhnacademy/lsj/Problem6.java @@ -0,0 +1,338 @@ +package org.nhnacademy.lsj; + +import textio.TextIO; + +public class Problem6 { + + + public static void problem6() { + + + SimpleParser3 simpleParser3 = new SimpleParser3(); + + + } + +} + + +/** + * This program reads standard expressions typed in by the user. + * The program constructs an expression tree to represent the + * expression. It then prints the value of the tree. It also uses + * the tree to print out a list of commands that could be used + * on a stack machine to evaluate the expression. + * The expressions can use positive real numbers and + * the binary operators +, -, *, and /. The unary minus operation + * is supported. The expressions are defined by the BNF rules: + * + * ::= [ "-" ] [ [ "+" | "-" ] ]... + * + * ::= [ [ "*" | "/" ] ]... + * + * ::= | "(" ")" + *

+ * A number must begin with a digit (i.e., not a decimal point). + * A line of input must contain exactly one such expression. If extra + * data is found on a line after an expression has been read, it is + * considered an error. + *

+ * In addition to the main program class, SimpleParser3, this program + * defines a set of four nested classes for implementing expression trees. + */ + +class SimpleParser3 { + + // -------------------- Nested classes for Expression Trees ------------------------------ + + + /** + * An abstract class representing any node in an expression tree. + * The three concrete node classes are concrete subclasses. + * Two instance methods are specified, so that they can be used with + * any ExpNode. The value() method returns the value of the + * expression. The printStackCommands() method prints a list + * of commands that could be used to evaluate the expression on + * a stack machine (assuming that the value of the expression is + * to be left on the stack). + */ + abstract private static class ExpNode { + abstract double value(double xValue); + + abstract void printStackCommands(); + } + + /** + * An expression node representing a binary operator. + */ + /** + * Represents an expression node that holds a number. + */ + private static class ConstNode extends ExpNode { + double number; // The number. + + ConstNode(double val) { + // Construct a ConstNode containing the specified number. + number = val; + } + + double value(double xValue) { + // The value of the node is the number that it contains. + return number; + } + + void printStackCommands() { + // On a stack machine, just push the number onto the stack. + System.out.println(" Push " + number); + } + } + + + /** + * An expression node representing a binary operator, + */ + private static class BinOpNode extends ExpNode { + char op; // The operator. + ExpNode left; // The expression for its left operand. + ExpNode right; // The expression for its right operand. + + BinOpNode(char op, ExpNode left, ExpNode right) { + // Construct a BinOpNode containing the specified data. + assert op == '+' || op == '-' || op == '*' || op == '/'; + assert left != null && right != null; + this.op = op; + this.left = left; + this.right = right; + } + + double value(double xValue) { + // The value is obtained by evaluating the left and right + // operands and combining the values with the operator. + double x = left.value(xValue); + double y = right.value(xValue); + switch (op) { + case '+': + return x + y; + case '-': + return x - y; + case '*': + return x * y; + case '/': + return x / y; + default: + return Double.NaN; // Bad operator! + } + } + + void printStackCommands() { + // To evaluate the expression on a stack machine, first do + // whatever is necessary to evaluate the left operand, leaving + // the answer on the stack. Then do the same thing for the + // second operand. Then apply the operator (which means popping + // the operands, applying the operator, and pushing the result). + left.printStackCommands(); + right.printStackCommands(); + System.out.println(" Operator " + op); + } + } + + + /** + * An expression node to represent a unary minus operator. + */ + private static class UnaryMinusNode extends ExpNode { + ExpNode operand; // The operand to which the unary minus applies. + + UnaryMinusNode(ExpNode operand) { + // Construct a UnaryMinusNode with the specified operand. + assert operand != null; + this.operand = operand; + } + + double value(double xValue) { + // The value is the negative of the value of the operand. + double neg = operand.value(xValue); + return -neg; + } + + void printStackCommands() { + // To evaluate this expression on a stack machine, first do + // whatever is necessary to evaluate the operand, leaving the + // operand on the stack. Then apply the unary minus (which means + // popping the operand, negating it, and pushing the result). + operand.printStackCommands(); + System.out.println(" Unary minus"); + } + } + + + /** + * An expression node that represents a reference to the variable, x. + */ + private static class VariableNode extends ExpNode { + VariableNode() { + // Construct a VariableNode. (There is nothing to do!) + } + + double value(double xValue) { + // The value of the node is the value of x. + return xValue; + } + + void printStackCommands() { + // On a stack machine, just push the value of X onto the stack. + System.out.println(" Push X"); + } + } + + +// ------------------------------------------------------------------------------- + + + /** + * An object of type ParseError represents a syntax error found in + * the user's input. + */ + private static class ParseError extends Exception { + ParseError(String message) { + super(message); + } + } // end nested class ParseError + + + public static void main(String[] args) { + + while (true) { + System.out.println("\n\nEnter an expression, or press return to end."); + System.out.print("\n? "); + TextIO.skipBlanks(); + if (TextIO.peek() == '\n') { + break; + } + try { + ExpNode exp = expressionTree(); + TextIO.skipBlanks(); + if (TextIO.peek() != '\n') { + throw new ParseError("Extra data after end of expression."); + } + TextIO.getln(); + System.out.println("\nValue at x = 0 is " + exp.value(0)); + System.out.println("Value at x = 1 is " + exp.value(1)); + System.out.println("Value at x = 2 is " + exp.value(2)); + System.out.println("Value at x = 3 is " + exp.value(3)); + System.out.println("\nOrder of postfix evaluation is:\n"); + exp.printStackCommands(); + } catch (ParseError e) { + System.out.println("\n*** Error in input: " + e.getMessage()); + System.out.println("*** Discarding input: " + TextIO.getln()); + } + } + + System.out.println("\n\nDone."); + + } // end main() + + + /** + * Reads an expression from the current line of input and builds + * an expression tree that represents the expression. + * + * @return an ExpNode which is a pointer to the root node of the + * expression tree + * @throws ParseError if a syntax error is found in the input + */ + private static ExpNode expressionTree() throws ParseError { + TextIO.skipBlanks(); + boolean negative; // True if there is a leading minus sign. + negative = false; + if (TextIO.peek() == '-') { + TextIO.getAnyChar(); + negative = true; + } + ExpNode exp; // The expression tree for the expression. + exp = termTree(); // Start with the first term. + if (negative) { + exp = new UnaryMinusNode(exp); + } + TextIO.skipBlanks(); + while (TextIO.peek() == '+' || TextIO.peek() == '-') { + // Read the next term and combine it with the + // previous terms into a bigger expression tree. + char op = TextIO.getAnyChar(); + ExpNode nextTerm = termTree(); + exp = new BinOpNode(op, exp, nextTerm); + TextIO.skipBlanks(); + } + return exp; + } // end expressionTree() + + + /** + * Reads a term from the current line of input and builds + * an expression tree that represents the expression. + * + * @return an ExpNode which is a pointer to the root node of the + * expression tree + * @throws ParseError if a syntax error is found in the input + */ + private static ExpNode termTree() throws ParseError { + TextIO.skipBlanks(); + ExpNode term; // The expression tree representing the term. + term = factorTree(); + TextIO.skipBlanks(); + while (TextIO.peek() == '*' || TextIO.peek() == '/') { + // Read the next factor, and combine it with the + // previous factors into a bigger expression tree. + char op = TextIO.getAnyChar(); + ExpNode nextFactor = factorTree(); + term = new BinOpNode(op, term, nextFactor); + TextIO.skipBlanks(); + } + return term; + } // end termValue() + + + /** + * Reads a factor from the current line of input and builds + * an expression tree that represents the expression. + * + * @return an ExpNode which is a pointer to the root node of the + * expression tree + * @throws ParseError if a syntax error is found in the input + */ + + private static ExpNode factorTree() throws ParseError { + TextIO.skipBlanks(); + char ch = TextIO.peek(); + if (Character.isDigit(ch)) { + // The factor is a number. Return a ConstNode. + double num = TextIO.getDouble(); + return new ConstNode(num); + } else if (ch == 'x' || ch == 'X') { + // The factor is the variable x. + TextIO.getAnyChar(); // Read the X. + return new VariableNode(); + } else if (ch == '(') { + // The factor is an expression in parentheses. + // Return a tree representing that expression. + TextIO.getAnyChar(); // Read the "(" + ExpNode exp = expressionTree(); + TextIO.skipBlanks(); + if (TextIO.peek() != ')') { + throw new ParseError("Missing right parenthesis."); + } + TextIO.getAnyChar(); // Read the ")" + return exp; + } else if (ch == '\n') { + throw new ParseError("End-of-line encountered in the middle of an expression."); + } else if (ch == ')') { + throw new ParseError("Extra right parenthesis."); + } else if (ch == '+' || ch == '-' || ch == '*' || ch == '/') { + throw new ParseError("Misplaced operator."); + } else { + throw new ParseError("Unexpected character \"" + ch + "\" encountered."); + } + } // end factorTree() + + +} // end class SimpleParser4 \ No newline at end of file diff --git "a/src/main/java/org/nhnacademy/lsj/\354\230\244\355\206\240\353\247\210\355\203\200\353\236\200" "b/src/main/java/org/nhnacademy/lsj/\354\230\244\355\206\240\353\247\210\355\203\200\353\236\200" new file mode 100644 index 0000000..2dba84d --- /dev/null +++ "b/src/main/java/org/nhnacademy/lsj/\354\230\244\355\206\240\353\247\210\355\203\200\353\236\200" @@ -0,0 +1,32 @@ + + +형식언어 = 특정한 법칙들에 따라 적절하게 구성된 문자열들의 집합 + +알파벳을 살펴보자 + +알파벳이란 a-z까지의 문자임 + +문자 하나하나를 의미해 + +그럼 문자열은?? + +알파벳에서 정의된 기호들을 나열한 유한 수열 (finite sequence)임 + +a , ca , ccba ,dddd 등이 문자열에 속함 + + +만약 다음과 같은 집합이 있다고 하자 + +Σ = (a,b,c) + +이 집합에서 만들어질 수 있는 문자열은 다음과 같다 + +Σ = { a,b,aa,ab,ba,bb,aaa,bbb,c,cc,....}는 무한언어 + +이 집합에 대해 만들어질 수 있는 모든 문자열들의 집합을 Σ = Closure 라고 한다. + + + + + + diff --git "a/src/main/java/org/nhnacademy/lsj/\354\261\225\355\204\2609\352\260\234\353\205\220.txt" "b/src/main/java/org/nhnacademy/lsj/\354\261\225\355\204\2609\352\260\234\353\205\220.txt" index b6da122..7db4854 100644 --- "a/src/main/java/org/nhnacademy/lsj/\354\261\225\355\204\2609\352\260\234\353\205\220.txt" +++ "b/src/main/java/org/nhnacademy/lsj/\354\261\225\355\204\2609\352\260\234\353\205\220.txt" @@ -348,5 +348,6 @@ while - loop can be while(조건문) <실행문> + diff --git "a/src/main/java/org/nhnacademy/lsj/\354\261\225\355\204\2609\355\200\264\354\246\210.txt" "b/src/main/java/org/nhnacademy/lsj/\354\261\225\355\204\2609\355\200\264\354\246\210.txt" index 84b56e6..2fd8e57 100644 --- "a/src/main/java/org/nhnacademy/lsj/\354\261\225\355\204\2609\355\200\264\354\246\210.txt" +++ "b/src/main/java/org/nhnacademy/lsj/\354\261\225\355\204\2609\355\200\264\354\246\210.txt" @@ -237,7 +237,10 @@ that is produced by a post-order traversal of the tree. 2 4 3 1 6 7 5 - + 5 + 1 7 + 3 6 + 2 4 Question 13: @@ -251,7 +254,7 @@ is almost the entire syntax of the programming language LISP! LISP is known for its simple syntax and its elegant and powerful semantics.) - +tree , stack , heap , node , next Question 14: @@ -268,16 +271,11 @@ Parse tree를 만드는 과정 Ex) 프로그램을 컴파일하는 과정에서 특정 프로그래밍 언어가 제시하는 문법을 잘 지켜서 작성했는지 검사하는 것 -인터넷에 주어진 정보를 내가 원하는대로 가공하여 서버에서 원하는 때 불러올 수 있도록 하는 것 - +이 Parse tree를 만드는데 BNF같은 문법규칙을 사용한다. -컴퓨팅에서 parse는 interpreter나 compiler의 구성 요소 중 하나 -parser = token을 검사하는 것 -Parsing을 하는 주체가 parser야 , 얘가 parsing을 하는 것 -후에 오타마타 이론에 대해서 더 공부하고 생각해보기 .