Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
color: #333333;
display: block;
padding: 8.5px;
margin: 0 0 9px;
font-size: 12px;
line-height: 18px;
background-color: #f5f5f5;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}

Problem Statement

One day, you found an old scroll with strange texts on it.

You revealed that the text was actually an expression denoting the position of
treasure. The expression consists of following three operations:

From two points, yield a line on which the points lie.

From a point and a line, yield a point that is symmetric to the given point with respect to the line.

From two lines, yield a point that is the intersection of the lines.

The syntax of the expression is denoted by following BNF:

<expression> ::= <point>
<point> ::= <point-factor> | <line> "@" <line-factor> | <line> "@" <point-factor> | <point> "@" <line-factor>
<point-factor> ::= "(" <number> "," <number> ")" | "(" <point> ")"
<line> ::= <line-factor> | <point> "@" <point-factor>
<line-factor> ::= "(" <line> ")"
<number> ::= <zero-digit> | <positive-number> | <negative-number>
<positive-number> ::= <nonzero-digit> | <positive-number> <digit>
<negative-number> ::= "-" <positive-number>
<digit> ::= <zero-digit> | <nonzero-digit>
<zero-digit> ::= "0"
<nonzero-digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

Each <point> or <point-factor> denotes a point, whereas each <line> or <line-factor> denotes a line. The former notion of <point-factor> $(X,Y)$ represents a point which has $X$ for $x$-coordinate and $Y$ for $y$-coordinate on the $2$-dimensional plane.
"@" indicates the operations on two operands. Since each operation is distinguishable from others by its operands' types (i.e. a point or a line),
all of these operations are denoted by the same character "@".
Note that "@" is left-associative, as can be seen from the BNF.

Your task is to determine where the treasure is placed.

Input

The input consists of multiple datasets. Each dataset is a single line which
contains an expression denoting the position of treasure.

It is guaranteed that each dataset satisfies the following conditions:

The length of the string never exceeds $10^2$.

If both operands of "@" are points, their distance is greater than $1$.

If both operands of "@" are lines, they are never parallel.

The absolute values of points' coordinates never exceed $10^2$ at any point of evaluation.

You can also assume that there are at most $100$ datasets.

The input ends with a line that contains only a single "#".

Output

For each dataset, print the $X$ and $Y$ coordinates of the point, denoted by
the expression, in this order.

The output will be considered correct if its absolute or relative error is at most $10^{-2}$.

Sample Input

((0,0)@(1,1))@((4,1)@(2,5))
((0,0)@(3,1))@((1,-3)@(2,-1))
(0,0)@(1,1)@(4,1)
(0,0)@((1,1)@(4,1))
(((0,0)@((10,20)@(((30,40))))))
((0,0)@(3,1))@((1,-3)@(2,-1))@(100,-100)@(100,100)
#

Output for the Sample Input

3.00000000 3.00000000
3.00000000 1.00000000
1.00000000 4.00000000
0.00000000 2.00000000
-10.00000000 10.00000000
-99.83681795 -91.92248853

Solution in Scala (judge verdict: Accepted)

import scala.annotation.tailrec

object Main extends App {
  import scala.io.StdIn._

  solve
  def solve: Unit = {
    val expression = readLine.trim
    if (expression == "#") return
    expression.toList match {
      case (p: Point) Expression Nil ⇒ println(s"${p.x} ${p.y}")
      case _ ⇒ ???
    }
    solve
  }

  object Expression {
    def unapply(arg: List[Char]): Option[(Result, List[Char])] = {
      arg match {
        case f Factor rest ⇒
          Some(takeAll(rest, f))
        case _ ⇒ None
      }
    }
    @tailrec
    def takeAll(arg: List[Char], prev: Result): (Result, List[Char]) = {
      arg match {
        case '@'::(f Factor r) ⇒
          takeAll(r, op(prev, f))
        case _ ⇒
          (prev, arg)
      }
    }
    private[this] def op(a: Result, b: Result): Result = {
      (a, b) match {
        case (p1: Point, p2: Point) ⇒
          Line(p1, p2)
        case (p: Point, l: Line) ⇒
          p.flipBy(l)
        case (l: Line, p: Point) ⇒
          p.flipBy(l)
        case (l1: Line, l2: Line) ⇒
          l1.crossPoint(l2)
        case _ ⇒ ???
      }
    }
  }
  object Factor {
    def unapply(arg: List[Char]): Option[(Result, List[Char])] = {
      arg match {
        case p PointFactor r ⇒
          Some(p, r)
        case '('::(e Expression ')'::r) ⇒
          Some(e, r)
        case _ ⇒ None
      }
    }
  }
  object PointFactor {
    def unapply(arg: List[Char]): Option[(Point, List[Char])] = {
      arg match {
        case '('::(x Number ','::(y Number ')'::r)) ⇒ Some(Point(x, y), r)
        case _ ⇒ None
      }
    }
  }
  object Number {
    def unapply(arg: List[Char]): Option[(Double, List[Char])] = {
      arg match {
        case '-'::rest ⇒
          rest.span(_.isDigit) match {
            case (Nil, _) ⇒ None
            case (n, r) ⇒ Some(n.foldLeft(0){(a, b) ⇒ a * 10 - b.asDigit}, r)
          }
        case _ ⇒
          arg.span(_.isDigit) match {
            case (Nil, _) ⇒ None
            case (n, r) ⇒ Some(n.foldLeft(0){(a, b) ⇒ a * 10 + b.asDigit}, r)
          }
      }
    }
  }
  sealed trait Result
  case class Point(x: Double, y: Double) extends Result {
    def -(that: Point): Point = Point(x - that.x, y - that.y)
    def +(that: Point): Point = Point(x + that.x, y + that.y)
    def flipBy(line: Line): Point = {
      Line(this, Angle(line).rotate90Clockwise).crossPoint(line).let(p ⇒ p - this + p)
    }
  }
  object Line {
    def apply(point: Point, angle: Angle): Line = {
      //cos(y - p.y) == sin(x - p.x)
      Line(-angle.sin, angle.cos, angle.sin * point.x - angle.cos * point.y)
    }
    def apply(a: Point, b: Point): Line = {
      //(a.x - b.x)(y - b.y) == (a.y - b.y)(x - b.x)
      Line(b.y - a.y, a.x - b.x, a.y * b.x - a.x * b.y)
    }
  }
  case class Line(a: Double, b: Double, c: Double) extends Result {
    def crossPoint(that: Line): Point = {
      Point((this.b * that.c - that.b * this.c) / (this.a * that.b - that.a * this.b), (that.a * this.c - this.a * that.c) / (this.a * that.b - that.a * this.b))
    }

  }
  object Angle {
    def apply(line: Line): Angle = {
      val norm = math.sqrt(line.a * line.a + line.b * line.b)
      new Angle(-line.a / norm, line.b / norm)
    }
  }
  class Angle(val sin: Double, val cos: Double) {
    def + (that: Angle): Angle = new Angle(sin * that.cos + cos * that.sin, cos * that.cos - sin * that.sin)
    def - (that: Angle): Angle = new Angle(sin * that.cos - cos * that.sin, cos * that.cos + sin * that.sin)
    def rotate90Clockwise: Angle = new Angle(-cos, sin)
  }
  implicit class Scope[T](val value: T) extends AnyVal{
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}