Skip to content

Interactive mode for working with the parse tree#41

Open
MinyazevR wants to merge 23 commits into
mainfrom
SolvingTheProblem
Open

Interactive mode for working with the parse tree#41
MinyazevR wants to merge 23 commits into
mainfrom
SolvingTheProblem

Conversation

@MinyazevR
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Название ветки и пулреквеста ужасно :) И программа не объясняет себя, а просто работает, так нельзя. Писать надо не для себя, а для людей, которые это читать будут.

Comment thread ParsingTree/ParsingTree/ParsingTree.c Outdated
struct Node* parent;
char value;
int number;
char help;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Не называйте переменные "help", это мило, но не мнемонично.

Comment thread ParsingTree/ParsingTree/ParsingTree.c Outdated
return root->number;
}

bool compare(char symbol)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тоже название не очень. compare чего с чем? Тем более тут проверяется, является ли символ оператором, так что я бы isOperator это назвал

Comment thread ParsingTree/ParsingTree/ParsingTree.c Outdated
|| symbol == '*' || symbol == '/';
}

Node* buildTree(char* array)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const char* array
Чтобы явно сказать всем, что мы не собираемся менять элементы массива, и разрешить, в частности, принимать строковые литералы сюда, что сделает работу с этой функцией в сотню раз более удобной

Comment thread ParsingTree/ParsingTree/ParsingTree.c Outdated
Node* newRoot = (Node*)calloc(1, sizeof(Node));
if (newRoot == NULL)
{
return NULL;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так всё построенное до этого дерево потеряется

Comment thread ParsingTree/ParsingTree/ParsingTree.c Outdated
Comment on lines +11 to +12
char value;
int number;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну тоже переменные названы замечательно, непонятно, кто из них кто.

{
Node* firstTree = createTree();
firstTree = buildTree("- * + 4 3 5 * 2 7");
firstTree = returnHead(firstTree);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Разве не buildTree должна была бы это делать?

Comment thread ParsingTree/ParsingTree/ParsingTree.h Outdated
Comment on lines +28 to +34
Node* rightSon(Node* root);

// Function for accessing the left son of the current root
Node* leftSon(Node* root);

// Function for accessing the parent of the current root
Node* parent(Node* root);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не слишком ли много дерево раскрывает о себе? Сокрытие деталей реализации тут не очень, и принцип минимальности интерфейса абстракции тоже страдает

}
char expression[100] = { '\0' };
return buildTree(fgets(expression, 100, file));
fclose(file);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оно так не работает :)

#include "../../ParsingTree/ParsingTree/ParsingTree.h"
#include <stdio.h>

Node* readExpression(Node* tree, const char* fileName, int* error)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tree не используется, что намекает на утечку памяти

tree = returnHead(tree);
findAnswer(tree);
const int answer = returnAnswer(tree);
printf("Meaning of the expression : %d\n", answer);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"meaning" --- это "значение" в смысле "смысл". Тут правильно "value" или "result" или что-то такое.

@MinyazevR MinyazevR changed the title Solving the problem InteractiveModeForWorkingWithTheParseTree Nov 19, 2021
@MinyazevR MinyazevR changed the title InteractiveModeForWorkingWithTheParseTree Interactive mode for working with the parse tree Nov 19, 2021
Copy link
Copy Markdown

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Утечки памяти тоже надо поправить

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

На самом деле, был ли узел посещён — это состояние обхода, а не свойство узла, потому что если мы два обхода параллельно запустим, всё сломается. Да даже если два последовательно, сбросится ли статус isVisitedNode? Но если хотите так, то можно не править.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У дерева нет головы, у него есть корень. Но если бы мы назвали эту функцию returnRoot, было бы не очень, потому что параметр у неё называется root. Это плохо.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот, например, тут — это же не корень, это узел

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эта строка — самое нелогичное, что я видел сегодня. Если оператор, то узел не посещён, иначе посещён, что?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут можно уже без else, выше ветка на return заканчивается. Это сэкономит уровень отступа.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Очень длинная строчка, надо перенести на несколько

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше было выводить в строку, потому что иначе эту функцию не протестировать, но ладно, пусть так

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тесты проверяют не тот формат записи, что просили в условии, то есть не доказывают, что программа работает как надо :)

Copy link
Copy Markdown

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почти всё ок, но надо поддержать целые числа

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так "целые числа в качестве аргументов" не получится поддержать. Например, "-15".

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да ну, проще было "если оператор, распечатать скобку, знак, вызваться рекурсивно от левого и правого сына, распечатать закрывающую скобку. Если операнд, просто число распечатать".

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тоже не уверен на самом деле, что это надо хранить в дереве. Всё равно ведь пересчитываете каждый раз. return findAnswer(root->leftSon, error); тоже было бы ок.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants