diff options
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
1 files changed, 56 insertions, 0 deletions
| -rw-r--r-- | homework/81281/c2html/controlStructures.pl | 56 |
diff --git a/homework/81281/c2html/controlStructures.pl b/homework/81281/c2html/controlStructures.pl new file mode 100644 index 0000000..026c216 --- /dev/null +++ b/homework/81281/c2html/controlStructures.pl @@ -0,0 +1,56 @@ +:- [essentials, tokens]. +identifyControlStructures([], []):- !. +identifyControlStructures([H|T], [NewH|R]):- + \+ append(_, [[ttypedef|_]|_], H), + append(_, [[Token|_]|_], H), + member(Token, [tdo, tfor, twhile, tif, telse, tswitch, tfunction, tstruct]), + T = [T1|T2], + append(T11, [[tleftBrace, "{"], [execNL, "\n"]], T1), + \+ ((member(M, T11), M \= [execTAB, "\s\s\s\s"])), + gatherBody(T2, [], PackedStructBody, Rest, 1), + identifyControlStructures(PackedStructBody, Result), + append([H, T1], Result, NewH), !, + identifyControlStructures(Rest, R). +identifyControlStructures([H|T], [NewH|R]):- + \+ append(_, [[ttypedef|_]|_], H), + append(_, [[Token|_]|_], H), + member(Token, [tfor, twhile, tif, telse]), + T = [T1|_], + \+ append(_, [[tleftBrace, "{"], [execNL, "\n"]], T1), + getPrefixTabsLength(H, N), + getPrefixTabsLength(T1, M), + N + 1 =:= M, + gatherOneLineBody(T, [], PackedOneLineBody, Rest, N), + identifyControlStructures(PackedOneLineBody, Result), + append([H], Result, NewH), !, + identifyControlStructures(Rest, R). +identifyControlStructures([H|T], [H|R]):- !, + identifyControlStructures(T, R). + + +gatherOneLineBody([], Res, Res, [], _):- !. +gatherOneLineBody([H|T], Res, Res, [H|T], N):- + getPrefixTabsLength(H, M), + N + 1 =\= M, !. +gatherOneLineBody([H|T], Buff, Res, Rest, N):- + getPrefixTabsLength(H, M), + N + 1 =:= M, + append(Buff, [H], NewBuff), !, + gatherOneLineBody(T, NewBuff, Res, Rest, M). + + +gatherBody(Rest, Res, Res, Rest, 0):- !. +gatherBody([H|T], Buff, Res, Rest, N):- + N =\= 0, append(H1, [[tleftBrace, "{"]|_], H), + \+ ((member(M, H1), M \= [execTAB, "\s\s\s\s"])), + append(Buff, [H], NewBuff), N1 is N + 1, !, + gatherBody(T, NewBuff, Res, Rest, N1). +gatherBody([H|T], Buff, Res, Rest, N):- + N =\= 0, append(H1, [[trightBrace, "}"]|_], H), + \+ ((member(M, H1), M \= [execTAB, "\s\s\s\s"])), + append(Buff, [H], NewBuff), N1 is N - 1, !, + gatherBody(T, NewBuff, Res, Rest, N1). +gatherBody([H|T], Buff, Res, Rest, N):- + N =\= 0, + append(Buff, [H], NewBuff), !, + gatherBody(T, NewBuff, Res, Rest, N). |
