OSDN Git Service

First Commit
[compforlearners/TuringMachine.git] / turing.h
1 #ifndef TURING_H
2 #define TURING_H
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 #define MAXSTATUS (10)
7 #define MAXTAPE   (1024)
8 #define MAXRULE   (128)
9
10
11 typedef struct turingRule {
12         /* input */
13         char currentStatus[MAXSTATUS];
14         char inputData;  
15         /* output */    
16         char outputData;
17         char movement; 
18         char nextStatus[MAXSTATUS];
19 } turingRule;
20
21 typedef struct turingMachine {
22         char data;
23
24         char status[MAXSTATUS];
25         int  currentPosition;
26
27         int        currentRule;
28         int        maxRule;
29         turingRule rule[MAXRULE];
30 } turingMachine;
31
32 typedef struct turingTape {
33         int     lastPosition;
34         char    tape[MAXTAPE];
35 }turingTape;
36
37
38 /* turingTape.c */
39 int turingTapeRead(FILE* fpt, turingTape* tape);
40 int turingTapePrint(FILE* fpt, turingTape tape);
41
42 /* turingRule.c */
43 int turingRuleRead(FILE* fpt, turingRule rule[]); 
44 int turingRulePrint(FILE* fpt, turingRule rule[], int max); 
45 int turingRulePrint0(FILE* fpt, turingRule rule);
46 /* turingMachine.c */
47 int turingMachineRun(turingMachine* TM, turingTape* tape, FILE* fpt, int mode);
48
49 int turingMachinePrint(turingMachine* TM, turingTape* tape, FILE* fpt, int count, int mode);
50
51 int turingMachineOneStep(turingMachine* TM, turingTape* tape);
52 int turingMachineInput(turingMachine* TM, turingTape tape);
53 int turingMachineRuleSelect(turingMachine* TMP, turingTape* tape);
54 int turingMachineOutput(turingMachine TM, turingTape* tape);
55 int turingMachineMove(turingMachine* m);
56 int turingMachineStatusChange(turingMachine* m);
57 int turingMachineHalt(turingMachine* m);
58 #endif
59