Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. enum class factortype { num ,           // FACTYPE: indicate if the factor is numerical
  2.                         litteral };     //          or is unknown ( symbolical )
  3.  
  4. struct factor                           // FACTOR: rappresentation of an object that is part of a monomial expression
  5. {                                       //         a monomial expression like ⅔x will be rappresented as:
  6.     std::variant                        //         [ num = 2 ; power = 1 ] [ num = 3 ; power = -1 ] [ letter = x ; power = 1 ]
  7.     <                                   //
  8.         std::string,                    //
  9.         double                          //
  10.     >                                   //
  11.     value;                              //
  12.     factortype type;                    //
  13.     double power;                       //
  14. };                                      //
  15.  
  16. struct monom                            // MONOM:   rappresentation of an object that is an entire monomial expression
  17. {                                       //          contains a vector of numeral factors and a vector of litteral factors
  18.     std::vector<factor> numeral;        //          sign is just stored as boolean
  19.     std::vector<factor> litteral;       //
  20.     bool sign;                          //
  21. };                                      //
  22.  
  23. enum class tokentype {      monomial ,  // TYPES:   monomial expression
  24.                             operation , //          an operator ( such as * - + / ^ ! )
  25.                             section ,   //          a section delimitated by "(" and ")"
  26.                             oparen ,    //          an opened parentesis
  27.                             cparen ,    //          a closed parentesis
  28.                             obraket ,   //          an opened braket for delimiting multichar name for variables
  29.                             cbraket ,   //          a closed braket for delimiting multichar name for variables
  30.                             function ,  //          a function name and the start of the arguments token
  31.                             comma,      //          the comma separeting function arguments
  32.                             endarg  };  //          the end of the argument token list
  33.  
  34. enum class operation {      sum,        // OP:      sum between two real numbers with a positive or negative sign and maybe unknow
  35.                             minus,      //          change sign of the following token
  36.                             mul,        //          moltiplication of two tokens
  37.                             div,        //          division of two tokens
  38.                             pow,        //          power of a token
  39.                             fact,       //          factorial of a token
  40.                             modul    }; //          rest of an integer division
  41.  
  42.  
  43. struct token                            // TOKEN:   rappresentation of a self semantic unit of an expression, just as
  44. {                                       //          '2x' or '+' or whatelse
  45.     std::variant                        //          sequence of tokens can be evaluated to get a result
  46.     <                                   //
  47.         monom,                          //
  48.         operation,                      //
  49.         std::vector<token>,             //
  50.         std::string                     //
  51.     >                                   //
  52.     data;                               //
  53.     tokentype type;                     //
  54. };                                      //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement