1 #ifndef PARSER_H
2 #define PARSER_H
3 
4 #include <string>
5 
6 #include "vektor.h"
7 #include "monomial.h"
8 #include "polynomial.h"
9 #include "field.h"
10 #include "polynomialring.h"
11 
12 using namespace std;
13 
14 class Parser
15 {
16  protected:
17   void parserError(const char *expected, char c);
18  public:
19   virtual int parseInt()=0;
20   virtual Monomial parseMonomial(PolynomialRing const &r)=0;
21   virtual IntegerVector parseIntegerVector()=0;
22 };
23 
24 
25 class CharacterBasedParser : public Parser
26 {
27  private:
28   PolynomialRing azAZ(Field const &f, int n=52);
29   bool isVariable(int c);
30   bool isDigit(int c);
31   int variableIndex(int c);
32  protected:
33   virtual int getChar()=0;
34   virtual void ungetChar(int c)=0;
35  public:
36   int nextNonBlank();
37   int nextNonBlankDoNotGet();
38   bool isLeftBracket(int c);
39   bool isRightBracket(int c);
40   int parseChar();
41   int parseInt();
42   double parseFloat();
43   ComplexNumber parseComplexNumber();
44   FieldElement parseFieldElement(Field const &f);
45   FieldElement parseFieldElementFromInteger(Field const &f);
46   Monomial parseMonomial(PolynomialRing const &r);
47   IntegerVector parseIntegerVector();
48   FloatVector parseFloatVector();
49   ComplexVector parseComplexVector();
50   IntegerVectorList parseIntegerVectorList();
51   IntegerVectorList parseIntegerVectorList4ti2();
52   IntegerVectorListList parseIntegerVectorListList();
53   Term parseTerm(PolynomialRing const &r);
54   Field parseField();
55   string parseVariableName();
56   vector<string> parseVariableList();
57   PolynomialRing parsePolynomialRing();
58   Polynomial parsePolynomial(PolynomialRing const &r);
59   Polynomial parsePolynomialWithRing();
60   PolynomialSet parsePolynomialSet(PolynomialRing const &r);
61   PolynomialSet parsePolynomialSetWithRing();
62   PolynomialSetList parsePolynomialSetList(PolynomialRing const &r);
63   PolynomialSetList parsePolynomialSetListWithRing();
64 };
65 
66 
67 class FileParser : public CharacterBasedParser
68 {
69   FILE *f;
70  protected:
71   virtual int getChar();
72   virtual void ungetChar(int c);
73  public:
74   FileParser(FILE *f);
75 };
76 
77 
78 class StringParser : public CharacterBasedParser
79 {
80   const char *s;
81   int index;
82   bool hasUngotten;
83   char ungotten;
84  protected:
85   virtual int getChar();
86   virtual void ungetChar(int c);
87  public:
88   StringParser(const char *s);
89 };
90 
91 #endif
92