require "CalcFileLexer"
require "CalcStringLexer"
require "CalcParser"

## reuse the same parser object
p = CalcParser.new
p.yydebug = false
p.yyerror = $stdout

print "Parsing file:\n"

l = CalcFileLexer.new("calc.in")
p.yyparse(l)
l.cleanup

print "Parsing string:\n"

l = CalcStringLexer.new(<<EOF)
4 + 4.5 - (34/(8*3+-3))
-56 + 2
3 ^ 2
EOF

p.yyparse(l)

print "Parsing another string:\n"

l.reset(<<EOF)
(84 / 2) ^ (14 * 3) / (6 * 7) ^ 41
99 - (3 - 2) ^ 4 * 57
((2*3*7) ^ 42 ^ 0 / (-1 - (-2)))
EOF

p.yyparse(l)

print "Parsing yet another string (this one has errors):\n"
p.yydebug = true
p.yyerror = $stderr

p.yyparse(CalcStringLexer.new(<<EOF))
2 + 3 * 5
-17 + 11
*37 ***42+++++++++ 0.0 2.1
( 42 * 32 + ) * (4.0) / (3.9999999) / 42
EOF
