Розробка системних програмних модулів та компонент систем програмування

Автор: Пользователь скрыл имя, 25 Февраля 2012 в 16:19, курсовая работа

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

Незважаючи на більш ніж піввікову історію обчислювальної техніки, формально роком народження теорії трансляторів можна вважати 1957, коли з'явився перший транслятор мови Фортран, створений Бекасом. До цього часу створення трансляторів було досить "творчим" процесом. Лише поява теорії формальних мов і строгих математичних моделей дозволило перейти від "творчості" до "науки".

Содержание

Вступ
1. Огляд методів та способів проектування трансляторів
1.1. Основні поняття і визначення
1.2. Узагальнена структура транслятора
1.4. Варіанти взаємодії блоків транслятора
2. Формальний опис вхідної мови програмування
2.1. Деталізований опис вхідної мови в термінах розширеної нотації Бекуса-Наура
2.2. Опис термінальних символів та ключових слів
3. Розробка транслятора вхідної мови програмування
3.1. Вибір технології програмування
3.2. Проектування таблиць транслятора та вибір структур даних
3.3. Розробка лексичного аналізатора
3.3.1. Розробка граф-схеми алгоритму
3.3.2. Опис програмної реалізації лексичного аналізатора
3.4. Розробка синтаксичного та семантичного аналізатора
3.4.1. Розробка граф-схеми алгоритму
3.4.2. Опис програмної реалізації синтаксичного та семантичного аналізатора
3.5. Розробка генератора коду
3.5.1. Розробка граф-схеми алгоритму
3.5.2. Опис програмної реалізації генератора коду
4. Опис інтерфейсу та інструкції користувача
4.1. Опис інтерфейсу
4.1.1. Головне меню та панель інструментів.
4.2. Інструкція програміста
4.2.1. Алфавіт мови
4.2.2. Коментарі
4.2.3. Тип даних
4.2.4. Розділи, використовувані при написанні програм
4.2.5. Типи операцій
4.2.6. Типи операторів
5. Відлагодження та тестування програми
5.1. Виявлення лексичних помилок
5.2. Виявлення синтаксичних помилок
5.3. Виявлення семантичних помилок
5.4. Загальна перевірка коректності роботи транслятора
Висновки
Список літератури
Додатки
А. Лістинг програми

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

asm_cource_k9.doc

— 1,020.00 Кб (Скачать)

                            code += "mov eax,temp\n";

                            code += "fistp temp\n";

                            code += "cmp eax,temp\n";

                            code += "jne lbl" + Convert.ToString(LblCount) + "\n";

                            code += "mov edx,1\n";

                            code += "lbl" + Convert.ToString(LblCount++) + ":\n";

                            code += "mov temp,edx\n";

                            code += "fild temp\n";

                            code += ";---------------------\n";

                            break;

                        case "NotEqual":

                            code += ";---st(0) != st(1)---";

                            code += "mov edx,0\n";

                            code += "fistp temp\n";

                            code += "mov eax,temp\n";

                            code += "fistp temp\n";

                            code += "cmp eax,temp\n";

                            code += "je lbl" + Convert.ToString(LblCount) + "\n";

                            code += "mov edx,1\n";

                            code += "lbl" + Convert.ToString(LblCount++) + ":\n";

                            code += "mov temp,edx\n";

                            code += "fild temp\n";

                            code += ";---------------------\n";

                            break;

                        case "LesserOrEqual":

                            code += ";---st(0) <= st(1)---";

                            code += "mov edx,0\n";

                            code += "fistp temp\n";

                            code += "mov eax,temp\n";

                            code += "fistp temp\n";

                            code += "cmp eax,temp\n";

                            code += "jg lbl" + Convert.ToString(LblCount) + "\n";

                            code += "mov edx,1\n";

                            code += "lbl" + Convert.ToString(LblCount++) + ":\n";

                            code += "mov temp,edx\n";

                            code += "fild temp\n";

                            code += ";---------------------\n";

                            break;

                        case "GreaterOrEqual":

                            code += ";---st(0) >= st(1)---";

                            code += "mov edx,0\n";

                            code += "fistp temp\n";

                            code += "mov eax,temp\n";

                            code += "fistp temp\n";

                            code += "cmp eax,temp\n";

                            code += "jl lbl" + Convert.ToString(LblCount) + "\n";

                            code += "mov edx,1\n";

                            code += "lbl" + Convert.ToString(LblCount++) + ":\n";

                            code += "mov temp,edx\n";

                            code += "fild temp\n";

                            code += "---------------------\n";

                            break;

                        case "Not":

                            code += "f_not\n";

                            break;

                        case "Or":

                            code += "f_or\n";

                            break;

                        case "And":

                            code += "f_and\n";

                            break;

                    }

                }

            }

            catch (InvalidOperationException)

            {

                AddError("Incorect form of expression", line);

            }

            TreeNode Code = new TreeNode(code);

            Output.Push(Code);

            return Output;

        }

        private TreeNode Coagulation(Stack<TreeNode> inp)

        {

            TreeNode Node = new TreeNode("Block");

            Node.Text = "Block";

            Node.Name = "";

            Node.ImageKey = "Block";

            Node.SelectedImageIndex = inp.First().SelectedImageIndex;

            for (; inp.Count > 0; )

            {

                if ((inp.First().ImageKey == "Block") | (inp.First().ImageKey == "Cycle") | (inp.First().ImageKey == "IOStream"))

                    Node.Name += inp.First().Name;

                Node.Nodes.Add(inp.Pop());

            }

            return Node;

        }

        //Additional fumctions, they help to reduce volume of text

        bool CheckIdentForDefine(int i)

        {

            for (; i < LexTable.Count - 1; i++)

            {

                if (LexTable[i].Type == LexemType.Ident)

                {

                    bool IsDeclared = false;

                    bool IsInitialized = false;

                    for (int j = 0; j < IdentTable.Count; j++)

                    {

                        if (LexTable[i].Text == IdentTable[j].Name)

                        {

                            IsDeclared = true;

                            if (LexTable[i + 1].Type == LexemType.Equator)

                            {

                                IsInitialized = true;

                                IdentTable[j].IsDeclared = true;

                            }

                            else

                            {

                                IsInitialized = IdentTable[j].IsDeclared;

                            }

                        }

                    }

                    if (!IsDeclared)

                    {

                        AddError("Undeclared identifier [" + LexTable[i].Text + "] used!", LexTable[i].Line);

                        return false;

                    }

                    else

                    {

                        if (!IsInitialized)

                        {

                            AddError("Uninitialized identifier [" + LexTable[i].Text + "] used!", LexTable[i].Line);

                            return false;

                        }

                    }

                }

            }

            return true;

        }

        private bool LogicalExpressionPart(string LexType)

        {

            if ((LexType == "Ident") | (LexType == "Const") | (LexType == "Addition") | (LexType == "Substraction") |

                (LexType == "OpenBracket") | (LexType == "CloseBracket") | (LexType == "Multiplication") | (LexType == "Divide") |

                (LexType == "Module") | (LexType == "And") | (LexType == "Or") | (LexType == "Not") |

                (LexType == "Equal") | (LexType == "NotEqual") | (LexType == "LesserOrEqual") | (LexType == "GreaterOrEqual") | (LexType == "Equator"))

            {

                return true;

            }

            else

            {

                return false;

            }

        }

        private Stack<TreeNode> Reverse(Stack<TreeNode> in_)

        {

            Stack<TreeNode> ret = new Stack<TreeNode>();

            while(in_.Count > 0)

            {

                ret.Push(in_.Pop());

            }

            return ret;

        }

       

        private void AddError(string error_text, int line)

        {

            Error Err = new Error();

            Err.Line = line;

            Err.Text = error_text;

            SyntaxErrors.Add(Err);

        }

        private TreeNode LexToNode(Lexema Lex)

        {

            TreeNode tmp = new TreeNode();

            tmp.Text = Lex.Text + "[" + Convert.ToString(Lex.Type) + "]";

            tmp.Name = Lex.Text;

            tmp.ImageIndex = Lex.Value;

            tmp.SelectedImageIndex = Lex.Line;

            tmp.ImageKey = Convert.ToString(Lex.Type);

            return tmp;

        }

        //class objects

        int StrCount;

        int LblCount;

        int ExitCicleCount;

        int StartCicleCount;

        private TreeNode GramTree;

        public List<Strings> StringTable;

        public List<Identificator> IdentTable;

        public List<Identificator> ConstTable;

        private List<Lexema> LexTable;

        public Errors SyntaxErrors;

        public int[,] PriorityTable;

      

    }

}

 



Информация о работе Розробка системних програмних модулів та компонент систем програмування