This commit is contained in:
Mariusz Pacek committed 2013-04-18 01:34:42 +02:00
1 parent 23f5f2e59a
commit d7257cfb96
7 files changed
+502

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
/*
* File: Generator.h
* Author: mar
*
* Created on 17 kwiecień 2013, 19:52
*/
#ifndef GENERATOR_H
#define GENERATOR_H
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
char* header();
struct Token getToken();
char* bottom();
char* convertTokenToHtml(struct Token *token,char **colorTable);
void converToHtml(char *path,char **colorTable);
void appendTofile(char *string,FILE *file);
FILE *createFile(char *name);
#endif /* GENERATOR_H */
+38
View File
@@ -0,0 +1,38 @@
#ifndef SCANNER
#define SCANNER
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
typedef enum {
ident,number,lparen,rparne,times,slash,plus,minus,eql,neq,lss,leq,
geq,gtr,callsym,beginsym,semicolon,ednsym,ifsym,whilesym,becomes,thensym,
dosym,constsym,comma,varsym,procsym,period,oddsym,eof,error,whitespace
} TokenType;
struct Token {
TokenType type;
char buffer[1024];
int line;
int column;
};
struct File {
int line;
int column;
int maxlenght;
int currentPosition;
char *file;
};
bool isDigit(char sign);
bool isLetter(char sign);
bool isDigitOrLetter(char sign);
void fillToken(struct Token *token,int line,int column,TokenType type);
void setBuffer(struct Token *token,int size);
char getChar(struct File *file);
char whatIsNextChar(struct File* file);
struct File init(char* path);
struct Token scan(struct File *file);
#endif
+61
View File
@@ -0,0 +1,61 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><html><head><rel="stylesheet" type="text/css" href="css/main.css" /><meta http-equiv="content-type" content="text/php; charset=utf-8" /><title>PL0 syntax highlight </title></head><body bgcolor=#C9C7F0><pre ><font color=#40a430>CONST</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>m</font><font color=#000000> </font><font color=#00ff00>=</font><font color=#000000> </font><font color=#000000> </font><font color=#bbaaff>7</font><font color=#000000>,</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>n</font><font color=#000000> </font><font color=#00ff00>=</font><font color=#000000> </font><font color=#bbaaff>85</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000>
</font><font color=#505450>VAR</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>x</font><font color=#000000>,</font><font color=#000000> </font><font color=#2341ff>y</font><font color=#000000>,</font><font color=#000000> </font><font color=#2341ff>z</font><font color=#000000>,</font><font color=#000000> </font><font color=#2341ff>q</font><font color=#000000>,</font><font color=#000000> </font><font color=#2341ff>r</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000>
</font><font color=#502050>PROCEDURE</font><font color=#000000> </font><font color=#2341ff>multiply</font><font color=#000000>;</font><font color=#000000>
</font><font color=#505450>VAR</font><font color=#000000> </font><font color=#2341ff>a</font><font color=#000000>,</font><font color=#000000> </font><font color=#2341ff>b</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000>
</font><font color=#734699>BEGIN</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>a</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>x</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>b</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>y</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>z</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#bbaaff>0</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#537324>WHILE</font><font color=#000000> </font><font color=#2341ff>b</font><font color=#000000> </font><font color=#00ff00>></font><font color=#000000> </font><font color=#bbaaff>0</font><font color=#000000> </font><font color=#537324>DO</font><font color=#000000> </font><font color=#734699>BEGIN</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#9F2323>IF</font><font color=#000000> </font><font color=#f020f0>ODD</font><font color=#000000> </font><font color=#2341ff>b</font><font color=#000000> </font><font color=#9F2323>THEN</font><font color=#000000> </font><font color=#2341ff>z</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>z</font><font color=#000000> </font><font color=#00ff00>+</font><font color=#000000> </font><font color=#2341ff>a</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>a</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#bbaaff>2</font><font color=#000000> </font><font color=#00ff00>*</font><font color=#000000> </font><font color=#2341ff>a</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>b</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>b</font><font color=#000000> </font><font color=#00ff00>/</font><font color=#000000> </font><font color=#bbaaff>2</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>END</font><font color=#000000>
</font><font color=#2341ff>END</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000>
</font><font color=#502050>PROCEDURE</font><font color=#000000> </font><font color=#2341ff>divide</font><font color=#000000>;</font><font color=#000000>
</font><font color=#505450>VAR</font><font color=#000000> </font><font color=#2341ff>w</font><font color=#000000>;</font><font color=#000000>
</font><font color=#734699>BEGIN</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>r</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>x</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>q</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#bbaaff>0</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>w</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>y</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#537324>WHILE</font><font color=#000000> </font><font color=#2341ff>w</font><font color=#000000> </font><font color=#00ff00><=</font><font color=#000000> </font><font color=#2341ff>r</font><font color=#000000> </font><font color=#537324>DO</font><font color=#000000> </font><font color=#2341ff>w</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#bbaaff>2</font><font color=#000000> </font><font color=#00ff00>*</font><font color=#000000> </font><font color=#2341ff>w</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#537324>WHILE</font><font color=#000000> </font><font color=#2341ff>w</font><font color=#000000> </font><font color=#00ff00>></font><font color=#000000> </font><font color=#2341ff>y</font><font color=#000000> </font><font color=#537324>DO</font><font color=#000000> </font><font color=#734699>BEGIN</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>q</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#bbaaff>2</font><font color=#000000> </font><font color=#00ff00>*</font><font color=#000000> </font><font color=#2341ff>q</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>w</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>w</font><font color=#000000> </font><font color=#00ff00>/</font><font color=#000000> </font><font color=#bbaaff>2</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#9F2323>IF</font><font color=#000000> </font><font color=#2341ff>w</font><font color=#000000> </font><font color=#00ff00><=</font><font color=#000000> </font><font color=#2341ff>r</font><font color=#000000> </font><font color=#9F2323>THEN</font><font color=#000000> </font><font color=#734699>BEGIN</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>r</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>r</font><font color=#000000> </font><font color=#00ff00>-</font><font color=#000000> </font><font color=#2341ff>w</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>q</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>q</font><font color=#000000> </font><font color=#00ff00>+</font><font color=#000000> </font><font color=#bbaaff>1</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>END</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>END</font><font color=#000000>
</font><font color=#2341ff>END</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000>
</font><font color=#502050>PROCEDURE</font><font color=#000000> </font><font color=#2341ff>gcd</font><font color=#000000>;</font><font color=#000000>
</font><font color=#505450>VAR</font><font color=#000000> </font><font color=#2341ff>f</font><font color=#000000>,</font><font color=#000000> </font><font color=#2341ff>g</font><font color=#000000>;</font><font color=#000000>
</font><font color=#734699>BEGIN</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>f</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>x</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>g</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>y</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#537324>WHILE</font><font color=#000000> </font><font color=#2341ff>f</font><font color=#000000> </font><font color=#000000></font><font color=#000000> </font><font color=#2341ff>g</font><font color=#000000> </font><font color=#537324>DO</font><font color=#000000> </font><font color=#734699>BEGIN</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#9F2323>IF</font><font color=#000000> </font><font color=#2341ff>f</font><font color=#000000> </font><font color=#00ff00><</font><font color=#000000> </font><font color=#2341ff>g</font><font color=#000000> </font><font color=#9F2323>THEN</font><font color=#000000> </font><font color=#2341ff>g</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>g</font><font color=#000000> </font><font color=#00ff00>-</font><font color=#000000> </font><font color=#2341ff>f</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#000000> </font><font color=#9F2323>IF</font><font color=#000000> </font><font color=#2341ff>g</font><font color=#000000> </font><font color=#00ff00><</font><font color=#000000> </font><font color=#2341ff>f</font><font color=#000000> </font><font color=#9F2323>THEN</font><font color=#000000> </font><font color=#2341ff>f</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>f</font><font color=#000000> </font><font color=#00ff00>-</font><font color=#000000> </font><font color=#2341ff>g</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>END</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>z</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>f</font><font color=#000000>
</font><font color=#2341ff>END</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000>
</font><font color=#734699>BEGIN</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>x</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>m</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>y</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#2341ff>n</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>CALL</font><font color=#000000> </font><font color=#2341ff>multiply</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>x</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#bbaaff>25</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>y</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#000000> </font><font color=#bbaaff>3</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>CALL</font><font color=#000000> </font><font color=#2341ff>divide</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>x</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#bbaaff>84</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>y</font><font color=#000000> </font><font color=#ff0000>:=</font><font color=#000000> </font><font color=#bbaaff>36</font><font color=#000000>;</font><font color=#000000>
</font><font color=#000000> </font><font color=#000000> </font><font color=#2341ff>CALL</font><font color=#000000> </font><font color=#2341ff>gcd</font><font color=#000000>
</font><font color=#2341ff>END</font><font color=#000000>.</font><font color=#000000></font></pre</body><footer><div class="Footer"><b>Copyright - 2013</b></div></footer></html>
+59
View File
@@ -0,0 +1,59 @@
#include <fcntl.h>
#include "Scanner.h"
#include "Generator.h"
#include <stdlib.h>
char* bottom(){
return "</pre</body><footer><div class=\"Footer\"><b>Copyright - 2013</b></div></footer></html>";
}
char* header(){
return "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css\" /><meta http-equiv=\"content-type\" content=\"text/php; charset=utf-8\" /><title>PL0 syntax highlight </title></head><body bgcolor=#C9C7F0><pre >";
}
char* convertTokenToHtml(struct Token* token,char **colorTable){
char *buffer =(char*)malloc(sizeof(char)*2048);
if(buffer == NULL){
perror("problem with malloc:");
exit(EXIT_FAILURE);
}
memset(buffer,'\0',2048);
strcat(buffer,"<font color=#");
strcat(buffer,colorTable[token->type]);
strcat(buffer,">");
strcat(buffer,token->buffer),
strcat(buffer,"</font>");
return buffer;
}
void converToHtml(char *path,char **colorTable)
{
struct File file=init(path);
struct Token token;
FILE *f = createFile("./output.html");
appendTofile(header(),f);
while(token.type != eof){
token = scan(&file);
printf("%s",token.buffer);
appendTofile(convertTokenToHtml(&token,colorTable),f);
}
appendTofile(bottom(),f);
fclose(f);
}
void appendTofile(char* string,FILE *file){
fwrite(string,sizeof(char),strlen(string),file);
//free(string);
}
FILE* createFile(char* name)
{
FILE *f = fopen(name,"w+");
if(f==NULL){
perror("Problem with creation of file");
exit(EXIT_FAILURE);
}
return f;
}
+240
View File
@@ -0,0 +1,240 @@
#include <fcntl.h>
#include <X11/Xlib.h>
#include "Scanner.h"
#include "errno.h"
#include "stdlib.h"
#include <ctype.h>
//wczytywanie pliku do pamieci, calego!
struct File init(char* path) {
long fd;
char *file;
FILE *f;
size_t nbytes;
f = fopen(path, "rb");
if (f == NULL) {
perror("cannot open specific file");
exit(EXIT_FAILURE);
}
fseek(f, 0, SEEK_END);
fd = ftell(f);
rewind(f);
file = (char*) malloc(sizeof (char)*fd);
if (file == NULL) {
perror("Blod malloc");
exit(EXIT_FAILURE);
}
if (f == NULL) {
perror("cannot open specific file");
exit(EXIT_FAILURE);
}
nbytes = fread(file, 1, fd, f);
if (nbytes != fd) {
perror("problem with read file");
exit(EXIT_FAILURE);
}
fclose(f);
struct File line = {0, 0, fd, 0, file};
return line;
}
bool isDigit(char sign) {
return sign >= '0' && sign <= '9';
}
bool isLetter(char sign) {
return sign >= 'A' && sign <= 'Z' || sign >= 'a' && sign <= 'z';
}
bool isDigitOrLetter(char sign) {
return isDigit(sign) || isLetter(sign);
}
void fillToken(struct Token *token, int line, int column, TokenType type) {
token->line = line;
token->column = column;
token->type = type;
}
char getChar(struct File *line) {
if (line->file != NULL) {
char a = line->file[line->currentPosition];
line->currentPosition++;
line->column++;
return a;
}
return 0;
}
char whatIsNextChar(struct File *file) {
if (file->file != NULL) {
return file->file[file->currentPosition];
}
return 0;
}
int typeOfIdent(char *ide) {
int i = 0;
char tmp[100] = "";
while (ide[i] != '\0') {
tmp[i] = (char) tolower((int) ide[i]);
i++;
}
if (!strcmp(tmp, "var")) {
return varsym;
} else
if (!strcmp(tmp, "while")) {
return whilesym;
} else
if (!strcmp(tmp, "do")) {
return dosym;
} else
if (!strcmp(tmp, "call")) {
return callsym;
} else
if (!strcmp(tmp, "begin")) {
return beginsym;
} else
if (!strcmp(tmp, "if")) {
return ifsym;
} else
if (!strcmp(tmp, "then")) {
return thensym;
} else
if (!strcmp(tmp, "const")) {
return constsym;
} else
if (!strcmp(tmp, "procedure")) {
return procsym;
} else
if (!strcmp(tmp, "odd")) {
return oddsym;
} else
return ident;
}
struct Token scan(struct File *file) {
char sign = getChar(file);
struct Token __token;
int line = file->line;
int column = file->column;
memset(&__token.buffer, 0, 1024);
switch (sign) {
case 0: fillToken(&__token, line, column, eof);
return __token; // end of program!
case '\n':
line++;
column = 0;
fillToken(&__token, line, column, whitespace);
strcat(__token.buffer, "\n");
return __token;
case 9:
fillToken(&__token, line, column, whitespace);
strcat(__token.buffer, " ");
return __token;
case 32:
fillToken(&__token, line, column, whitespace);
strcat(__token.buffer, " ");
return __token;
case 13:
fillToken(&__token, line, column, whitespace);
strcat(__token.buffer, (char) 13);
return __token;
case '=': fillToken(&__token, line, column, eql);
strcat(__token.buffer, "=");
return __token;
case '+': fillToken(&__token, line, column, plus);
strcat(__token.buffer, "+");
return __token;
case '-': fillToken(&__token, line, column, minus);
strcat(__token.buffer, "-");
return __token;
case '>': if (whatIsNextChar(file) == '=') {
sign = getChar(file);
fillToken(&__token, line, column, geq);
strcat(__token.buffer, ">=");
} else
fillToken(&__token, line, column, gtr);
strcat(__token.buffer, ">");
return __token;
case '<':
switch (whatIsNextChar(file)) {
case '=':
sign = getChar(file);
fillToken(&__token, line, column, leq);
strcat(__token.buffer, "<=");
break;
case '>':
sign = getChar(file);
fillToken(&__token, line, column, neq);
strcat(__token.buffer, "<>");
break;
default:
fillToken(&__token, line, column, lss);
strcat(__token.buffer, "<");
}
return __token;
case ':': switch (whatIsNextChar(file)) {
case '=': fillToken(&__token, line, column, becomes);
strcat(__token.buffer, ":=");
getChar(file);
break;
default: sign = getChar(file);
fillToken(&__token, line, column, error);
strcat(__token.buffer, ":");
}
return __token;
case '.': fillToken(&__token, line, column, period);
strcat(__token.buffer, ".");
return __token;
case '*': fillToken(&__token, line, column, times);
strcat(__token.buffer, "*");
return __token;
case '/': fillToken(&__token, line, column, slash);
strcat(__token.buffer, "/");
return __token;
case ';': fillToken(&__token, line, column, semicolon);
strcat(__token.buffer, ";");
return __token;
case ',': fillToken(&__token, line, column, comma);
strcat(__token.buffer, ",");
return __token;
default:
if (isDigit(sign)) {
fillToken(&__token, line, column, number);
while (isDigit(sign)) {
__token.buffer[strlen(__token.buffer)] = sign;
__token.buffer[strlen(__token.buffer) + 1] = '\0';
sign = getChar(file);
}
file->currentPosition--;
} else
if (isLetter(sign)) {
fillToken(&__token, line, column, ident);
while (isDigitOrLetter(sign)) {
__token.buffer[strlen(__token.buffer)] = sign;
__token.buffer[strlen(__token.buffer) + 1] = '\0';
sign = getChar(file);
}
file->currentPosition--;
__token.type = typeOfIdent(__token.buffer);
}
return __token;
}
}
+19
View File
@@ -0,0 +1,19 @@
#include <fcntl.h>
#include "Generator.h"
#include "errno.h"
#include "stdlib.h"
#include <stdio.h>
char *colorTable[32] ={"2341ff","bbaaff","000000","000000","00ff00","00ff00",
"00ff00","00ff00","00ff00","00ff00","00ff00","00ff00",
"00ff00","00ff00","2341ff","734699","000000","734699",
"9F2323","537324","ff0000","9F2323","537324","40a430",
"000000","505450","502050","000000","f020f0","000000",
"000000","000000"};
int main(){
converToHtml("./test.txt",colorTable);
return 0;
}
+61
View File
@@ -0,0 +1,61 @@
CONST
m = 7,
n = 85;
VAR
x, y, z, q, r;
PROCEDURE multiply;
VAR a, b;
BEGIN
a := x;
b := y;
z := 0;
WHILE b > 0 DO BEGIN
IF ODD b THEN z := z + a;
a := 2 * a;
b := b / 2
END
END;
PROCEDURE divide;
VAR w;
BEGIN
r := x;
q := 0;
w := y;
WHILE w <= r DO w := 2 * w;
WHILE w > y DO BEGIN
q := 2 * q;
w := w / 2;
IF w <= r THEN BEGIN
r := r - w;
q := q + 1
END
END
END;
PROCEDURE gcd;
VAR f, g;
BEGIN
f := x;
g := y;
WHILE f # g DO BEGIN
IF f < g THEN g := g - f;
IF g < f THEN f := f - g
END;
z := f
END;
BEGIN
x := m;
y := n;
CALL multiply;
x := 25;
y := 3;
CALL divide;
x := 84;
y := 36;
CALL gcd
END.