Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.49 KB | None | 0 0
  1. char gramMatrix[24][24] =
  2. {//       pr  end. if   then else begin end  rep  un    or  and  not +    -    <   >   =  ++   (    )    a  :=   ;   |
  3. /*pr */ {' ', '=', '<', ' ', ' ', '<',  ' ', '<', ' ',  ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<',' ','<',' '},
  4. /*en*/  {' ', ' ', ' ', ' ', ' ', ' ',  ' ', ' ', ' ',  ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', ' ',' ',' ','>'},
  5. /*if*/  {' ', ' ', ' ', '=', ' ', ' ',  ' ', ' ', ' ',  '<','<', '<','<','<', '<','<','<','<', '<',' ', '<',' ',' ',' '},
  6. /*th*/  {' ', ' ', '<', ' ', '=', '<',  ' ', '>', ' ',  ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<',' ','>',' '},
  7. /*el*/  {' ', ' ', '<', ' ', ' ', '<',  ' ', '>', ' ',  ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<',' ','>',' '},
  8. /*bg*/  {' ', ' ', '<', ' ', ' ', '<',  '=', '>', ' ',  ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<',' ','<',' '},
  9. /*e*/   {' ', ' ', ' ', ' ', '>', ' ',  ' ', ' ', ' ',  ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', ' ',' ','>',' '},
  10. /*rp*/  {' ', ' ', '<', ' ', '>', '<',  ' ', ' ', '=',  ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<',' ',' ',' '},
  11. /*un*/  {' ', ' ', ' ', ' ', ' ', ' ',  ' ', '>', ' ',  '<','<', '<','<','<', '<','<','<',' ', '<',' ', '<',' ','>',' '},
  12. /*or*/  {' ', ' ', ' ', '>', ' ', ' ',  ' ', ' ', '>',  '>','>', '<','<','<', '<','<','<',' ', '<','>', '<',' ',' ',' '},
  13. /*an*/  {' ', ' ', ' ', '>', ' ', ' ',  ' ', ' ', '>',  '>','>', '<','<','<', '<','<','<',' ', '<','>', '<',' ',' ',' '},
  14. /*nt*/  {' ', ' ', ' ', '>', ' ', ' ',  ' ', ' ', '>',  ' ',' ', '<','<','<', '<','<','<',' ', '<','>', '<',' ',' ',' '},
  15. /*+*/   {' ', ' ', ' ', '>', ' ', ' ',  ' ', ' ', '>',  '>','>', ' ','>','>', '>','>','>','>', '<','>', '<',' ','>',' '},
  16. /*-*/   {' ', ' ', ' ', '>', ' ', ' ',  ' ', ' ', '>',  '>','>', ' ','>','>', '>','>','>','>', '<','>', '<',' ','>',' '},
  17. /*> */  {' ', ' ', ' ', '>', ' ', ' ',  ' ', ' ', '>',  '>','>', ' ','<','<', ' ',' ',' ',' ', '<','>', '<',' ',' ',' '},
  18. /*< */  {' ', ' ', ' ', '>', ' ', ' ',  ' ', ' ', '>',  '>','>', ' ','<','<', ' ',' ',' ',' ', '<','>', '<',' ',' ',' '},
  19. /*= */  {' ', ' ', ' ', '>', ' ', ' ',  ' ', ' ', '>',  '>','>', ' ','<','<', ' ',' ',' ','<', '<','>', '<',' ',' ',' '},
  20. /*++*/  {' ', ' ', ' ', '>', '>', ' ',  ' ', ' ', '>',  '>','>', ' ','<','<', '>','>','>','>', '<','>', '<',' ','>',' '},
  21. /*( */  {' ', ' ', ' ', ' ', ' ', ' ',  ' ', ' ', ' ',  '<','<', '>','<','<', '<','<','>','>', '<','=', '<',' ',' ',' '},
  22. /*) */  {' ', ' ', ' ', '>', '>', ' ',  ' ', ' ', '>',  '>','>', ' ','>','>', '>','>','>',' ', ' ','>', ' ',' ','>',' '},
  23. /*a */  {' ', ' ', ' ', '>', '>', ' ',  ' ', ' ', '>',  '>','>', ' ','>','>', '>','>','>','>', ' ','>', ' ','=','>',' '},
  24. /*:=*/  {' ', ' ', ' ', ' ', '>', ' ',  ' ', ' ', ' ',  ' ',' ', ' ','<','<', ' ',' ',' ',' ', '<',' ', '<',' ','>',' '},
  25. /*; */  {' ', '>', '<', ' ', ' ', '<',  '>', '<', ' ',  ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', '<','<','>',' '},
  26. /*н*/   {'<', ' ', ' ', ' ', ' ', ' ',  ' ', ' ', ' ',  ' ',' ', ' ',' ',' ', ' ',' ',' ',' ', ' ',' ', ' ',' ',' ','='},
  27. };
  28. //-
  29.  
  30.  
  31. QString gramRules[] = { "progEend.","E;E","E;","ifEthenE","ifEthenEelseE","beginEend",
  32.                         "repeatEuntilE", "a:=E","EorE","EandE","notE","E<E","E>E","E=E","(E)",
  33.                         "++E","E-E","E+E","a"};
  34.  
  35. bool SyntaxAnalyser::BuildTree(QList<Lexem> &lexTable)
  36. {
  37.  
  38.   for (QList<Lexem>::iterator iter = lexTable.begin();
  39.        iter != lexTable.end(); ++iter)
  40.   {
  41.        Symbol newSymb;
  42.        newSymb.node = NULL;
  43.        newSymb.lex = &*iter;
  44.        newSymb.name = iter->name;
  45.  
  46.        if (iter->type == R("Переменная") or
  47.            iter->type == R("Константное значение"))
  48.        {
  49.            newSymb.gramTableNum = 20;
  50.            newSymb.name = "a";
  51.        }
  52.        else if (iter->name == "prog")
  53.            newSymb.gramTableNum = 0;
  54.        else if (iter->name == "end.")
  55.            newSymb.gramTableNum = 1;
  56.        else if (iter->name == "if")
  57.            newSymb.gramTableNum = 2;
  58.        else if (iter->name == "then")
  59.            newSymb.gramTableNum = 3;
  60.        else if (iter->name == "else")
  61.            newSymb.gramTableNum = 5;
  62.        else if (iter->name == "begin")
  63.            newSymb.gramTableNum = 6;
  64.        else if (iter->name == "end")
  65.            newSymb.gramTableNum = 7;
  66.        else if (iter->name == "repeat")
  67.            newSymb.gramTableNum = 8;
  68.        else if (iter->name == "until")
  69.            newSymb.gramTableNum = 9;
  70.        else if (iter->name == "or")
  71.            newSymb.gramTableNum = 10;
  72.        else if (iter->name == "and")
  73.            newSymb.gramTableNum = 11;
  74.        else if (iter->name == "not")
  75.            newSymb.gramTableNum = 12;
  76.        else if (iter->name == "+")
  77.            newSymb.gramTableNum = 13;
  78.        else if (iter->name == "-")
  79.            newSymb.gramTableNum = 14;
  80.        else if (iter->name == ">")
  81.            newSymb.gramTableNum = 15;
  82.        else if (iter->name == "<")
  83.            newSymb.gramTableNum = 16;
  84.        else if (iter->name == "=")
  85.            newSymb.gramTableNum = 17;
  86.        else if (iter->name == "++")
  87.            newSymb.gramTableNum = 18;
  88.        else if (iter->name == "(")
  89.            newSymb.gramTableNum = 19;
  90.        else if (iter->name == ")")
  91.            newSymb.gramTableNum = 21;
  92.        else if (iter->name == ":=")
  93.            newSymb.gramTableNum = 22;
  94.        else if (iter->name == ";")
  95.            newSymb.gramTableNum = 23;
  96.        else if (iter->name == "|k" || iter->name == "|n" )
  97.            newSymb.gramTableNum = 24;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement