-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC_STATE.h
61 lines (53 loc) · 1.48 KB
/
C_STATE.h
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
/**
* Drew Rife and Brad Olah
*
* Holds transition table for the state machine
*/
#ifndef C_STATE_H
#define C_STATE_H
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int StartState();
int IntegerState();
int DecimalState();
int EndState();
int (* state[])(void) = {StartState, IntegerState, DecimalState, EndState};
enum states {start, integer, decimal, end};
enum inputType {isNegSign,isPosSign, isDigit, isPoint, isTerminator, isInvalid};
struct transition{
enum states thisState;
enum inputType action;
enum states nextState;
};
enum inputType GetInputType(char input); // what the user enters
/**
* transition table
*/
static const struct transition change_state[] = {
{start, isPosSign, integer},
{start, isNegSign, integer},
{start, isDigit, integer},
{start, isPoint, decimal},
{start, isTerminator, end},
{start, isInvalid, end},
{integer, isPosSign, end},
{integer, isNegSign, end},
{integer, isDigit, integer},
{integer, isPoint, decimal},
{integer, isTerminator, end},
{integer, isInvalid, end},
{decimal, isPosSign, end},
{decimal, isNegSign, end},
{decimal, isDigit, decimal},
{decimal, isPoint, end},
{decimal, isTerminator, end},
{decimal, isInvalid, end}
};
int sign; // the sign of the input
double value; // the calculated result from input
double point; // determines whether there is a decimal or not
char character; // the input character
enum states currentState; // the current state of the machine is in
#endif // C_STATE_H