Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ZPOlab2.1.cpp: definiuje punkt wejścia dla aplikacji konsolowej.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- class MyError
- {
- public:
- MyError(string x)
- {
- cout << x << endl;
- exit(0);
- }
- MyError(int i, string x)
- {
- cout << "Blad w linii " << i << ". " << x << endl;
- exit(0);
- }
- };
- template <typename T , int rozm>
- class SzablonStosu
- {
- T stos[rozm];
- int top;
- public:
- SzablonStosu() : top(0) {}
- void push(const T &i)
- {
- stos[top++] = i;
- }
- T pop()
- {
- return stos[--top];
- }
- };
- void CheckMath(fstream &stream)
- {
- string pom;
- stream >> pom;
- if ( pom != "<math" && pom != "<math>" ) throw MyError("Brak tagu <math>");
- while (pom != "</math>" && !stream.eof() )
- {
- stream >> pom;
- }
- if (pom != "</math>") throw MyError("Brak tagu </math>");
- stream.seekg(0);
- }
- void CheckTag(fstream &stream)
- {
- string str;
- int pom;
- for (int i = 1; !stream.eof(); i++)
- {
- getline(stream, str);
- pom = str.find('>') + 1;
- if (str.substr(0,5) == "<math" || str.substr(0,pom) == "</math>" ){ } // ok
- else if (str.substr(0, pom) == "<mi>" && str.substr(pom + 1, 5) != "</mi>")
- {
- throw MyError( i , "Brak tagu zamykajacego </mi>.");
- }
- else if (str.substr(0, pom) == "<mo>" && str.substr(pom + 1, 5) != "</mo>")
- {
- throw MyError(i, "Brak tagu zamykajacego </mo>.");
- }
- else if (str.substr(0, pom) == "<mn>" && str.substr(pom + 1, 5) != "</mn>")
- {
- throw MyError(i, "Brak tagu zamykajacego </mn>.");
- }
- else if (str.substr(0, pom) == "<msup>")
- {
- // tu nie wiem co..
- }
- else if (str.substr(0, pom) != "<mi>" && str.substr(0, pom) != "<mo>" && str.substr(0, pom) != "<mn>" && str.substr(0, pom) != "<msup>")
- {
- throw MyError( i , "Nie rozpoznany tag." );
- }
- }
- stream.seekg(0);
- }
- void Check( fstream &stream )
- {
- try
- {
- CheckMath(stream);
- CheckTag(stream);
- }
- catch (MyError) { }
- }
- int main()
- {
- // strumien do pliku
- fstream stream;
- stream.open( "dane.txt" , ios::in );
- if ( !stream.good() )
- {
- cout << "Blad otwarcia pliku" << endl;
- exit(0);
- }
- Check(stream);
- stream.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement