Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char gramMatrix[24][24] =
- {// pr end. if then else begin end rep un or and not + - < > = ++ ( ) a := ; |
- /*pr */ {' ', '=', '<', ' ', ' ', '<', ' ', '<', ' ', ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<',' ','<',' '},
- /*en*/ {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', ' ',' ',' ','>'},
- /*if*/ {' ', ' ', ' ', '=', ' ', ' ', ' ', ' ', ' ', '<','<', '<','<','<', '<','<','<','<', '<',' ', '<',' ',' ',' '},
- /*th*/ {' ', ' ', '<', ' ', '=', '<', ' ', '>', ' ', ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<',' ','>',' '},
- /*el*/ {' ', ' ', '<', ' ', ' ', '<', ' ', '>', ' ', ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<',' ','>',' '},
- /*bg*/ {' ', ' ', '<', ' ', ' ', '<', '=', '>', ' ', ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<',' ','<',' '},
- /*e*/ {' ', ' ', ' ', ' ', '>', ' ', ' ', ' ', ' ', ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', ' ',' ','>',' '},
- /*rp*/ {' ', ' ', '<', ' ', '>', '<', ' ', ' ', '=', ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<',' ',' ',' '},
- /*un*/ {' ', ' ', ' ', ' ', ' ', ' ', ' ', '>', ' ', '<','<', '<','<','<', '<','<','<',' ', '<',' ', '<',' ','>',' '},
- /*or*/ {' ', ' ', ' ', '>', ' ', ' ', ' ', ' ', '>', '>','>', '<','<','<', '<','<','<',' ', '<','>', '<',' ',' ',' '},
- /*an*/ {' ', ' ', ' ', '>', ' ', ' ', ' ', ' ', '>', '>','>', '<','<','<', '<','<','<',' ', '<','>', '<',' ',' ',' '},
- /*nt*/ {' ', ' ', ' ', '>', ' ', ' ', ' ', ' ', '>', ' ',' ', '<','<','<', '<','<','<',' ', '<','>', '<',' ',' ',' '},
- /*+*/ {' ', ' ', ' ', '>', ' ', ' ', ' ', ' ', '>', '>','>', ' ','>','>', '>','>','>','>', '<','>', '<',' ','>',' '},
- /*-*/ {' ', ' ', ' ', '>', ' ', ' ', ' ', ' ', '>', '>','>', ' ','>','>', '>','>','>','>', '<','>', '<',' ','>',' '},
- /*> */ {' ', ' ', ' ', '>', ' ', ' ', ' ', ' ', '>', '>','>', ' ','<','<', ' ',' ',' ',' ', '<','>', '<',' ',' ',' '},
- /*< */ {' ', ' ', ' ', '>', ' ', ' ', ' ', ' ', '>', '>','>', ' ','<','<', ' ',' ',' ',' ', '<','>', '<',' ',' ',' '},
- /*= */ {' ', ' ', ' ', '>', ' ', ' ', ' ', ' ', '>', '>','>', ' ','<','<', ' ',' ',' ','<', '<','>', '<',' ',' ',' '},
- /*++*/ {' ', ' ', ' ', '>', '>', ' ', ' ', ' ', '>', '>','>', ' ','<','<', '>','>','>','>', '<','>', '<',' ','>',' '},
- /*( */ {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '<','<', '>','<','<', '<','<','>','>', '<','=', '<',' ',' ',' '},
- /*) */ {' ', ' ', ' ', '>', '>', ' ', ' ', ' ', '>', '>','>', ' ','>','>', '>','>','>',' ', ' ','>', ' ',' ','>',' '},
- /*a */ {' ', ' ', ' ', '>', '>', ' ', ' ', ' ', '>', '>','>', ' ','>','>', '>','>','>','>', ' ','>', ' ','=','>',' '},
- /*:=*/ {' ', ' ', ' ', ' ', '>', ' ', ' ', ' ', ' ', ' ',' ', ' ','<','<', ' ',' ',' ',' ', '<',' ', '<',' ','>',' '},
- /*; */ {' ', '>', '<', ' ', ' ', '<', '>', '<', ' ', ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<','<','>',' '},
- /*н*/ {'<', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', ' ',' ',' ','='},
- };
- //-
- QString gramRules[] = { "progEend.","E;E","E;","ifEthenE","ifEthenEelseE","beginEend",
- "repeatEuntilE", "a:=E","EorE","EandE","notE","E<E","E>E","E=E","(E)",
- "++E","E-E","E+E","a"};
- bool SyntaxAnalyser::BuildTree(QList<Lexem> &lexTable)
- {
- for (QList<Lexem>::iterator iter = lexTable.begin();
- iter != lexTable.end(); ++iter)
- {
- Symbol newSymb;
- newSymb.node = NULL;
- newSymb.lex = &*iter;
- newSymb.name = iter->name;
- if (iter->type == R("Переменная") or
- iter->type == R("Константное значение"))
- {
- newSymb.gramTableNum = 20;
- newSymb.name = "a";
- }
- else if (iter->name == "prog")
- newSymb.gramTableNum = 0;
- else if (iter->name == "end.")
- newSymb.gramTableNum = 1;
- else if (iter->name == "if")
- newSymb.gramTableNum = 2;
- else if (iter->name == "then")
- newSymb.gramTableNum = 3;
- else if (iter->name == "else")
- newSymb.gramTableNum = 5;
- else if (iter->name == "begin")
- newSymb.gramTableNum = 6;
- else if (iter->name == "end")
- newSymb.gramTableNum = 7;
- else if (iter->name == "repeat")
- newSymb.gramTableNum = 8;
- else if (iter->name == "until")
- newSymb.gramTableNum = 9;
- else if (iter->name == "or")
- newSymb.gramTableNum = 10;
- else if (iter->name == "and")
- newSymb.gramTableNum = 11;
- else if (iter->name == "not")
- newSymb.gramTableNum = 12;
- else if (iter->name == "+")
- newSymb.gramTableNum = 13;
- else if (iter->name == "-")
- newSymb.gramTableNum = 14;
- else if (iter->name == ">")
- newSymb.gramTableNum = 15;
- else if (iter->name == "<")
- newSymb.gramTableNum = 16;
- else if (iter->name == "=")
- newSymb.gramTableNum = 17;
- else if (iter->name == "++")
- newSymb.gramTableNum = 18;
- else if (iter->name == "(")
- newSymb.gramTableNum = 19;
- else if (iter->name == ")")
- newSymb.gramTableNum = 21;
- else if (iter->name == ":=")
- newSymb.gramTableNum = 22;
- else if (iter->name == ";")
- newSymb.gramTableNum = 23;
- else if (iter->name == "|k" || iter->name == "|n" )
- newSymb.gramTableNum = 24;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement