[brlcad-commits] SF.net SVN: brlcad:[33951] brlcad/trunk/src/libpc/pcMathGrammar.h
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <hom...@us...> - 2009-03-06 06:26:42
|
Revision: 33951 http://brlcad.svn.sourceforge.net/brlcad/?rev=33951&view=rev Author: homovulgaris Date: 2009-03-06 06:26:34 +0000 (Fri, 06 Mar 2009) Log Message: ----------- adding various operators to the expression grammar Modified Paths: -------------- brlcad/trunk/src/libpc/pcMathGrammar.h Modified: brlcad/trunk/src/libpc/pcMathGrammar.h =================================================================== --- brlcad/trunk/src/libpc/pcMathGrammar.h 2009-03-05 23:45:24 UTC (rev 33950) +++ brlcad/trunk/src/libpc/pcMathGrammar.h 2009-03-06 06:26:34 UTC (rev 33951) @@ -82,9 +82,20 @@ }; boost::spirit::symbols<char> NameGrammar::reserved_keywords; + +/** Finding the math function using the name */ + +boost::shared_ptr<MathFunction> checked_find + (boost::spirit::symbols<boost::shared_ptr<MathFunction> > const & symbols, + std::string const & name) +{ + boost::shared_ptr<MathFunction> * ptr; + return *ptr; +} + /** Different types of closures */ -struct FuncExprClosure : boost spirit::closure<FuncExprClosure, Stack, std::string, int, boost::shared_ptr<MathFunction> +struct FuncExprClosure : boost spirit::closure<FuncExprClosure, Stack, std::string, int, boost::shared_ptr<MathFunction> > { member1 stack; member2 name; @@ -112,7 +123,8 @@ */ struct ExpressionGrammar : public boost::spirit::classic::grammar<ExpressionGrammar,StackClosure::context_t> { - typedef boost::spirit::symbols<boost::shared_ptr<MathFunction> > FunctionTable; + typedef boost::shared_ptr<MathFunction> FunctionPointer; + typedef boost::spirit::symbols<FunctionPointer> FunctionTable; typedef boost::spirit::symbols<double> VarTable; VarTable const dummy_local_vars; @@ -134,6 +146,35 @@ definition(ExpressionGrammar const & self) : name(false) { + boolean_op.add + ("&&", false) + ("||", true); + add_op.add + ("+", checked_find(self.functions,"add")) + ("-", checked_find(self.functions, "subtract")); + bitwise_op.add + ("&", checked_find(self.functions,"bitwise_and")) + ("|", checked_find(self.functions,"bitwise_or")) + ("^", checked_find(self.functions,"bitwise_xor")); + compare_op.add + ("<", checked_find(self.functions,"less")) + (">", checked_find(self.functions,"greater")) + ("<=", checked_find(self.functions,"leq")) + (">=", checked_find(self.functions,"geq")); + equality_op.add + ("==", checked_find(self.functions,"equal")) + ("+", checked_find(self.functions,"notequal")); + mult_op.add + ("*", checked_find(self.functions,"multiply")) + ("/", checked_find(self.functions,"divide")) + ("%", checked_find(self.functions,"mod")); + shift_op.add + ("<<", checked_find(self.functions,"lshift")) + (">>", checked_find(self.functions,"rshift")); + unary_op.add + ("+", FunctionPointer() ) + ("-", checked_find(self.functions,"negate")) + ("!", checked_find(self.functions,"logical_not")); } typedef RuleT boost::spirit::classic::rule<ScannerT>; @@ -141,6 +182,9 @@ private: RuleT arg, top; NameGrammar name; + boost::spirit::symbols<bool> boolean_op; + FunctionTable and_op, add_op, bitwise_op, compare_op, equality_op,\ + shift_op, mult_op,unary_op; }; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |