/* * Copyright (c) 2008 Andrew Garrett. * Copyright (c) 2008 River Tarnell * Derived from public domain code contributed by Victor Vasiliev. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely. This software is provided 'as-is', without any express or * implied warranty. */ #include #include "parser.h" #include "afstring.h" template afp::basic_datum f_add(std::vector > const &args) { return args[0] + args[1]; } template afp::basic_datum f_norm(std::vector > const &args) { return args[0]; } template afp::basic_datum f_length(std::vector > const &args) { return afp::basic_datum::from_int(args[0].toString().size()); } int main(int argc, char **argv) { if (argc != 2) { std::cerr << boost::format("usage: %s \n") % argv[0]; return 1; } afp::expressor e; e.add_variable(make_u32fray("ONE"), afp::u32datum::from_int(1)); e.add_variable(make_u32fray("TWO"), afp::u32datum::from_int(2)); e.add_variable(make_u32fray("THREE"), afp::u32datum::from_int(3)); e.add_function(make_u32fray("add"), f_add); e.add_function(make_u32fray("norm"), f_norm); e.add_function(make_u32fray("length"), f_length); try { e.print_xml(std::cout, make_u32fray(argv[1])); } catch (std::exception &e) { std::cout << "parsing failed: " << e.what() << '\n'; } }