Теория вычислительных процессов

Автор: Пользователь скрыл имя, 15 Сентября 2012 в 17:08, лабораторная работа

Описание работы

Создание в среде Pascal программы, которая определяет правильно ли описаны переменные языка Паскаль во входном файле input.txt

Содержание

1. Задание
1.1 Входные данные
1.2 Выходные данные
2. Краткая теория
3. Результаты работы программы
4. Выводы
Список литературы
Приложение.

Работа содержит 1 файл

Лаб№1.doc

— 101.50 Кб (Скачать)

                      err_pos:=err_pos+position;

                      err_name:='Ожидается "," или ":", а найдено '+'"'+lines[err_line][err_pos]+'"';

                      check:=false;

                      exit;

                    end;

                end;

      COLON    :

                begin

                  case UpCase(lines[line][position]) of

                    'A':

                        begin

                              if UpperCase(get_str) = 'ARRAY' then

                                begin

                                  prev_pos:= ARRAY_P;

                                  check(lines[line]);

                                  exit;

                                end

                              else

                                  goto else_p_colon;

                        end;

                    'S':

                        begin

                          if UpperCase(get_str) = 'STRING' then

                            begin

                              prev_pos:=VAR_TYPE;

                              aft_str:=true;

                              check(lines[line]);

                              exit;

                            end

                          else

                            goto else_p_colon;

                        end;

                    'I':

                        begin

                          if UpperCase(get_str) = 'INTEGER' then

                            begin

                              prev_pos:=VAR_TYPE;

                              check(lines[line]);

                              exit;

                            end

                          else

                            goto else_p_colon;

                        end;

                    'R':

                        begin

                          if UpperCase(get_str) = 'REAL' then

                            begin

                              prev_pos:=VAR_TYPE;

                              check(lines[line]);

                              exit;

                            end

                          else

                            goto else_p_colon;

                        end;

                  else

                    begin

else_p_colon:         err_name:='Ожидается "array" или тип переменной'; //Можно добавить вывод имени, встретившегося вместо переменной

                      err_line:=line;

                      err_pos:=err_pos+position-(length(temp_str));

                      check:=false;

                      exit;

                    end;

                  end;

                end;

      ARRAY_P  :

                begin

                  is_array:=true;

                  if lines[line][position] = '[' then        

                    begin

                      prev_pos:=BRECKET_1;

                      startP:='';

                      position:=position+1;

                      check(lines[line]);

                      exit;

                    end

                  else

                    if (UpCase(lines[line][position])='O') then

                     begin

                      if UpperCase(get_str) = 'OF' then

                        begin

                          prev_pos:=COLON;

                          is_array:=false;

                          check(lines[line]);

                          exit;

                        end

                     end

                  else

                    begin

                       err_line:=line;

                       err_pos:=err_pos+position;

                       err_name:='Ожидается "[", а найдено '+'"'+lines[err_line][err_pos]+'"';

                       check:=false;

                       exit;

                    end;

                end;

      BRECKET_1:      //  "["  ,  ".."  ,  ","

                begin

                  if (lines[line][position]>='0') and (lines[line][position]<='9') then

                    begin

                      if (not aft_dots) or (aft_str) then //если двух точек не было ИЛИ это не строка

                        begin

                          while (lines[line][position]>='0') and (lines[line][position]<='9') do

                            begin

                              startP:=startP+lines[line][position];

                              position:=position+1;

                            end;

                          if aft_str then //Проверка длинны строки не может быть длиннее 255 сиволов

                              if StrToInt(startP) > 255 then

                                begin

                                  err_line:=line;

                                  err_pos:=err_pos+position;

                                  err_name:='Длинна строки не может быть больше 255';

                                  check:=false;

                                  exit;

                                end;

                        end

                      else //если 2 точки были

                        begin

                          while (lines[line][position]>='0') and (lines[line][position]<='9') do

                            begin

                              endP:=endP+lines[line][position];

                              position:=position+1;

                            end;

                          if StrToInt(endP) < StrToInt(startP) then  //Проверяем границы массива

                            begin

                                  err_line:=line;

                                  err_pos:=err_pos+position;

                                  err_name:='Верхняя граница массива не может быть меньше нижней';

                                  check:=false;

                                  exit;

                            end

                        end; 

                      prev_pos:=NUMERIC;

                      check(lines[line]);

                      exit;

                    end

                  else //Если не цифра

                    begin

                       err_line:=line;

                       err_pos:=err_pos+position;

                       err_name:='Ожидается цифра, а найдено '+'"'+lines[err_line][err_pos]+'"';

                       check:=false;

                       exit;

                    end;

                end;

      NUMERIC  :

                begin

                  case lines[line][position] of

                    '.'       :

                               begin

                                if (not aft_str) and (not aft_dots) then

                                  begin

                                   while lines[line][position]='.' do    //Впринципе, можно совместить с процедурой get_str

                                      begin

                                        dots_str:=dots_str+lines[line][position];

                                        position:=position+1;

                                      end;

                                   if dots_str = '..' then

                                    begin

                                          prev_pos:=BRECKET_1;

                                          endP:='';

                                          aft_dots:=true;

                                          check(lines[line]);

                                          exit;

                                    end

                                   else

                                    goto else_p_num;

                                  end

                                else

                                  begin

                                   err_line:=line;

                                   err_pos:=err_pos+position;

                                   if aft_str then

                                    err_name:='Ожидается "]", а найдено '+'"'+lines[err_line][err_pos]+'"'

                                   else

                                    err_name:='Не ожидается "."';

                                   check:=false;

                                   exit;

                                  end;

                               end;

 

                    ','       :

                               begin

                                if (not aft_str) and (aft_dots) then   //Уже было ".."

                                  begin

                                    prev_pos:=BRECKET_1;

                                    startP:='';

                                    position:=position+1;

                                    aft_dots:=false;

                                    check(lines[line]);

                                    exit;

                                  end

                                else

                                  begin

                                   err_line:=line;

                                   err_pos:=err_pos+position;

                                   if aft_str then

                                    err_name:='Ожидается "]", а найдено '+'"'+lines[err_line][err_pos]+'"'

                                   else

                                    err_name:='Не ожидается ","';

                                   check:=false;

                                   exit;

                                  end;

                               end;

                    ']'       :

                               begin

                                if ((is_array) and (aft_dots)) or (aft_str) then

                                  begin

                                   prev_pos:=BRECKET_2;

                                   aft_str:=false;

                                   aft_dots:=false;//************

                                   position:=position+1;

                                   check(lines[line]);

                                   exit;

                                  end

                                else

                                  goto else_p_num;

                               end;

                  else

else_p_num:         begin

Информация о работе Теория вычислительных процессов