// Copyright (C) 2014, Gabriel Dos Reis.1// All rights reserved.2// Written by Gabriel Dos Reis.3//4// Redistribution and use in source and binary forms, with or without5// modification, are permitted provided that the following conditions are6// met:7//8// - Redistributions of source code must retain the above copyright9// notice, this list of conditions and the following disclaimer.10//11// - Redistributions in binary form must reproduce the above copyright12// notice, this list of conditions and the following disclaimer in13// the documentation and/or other materials provided with the14// distribution.15//16// - Neither the name of OpenAxiom nor the names of its contributors17// may be used to endorse or promote products derived from this18// software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED22// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A23// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER24// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,25// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,26// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.3132// --% Author: Gabriel Dos Reis3334#include <open-axiom/Lisp>35#include <iostream>36#include <string>3738static OpenAxiom::Sexpr::RawInput39raw_input(const std::string& line, OpenAxiom::Ordinal lineno) {40if (line.empty())41return { nullptr, nullptr, lineno };42auto p = reinterpret_cast<const OpenAxiom::Byte*>(&line[0]);43return { p, p + line.size(), lineno };44}4546int main(int argc, char* argv[]) {47using namespace OpenAxiom;48Lisp::Evaluator lisp;4950const char* prompt = "*> ";51std::string line;52Ordinal lineno { };53while (true) {54std::cout << prompt;55if (!std::getline(std::cin, line))56break;57else if (line.empty())58continue;59Sexpr::Reader reader { raw_input(line, ++lineno) };60while (true) {61try {62auto s = reader.read();63if (s == nullptr)64break;65auto value = lisp.eval(s);66Lisp::format(value, std::cout);67std::cout << '\n';68}69catch (const OpenAxiom::Diagnostics::BasicError& e) {70std::cerr << e.message() << std::endl;71}72}73}7475std::cout << std::endl;76}77787980