OSDN Git Service

Initial Commit
[qcad/qcad.git] / compiler / QCompiler.h
1 //----------------------------------------------------------------------------\r
2 //  QCompiler.h\r
3 //  Compile intermediate codes\r
4 //  $Date: 2003/01/17 19:37:43 $\r
5 //  $Revision: 1.3 $\r
6 //----------------------------------------------------------------------------\r
7 #ifndef QCOMPILER_H\r
8 #define QCOMPILER_H\r
9 \r
10 #include <iostream>\r
11 #include <string>\r
12 #include <vector>\r
13 #include "QParseInfo.h"\r
14 \r
15 class QCompiler {\r
16 \r
17 public:\r
18   QCompiler(void);\r
19   QCompiler(std::istream &is);\r
20   virtual ~QCompiler();\r
21   bool Compile(void);\r
22   void ReadFromStream(std::istream &is);\r
23   bool HasError(void) {\r
24     return mError;\r
25   }\r
26   bool GetState(void) {\r
27     return mState;\r
28   }\r
29 \r
30   typedef enum _opnumber {\r
31     opn_arg_max = 3,\r
32     opn_length  = 10\r
33   } OpNumber;\r
34 \r
35   static const int opn_max;\r
36 \r
37 protected:\r
38   virtual bool CompileOneLine(const QParseInfo &pinfo) = 0;\r
39   virtual void CatchError(const QParseInfo &pinfo, const int at) = 0;\r
40 \r
41   QParseInfo  ParseOneLine(const std::string &strline) const;\r
42   bool        ExtractComArg(const std::string &strline, const char bra, const char ket,\r
43                             std::string &Com, std::string &Arg) const;\r
44   bool        ExtractField(const std::string &strline, const char delim,\r
45                            std::vector<std::string> &Args) const ;\r
46   int         GetComint(const std::string &_str) const;\r
47 \r
48   // Member valuables\r
49   std::vector<std::string>    mLines;\r
50   bool                        mError;\r
51   bool                        mState; // true == finished\r
52 \r
53   //------------------------------------------------------------------------\r
54   //  Syntax of intermediate code  (see also `QCompiler.cpp')\r
55   //------------------------------------------------------------------------\r
56   // Argument types\r
57   typedef enum _argtype {\r
58     at_null = 0,\r
59     at_qbit = 1,\r
60     at_real = 2,\r
61     at_oprt = 3\r
62   } ArgType;\r
63 \r
64   // Command numbers, each of which corresponds to the index num of OPSTR\r
65 \r
66   typedef enum _commandnumber {\r
67     cn_cnot     = 0,\r
68     cn_rot ,\r
69     cn_crot ,\r
70     cn_h    ,\r
71     cn_m    ,\r
72     cn_swap ,\r
73     cn_x    ,\r
74     cn_y    ,\r
75     cn_z    ,\r
76     cn_not  ,\r
77     cn_ccnot,\r
78     cn_init\r
79   } CommandNumber;\r
80 \r
81   // Size of array\r
82 \r
83 \r
84 \r
85   struct QGATES {\r
86     char opstr[opn_length];\r
87     int arg_num;\r
88     int arg_types[opn_arg_max];\r
89   };\r
90 \r
91   static const QGATES qgates[];\r
92 \r
93   static const char   OP_BRA;\r
94   static const char   OP_KET;\r
95   static const char   QB_BRA;\r
96   static const char   QB_KET;\r
97   static const char   DELIM;\r
98 };\r
99 \r
100 #endif //QCOMPILER_H\r