Семантика языков программирования. Семантический анализ и элементы генерации объектного кода или интерпретации

Страницы работы

Содержание работы

МИНИСТЕРСТВО ОБРАЗОВАНИЯ И НАУКИ

ФЕДЕРАЛЬНОЕ АГЕНТСТВО ПО ОБРАЗОВАНИЮ

ГОСУДАРСТВЕННОЕ ОБРАЗОВАТЕЛЬНОЕ УЧРЕЖДЕНИЕ

ВЫСШЕГО ПРОФЕССИОНАЛЬНОГО ОБРАЗОВАНИЯ

НОВОСИБИРСКИЙ ГОСУДАРСТВЕННЫЙ ТЕХНИЧЕСКИЙ УНИВЕРСИТЕТ

КАФЕДРА ВЫЧИСЛИТЕЛЬНОЙ ТЕХНИКИ

emblem_NSTU_black

Лабораторная работа №8

по дисциплине “Системное программное обеспечение”

Семантика языков программирования. Семантический анализ и элементы генерации объектного кода или интерпретации

Факультет: АВТ

Группа: АМ-709

Студент: Терехов Р.В.

Вариант: 4214414

Преподаватель: Малявко А.А.

Новосибирск

2010г

Цели работы: изучение семантических свойств объектов транслируемой программы, методов их выявления и использования, типов данных и методов контроля типов, областей видимости переменных, локальных и нелокальных сред ссылок, способов передачи параметров, приобретение навыков преобразования псевдокода в объектный код или разработки элементов виртуальной машины для интерпретируемого языка.

Выполнение работы:

Поскольку рисунок с правилами будет огромен и непонятен приведем содержимое XML файла.

<?xml version="1.0" encoding="windows-1251"?>

<transLab>

<lexic>

 <data>

class ServiceHash{//ХЭШ

    public String[] mas;

    public  int[] kind;

    public  boolean[] free;

    public  Object[] data;

     int maskForHash;

     int size;

private int GetIndex(String word){

if(word.length()%2!=0)

       word=word+" ";

int length=word.length();

int buf=1;

for(int j=0; j&lt;word.length(); j+=2){

 buf=buf*(word.charAt(j)*1024+word.charAt(j+1));

}

return buf&maskForHash;

}

public ServiceHash(int Size){

size=1;

maskForHash=0;

for(int i=0; i&lt;Size; i++){

maskForHash=maskForHash&lt;&lt;1|1;

size*=2;}

data=new Object[size];

   mas=new String[size];

free=new boolean[size];

kind =new int[size];

for(int i=0; i&lt;size; i++){

free[i]=true;

kind[i]=0;

}

Insert("card");

Insert("float");

Insert("char");

Insert("logical");

Insert("true");

Insert("false");

Insert("data");

Insert("get");

Insert("drop");

Insert("if");

Insert("else");

Insert("select");

Insert("case");

Insert("endcase");

Insert("cycle");

Insert("return");

Insert("private");

Insert("public");

Insert("end");

}

public ServiceHash(){

size=1;

maskForHash=0;

for(int i=0; i&lt;9; i++){

maskForHash=maskForHash&lt;&lt;1|1;

size*=2;}

   mas=new String[size];

kind=new int[size];

free=new boolean[size];

data=new Object[size];

for(int i=0; i&lt;size; i++){

free[i]=true;

kind[i]=0;

}

Insert("card");

Insert("float");

Insert("char");

Insert("logical");

Insert("true");

Insert("false");

Insert("data");

Insert("get");

Insert("drop");

Insert("if");

Insert("else");

Insert("select");

Insert("case");

Insert("endcase");

Insert("cycle");

Insert("void");

Insert("return");

Insert("private");

Insert("public");

Insert("end");

}

public void Insert(lexem Lexem){

String str=Lexem.textOfWord.toString();

int i=GetIndex(str);

int j=0;

while(j!=size){

      if(free[i]){

              mas[i]=str;

              Lexem.wordIndex=i;

             free[i]=false;

             return;

        }

      if(mas[i].compareTo(str)==0){

             Lexem.wordIndex=i;

              return;

      }

      j++;

     i=(i+j)%size;

}

return;

}

public void Insert(String str){

int i=GetIndex(str);

int j=0;

while(j!=size){

      if(free[i]){

              mas[i]=str;

             free[i]=false;

             return;

        }

      if(mas[i].compareTo(str)==0){

              return;

      }

      j++;

     i=(i+j)%size;

}

return;

}

public boolean Search(lexem Lexem){

String str=Lexem.textOfWord.toString();

int i=GetIndex(str);

int j=0;

while(j!=size&&free[i]==false){

      if(mas[i].compareTo(str)==0){

          Lexem.wordIndex=i;

          return true;

     }

      j++;

     i=(i+j)%size;

}

return false;

}

};

ServiceHash identTable=new ServiceHash(16);

 </data>

 <automat name='main'>

  <rule groupWordsName='LineComentStart'>

   <expression>"//"</expression>

   <action>ignoreLastWord=true;

lexStk.push(lexAcceptor);

lexAcceptor=lexAcceptors[findAutomat("LineComent")];</action>

   <comment>Начало одно строчного коментария, сохранение в стеке текущего лексического акцептора, и поиск среди акцепторов автомата для разбора одно строчного комента.</comment>

  </rule>

  <rule groupWordsName='MultiCommentStart'>

   <expression>"/*"</expression>

Похожие материалы

Информация о работе