// File: Parser.h #if !defined PARSER_H #define PARSER_H #pragma warning(disable:4786) #include "tokens.h" #include "CSPException.h" #include "Lexer.h" #include "exp.h" #include "domains.h" #include "Variable.h" #include "Constraint.h" #include "CSProblem.h" #include #include /** Analizzatore sintattico */ class Parser { public: /** Costruttore */ Parser(const std::string& s); /** Legge il dominio di una variabile */ Domain *readDomain() throw (ParserException); // delete a carico del chiamante /** Legge il nome di una variabile e restituisce una variabile con dominio vuoto */ Variable *readVariable() throw (ParserException); // delete a carico del chiamante /** Legge una variabile con relativo dominio (es: x::[1..42]) */ Variable *readVariableWithDomain() throw (ParserException); // delete a carico del chiamante /** Legge un vincolo */ Constraint *readConstraint() throw (ParserException); // delete a carico del chiamante /** Legge un intero programma */ void readProgram(CSProblem *p) throw (ParserException); /** Distruttore */ ~Parser(); private: /** Disabilitazione del costruttore per copia */ Parser(const Parser& par); /** Disabilitazione dell'operatore di assegnamento */ Parser& operator=(const Parser& par); /** Controlla se il token è un operatore relazionale */ static bool isRelOperator(Token* tok); /** Controlla se il token è un operatore di somma o sottrazione */ static bool isSumOperator(Token* tok); /** Controlla se il token è un operatore di moltiplicazione o divisione */ static bool isMulOperator(Token* tok); /** Legge un'espressione relazionale */ Exp *readRelExp() throw (ParserException); /** Legge un'espressione aritmetica */ Exp *readExp() throw (ParserException); /** Legge un termine */ Exp *readTerm() throw (ParserException); /** Legge un fattore */ Exp *readFactor() throw (ParserException); /** Legge una lista di sottodomini */ void readDomainList(Domain * d) throw (ParserException); /** Legge un sottodominio */ void readDomainElement(Domain * d) throw (ParserException); /** Legge un numero intero */ int readInteger() throw (ParserException); /** Salta i token di fine linea */ void skipEOL(); /** Legge il successivo token dal lexer e lo imposta come token corrente */ void nextToken(); /** Token dorrente */ Token *curToken; /** Analizzatore lessicale */ Lexer *lex; }; #endif