예제 #1
0
 private void checkUnaryMinus(LexemaSequence input, Lexema lexema)
 {
     if (lexema.symbol == Expression.MINUS)
     {
         bool must_change = false;
         if (input.GetPosition() > 1)
         {
             char symbol = input.getLexema(input.GetPosition() - 2).symbol;
             if ((symbol == Expression.ASSIGNMENT) ||
                 (symbol == Expression.OPEN_BRACE) ||
                 (symbol == Expression.PLUS) ||
                 (symbol == Expression.MULTUPLICATION) ||
                 (symbol == Expression.BITWISE_OR) ||
                 (symbol == Expression.DIVISION) ||
                 (symbol == Expression.MODUL) ||
                 (symbol == Expression.BITWISE_AND) ||
                 (symbol == Expression.BITWISE_INVERSION) ||
                 (symbol == Expression.BOOLEAN_INVERSION))
             {
                 must_change = true;
             }
         }
         else
         {
             must_change = true;
         }
         if (must_change)
         {
             lexema.symbol = Expression.UNARY_MINUS;
         }
     }
 }
예제 #2
0
 private bool changeSymbol(LexemaSequence input, Lexema lexema, char search_symbol,
                           char replace_symbol)
 {
     if (lexema.symbol == search_symbol)
     {
         if (input.GetPosition() > 1)
         {
             if (input.getLexema(input.GetPosition() - 2).symbol == Expression.IDENTIFIER)
             {
                 lexema.symbol = replace_symbol;
                 return(true);
             }
         }
         if (input.GetPosition() < input.size())
         {
             if (input.peekLexema().symbol == Expression.IDENTIFIER)
             {
                 //това е префиксна операция, не се прави заместване
                 return(true);
             }
             else
             {
                 Console.WriteLine(search_symbol + " can be applyed only to identifier.");
                 return(false);
             }
         }
         Console.WriteLine("Error 1002.");
         return(false);
     }
     else
     {
         return(true);
     }
 }