From 9557d0cb5a1b3aa9466ddc504be004b5449ce9f2 Mon Sep 17 00:00:00 2001 From: YanaRG Date: Sat, 3 Nov 2018 15:22:53 +0200 Subject: Added prettifier and control structure collapse. (#19) * Create README.md * Initial commit * Initial commit * Create README.md * Rename homework/81281/c2html.pl to homework/81281/c2html/c2html.pl * Rename homework/81281/test.c to homework/81281/c2html/test.c * Update README.md * Update README.md * Update c2html.pl * Update c2html.pl * Update c2html.pl * Update README.md * Update c2html.pl * Update test.c * Create executeProgram.sh * Update README.md * Update c2html.pl * Initial commit of updated code + prettify C * Rename secret.c to messyCode.c * Update and rename test.c to initialTest.c * Update README.md * Update README.md * Update README.md * Update README.md * Rename executeProgram.sh to c2htmlrun.sh * Update README.md * Update prettify.pl * Update prettify.pl * Update messyCode.c * Fixed some bugs. * Update README.md * Update c2html.pl * Added collapse and fixed matrix representation. * Updated flatten and added predicate for function identification. * Update initialTest.c * Update messyCode.c * Bug fixing, added is_functionAndBody predicate. * Update print.pl * Result after applying prettify and added collapse functions * Can identify structures and collapse them too * Can identify structures and collapse them too * Can identify structures and collapse them too * Can identify structures and collapse them too * Can identify structures and collapse them too * Update messyCode.c * Update README.md * Update prettify.pl * Update README.md * Update prettify.pl * Update messyCode.c * Update messyCode.c * Update page.html * Fix bug typedef * Update page.html * Added choices * Update c2html.pl * Update prettify.pl * Update prettify.pl * Update README.md * Update README.md * Update c2html.pl * Update c2html.pl * Added forgotten do-while structure format * Update messyCode.c * Removing unknown tokens from stream * Rename homework/81281/c2html/page.html to homework/81281/c2html/exampleCodeAndTestPage/page.html * Rename homework/81281/c2html/messyCode.c to homework/81281/c2html/exampleCodeAndTestPage/messyCode.c * Rename homework/81281/c2html/initialTest.c to homework/81281/c2html/exampleCodeAndTestPage/initialTest.c * Update prettify.pl * Can collapse all control structures and fixed comment /**/ * Can collapse all control structures and fixed comment /**/ * Can collapse all control structures and fixed comment /**/ * Can collapse all control structures and fixed comment /**/ * Can collapse all control structures and fixed comment /**/ * Fixed named of predicates * Update messyCode.c * Update page.html * Update README.md * Changed execTAB to "\s\s\s\s" * Changed execTAB to "\s\s\s\s" * Changed execTAB to "\s\s\s\s" * Update page.html * Added new tokens (forgotten operators) and added rules for them * Added new tokens (forgotten operators) and fixed some old predicates * Fixed bug with "else '\n' if (..)" in addNewLines predicate * Fixed regular expression for a string and removed token ttypesPrintF * Added clauses for handling enum and fixed handling of chars * Fixed typos * Added forgotten token to clause * Fixed "case smt :'\n'" where smt is more than one char * Fixed some bugs and divided code in modules * New code module and fixed bugs * Fixed some bugs with tabulation * Divided code in modules --- .../c2html/exampleCodeAndTestPage/initialTest.c | 99 ++++++++ .../c2html/exampleCodeAndTestPage/messyCode.c | 139 +++++++++++ .../81281/c2html/exampleCodeAndTestPage/page.html | 266 +++++++++++++++++++++ 3 files changed, 504 insertions(+) create mode 100644 homework/81281/c2html/exampleCodeAndTestPage/initialTest.c create mode 100644 homework/81281/c2html/exampleCodeAndTestPage/messyCode.c create mode 100644 homework/81281/c2html/exampleCodeAndTestPage/page.html (limited to 'homework/81281/c2html/exampleCodeAndTestPage') diff --git a/homework/81281/c2html/exampleCodeAndTestPage/initialTest.c b/homework/81281/c2html/exampleCodeAndTestPage/initialTest.c new file mode 100644 index 0000000..7f1b4cd --- /dev/null +++ b/homework/81281/c2html/exampleCodeAndTestPage/initialTest.c @@ -0,0 +1,99 @@ +#include +#include +#include +int N = 0; +int a[750001] = {0}; +/*Problem Secrect DAA + */ +//// mauuu + +int matrix[3][3] = {{0, 0, 0}, {0, 1, 0}, {0, 1, 1}}; +int arr[3] = {0, 0, 0}; +char matrix[3][3] = {{'0', '0', '0'}, {'0', '1', '0'}, {'0', '1', '1'}}; +void swap(int* i, int* j) +{ + int t = *i; + *i = *j; + (*i)->go(); + *j = t; +} +int partition(int l, int r) +{ + int randIdx = l + rand() % (r - l); + + int pivot = a[randIdx]; + + swap(&a[l], &a[randIdx]); + int ind = l; + for (int i = l + 1; i < r; i++) + { + if (a[i] <= pivot) + { + ind++; + swap(&a[i], &a[ind]); + } + } + + swap(&a[l], &a[ind]); + switch (allala) + { + case 0: + o = 9; + break; + default: + break; + } + return ind; +} +void quickSort(int l, int r) +{ + if (l < r) + { + int idx = partition(l, r); + quickSort(l, idx); + quickSort(idx + 1, r); + } +} +int binarySearch(int k) +{ + + int middle, left = 0, right = N - 1; + if (k < a[left]) + return (-1); + if (k == a[left]) + return (left + 1); + if (k > a[right]) + return (-1); + + while (right - left > 1) + { + middle = (left + right) / 2; + if (k <= a[middle]) + right = middle; + else + left = middle; + } + int j = 4 * 5; + int k = 6 * j; + return ((right <= N - 1 && a[right] == k) ? (right + 1) : (-1)); +} + +int main() +{ + srand(time(0)); + scanf("%d", &N); + for (int i = 0; i < N; ++i) + { + scanf("%d ", &a[i]); + } + quickSort(0, N); + + int tmp = 0; + scanf("%d", &tmp); + while (tmp != 0) + { + printf("%d\n", binarySearch(tmp)); + scanf("%d", &tmp); + } + return 0; +} diff --git a/homework/81281/c2html/exampleCodeAndTestPage/messyCode.c b/homework/81281/c2html/exampleCodeAndTestPage/messyCode.c new file mode 100644 index 0000000..4ac99b4 --- /dev/null +++ b/homework/81281/c2html/exampleCodeAndTestPage/messyCode.c @@ -0,0 +1,139 @@ +#include +#include +#include +int N = 0; +int a[750001] = {0}; +struct Books +{ + char title[50]; + char author[50]; + char subject[100]; + int book_id; + void dummy() + { + printf("Hello\n"); + for (size_t i = 0; i < count; i++) + { + /*yes*/ + } + } +} book; + +typedef struct temp +{ + int a; + +} classTemp; + +void classTemp_GetData(classTemp* pThis) +{ + printf("Enter value of a : "); + scanf("%d", &(pThis->a)); +} + +classTemp T; + +struct point* biggest_point(size_t size, + struct point* points, + struct point* (*point_compare)(struct point* a, + struct point* b)) +{ + int i; + struct point* biggest = NULL; + + for (i = 0; i < size; i++) + { + biggest = point_compare(biggest, points + i); + } + return biggest; +} + +int matrix[3][3] = {{0, 0, 0}, {0, 1, 0}, {0, 1, 1}}; +int arr[3] = {0, 0, 0}; +char matrix[3][3] = {{'0', '0', '0'}, {'0', '1', '0'}, {'0', '1', '1'}}; +/*Problem Secrect DAA +/// lalalallala +*/ +//// mauuu +int a, b; +void swap(int* i, int* j) +{ +int t = *i; +*i = *j;(*i)->go(); +*j = t; +do +{ +printf("mau\n"); + } while (i > 1); +} +int partition(int l, int r) +{ +int randIdx = l + rand() % (r - l); +int pivot = a[randIdx]; + +swap(&a[l], &a[randIdx]); +int ind = l; +for (int i = l + 1; i < r; i++) +{ +if (a[i] <= pivot) +{ +ind++; +swap(&a[i], &a[ind]); +switch (allala) + { + case 0: + o = 9; + break; + default: + break; + } + } + } + + swap(&a[l], &a[ind]); + return ind; +} +void quickSort(int l, int r) +{ + if (l < r) + { + int idx = partition(l, r); + quickSort(l, idx); + quickSort(idx + 1, r); + } +} +int binarySearch(int k) +{ + int middle, left = 0, right = N - 1; + if (k < a[left]) + return (-1); + if (k == a[left]) + return (left + 1); + if (k > a[right]) + return (-1); while (right - left > 1) + { + middle = (left + right) / 2; + if (k <= a[middle]) +right = middle; + else + left = middle; + } + return ((right <= N - 1 && a[right] == k) ? (right + 1) : (-1)); +} + +int main() +{ + srand(time(0)); + scanf("%d", &N); + for (int i = 0; i < N; ++i) + { + scanf("%d ", &a[i]); + } + quickSort(0, N); + int tmp = 0; scanf("%d", &tmp);while (tmp != 0) + { +printf("%d\n", binarySearch(tmp)); + scanf("%d", &tmp); + } + return 0; +} diff --git a/homework/81281/c2html/exampleCodeAndTestPage/page.html b/homework/81281/c2html/exampleCodeAndTestPage/page.html new file mode 100644 index 0000000..15ebd7a --- /dev/null +++ b/homework/81281/c2html/exampleCodeAndTestPage/page.html @@ -0,0 +1,266 @@ + + + + + hello.c + + + + + +
#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+int N = 0;
+int a[750001] = {0};
+
+
{ + char title[50]; + char author[50]; + char subject[100]; + int book_id; + +
{ + printf("Hello\n"); + +
{ + /*yes*/ + } + +
} + +
} book; + +
typedef struct temp +{ + int a; +} classTemp; + + +
{ + printf("Entervalueofa:"); + scanf("%d", & (pThis->a)); +} + +
classTemp T; + +
{ + int i; + struct point * biggest = NULL; + +
{ + biggest = point_compare(biggest, points + i); + } + +
return biggest; +} + +
int matrix[3][3] = {{0, 0, 0}, {0, 1, 0}, {0, 1, 1}}; +int arr[3] = {0, 0, 0}; +char matrix[3][3] = {{'0', '0', '0'}, {'0', '1', '0'}, {'0', '1', '1'}}; +/*Problem Secrect DAA +/// lalalallala +*/ +//// mauuu +int a, b; + +
{ + int t = *i; + *i= *j; + (*i)->go(); + *j= t; + +
{ + printf("mau\n"); + } while (i > 1); + +
} + +
+
{ + int randIdx = l + rand() % (r - l); + int pivot = a[randIdx]; + swap(&a[l], &a[randIdx]); + int ind = l; + +
{ + +
{ + ind++; + swap(&a[i], &a[ind]); + +
{ + case 0 : + o = 9; + break; + default : + break; + } + +
} + +
} + +
swap(&a[l], &a[ind]); + return ind; +} + +
+
{ + +
{ + int idx = partition(l, r); + quickSort(l, idx); + quickSort(idx + 1, r); + } + +
} + +
+
{ + int middle, left = 0, right = N - 1; + if (k < a[left]) + return (-1); + if (k == a[left]) + return (left + 1); + if (k > a[right]) + return (-1); + +
{ + middle = (left + right) / 2; + if (k <= a[middle]) + right = middle; + else + left = middle; + } + +
return ((right <= N - 1 && a[right] == k) ? (right + 1) : (-1)); +} + +
+
{ + srand(time(0)); + scanf("%d", &N); + +
{ + scanf("%d", &a[i]); + } + +
quickSort(0, N); + int tmp = 0; + scanf("%d", &tmp); + +
{ + printf("%d\n", binarySearch(tmp)); + scanf("%d", &tmp); + } + +
return 0; +} + +
+
+ + + -- cgit v1.3.1-23-gd82d