1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <conio.h>
#include <malloc.h>
#define MAX_PROG_SIZE 20
#define MAX_PROG_OVERFLOW 40
#define Randint(UPPER) ((int)(random_number()*(UPPER)))
enum tokens {DUMMY, LEFT, RIGHT, MOVE, IF_FOOD_AHEAD, PROGN2, PROGN3, GHOST_NODE};
struct token_entry
{
char *name;
int arity_sub1;
// function
};
struct token_entry token_table [] =
{ {"# ", -1}, // String end. Arity must be -1 for sub-string search
{"LEFT ", -1},
{"RIGHT ", -1},
{"MOVE ", -1},
{"IF_FOOD_AHEAD ", 1},
{"PROGN2 ", 1},
{"PROGN3 ", 2},
{"GHOST_NODE", -1}
};
int main()
{
int editdistance = 0;
int i;
int ar1 = 0;
int ar2 = 0;
int a, b, j, x = 0;
int s1[MAX_PROG_SIZE]={4, 5, 1, 6, 1, 2, 3, 3 };
int s2[MAX_PROG_SIZE]={5, 1, 5, 2, 5, 4, 3, 1, 3};
int c[MAX_PROG_OVERFLOW]={};
int g[1]={7};
for ( i = 0; i < MAX_PROG_SIZE ; i++ )
{
printf("s1 %d and s2 %d\n", s1[a],s2[b]);
if (s1[a] != s2[b])
{
printf("The edit distance is now %d\n", editdistance);
editdistance = editdistance + 1;
printf("The edit distance has increased to %d\n\n", editdistance);
}
else if (s1[a] == s2[b])
{
printf("The edit distance is %d\n\n", editdistance);
}
else if (s1[a] == NULL)
{
ar1 = 0;
}
else if (s1[b] == NULL)
{
ar2 = 0;
}
printf("The edit distance is now %d\n", editdistance);
switch( s1[a] )
{
case LEFT : // LEFT
ar1 = 0;
printf("I have got here, ar1 = %d\n", ar1);
break;
case RIGHT : // RIGHT
ar1 = 0;
printf("I have got here, ar1 = %d\n", ar1);
break;
case MOVE : // MOVE
ar1 = 0;
printf("I have got here, ar1 = %d\n", ar1);
break;
case IF_FOOD_AHEAD : // IF_FOOD_AHEAD
ar1 = 2;
printf("I have got here, ar1 = %d\n", ar1);
break;
case PROGN2 : // PROGN2
ar1 = 2;
printf("I have got here, ar1 = %d\n", ar1);
break;
case PROGN3 : // PROGN3
ar1 = 3;
printf("I have got here, ar1 = %d\n", ar1);
break;
case GHOST_NODE : // GHOST_NODE
ar1 = 0;
printf("I have got here, ar1 = %d\n", ar1);
break;
default :
ar1 = 0;
break;
}
switch( s2[b] )
{
case LEFT : // LEFT
ar2 = 0;
printf("I have got here, ar2 = %d\n", ar2);
break;
case RIGHT : // RIGHT
ar2 = 0;
printf("I have got here, ar2 = %d\n", ar2);
break;
case MOVE : // MOVE
ar2 = 0;
printf("I have got here, ar2 = %d\n", ar2);
break;
case IF_FOOD_AHEAD : // IF_FOOD_AHEAD
ar2 = 2;
printf("I have got here, ar2 = %d\n", ar2);
break;
case PROGN2 : // PROGN2
ar2 = 2;
printf("I have got here, ar2 = %d\n", ar2);
break;
case PROGN3 : // PROGN3
ar2 = 3;
printf("I have got here, ar2 = %d\n", ar2);
break;
case GHOST_NODE : // GHOST_NODE
ar2 = 0;
printf("I have got here, ar2 = %d\n", ar2);
break;
default :
ar2 = 0;
break;
}
if ((ar1 - ar2) > (ar2 - ar1))
{
int k = 0;
memcpy(c[k], s2[b+1], MAX_PROG_SIZE + 1); // This line is the one causing the problems
printf("Memcpy complete s2\n");
}
a++;
b++;
}
getch();
return 0;
}
|