-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler.h
76 lines (64 loc) · 1.54 KB
/
compiler.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* compiler.h
*
* (c) Copyright 2010, P. Jakubco
*/
#ifndef __COMPILER__
#define __COMPILER__
#include <stdio.h>
/* Symbols used by lexical analyzer */
#define TEXT 1
#define LABELTEXT 2
#define NUMBER 4
#define HALT 8
#define READ 16
#define WRITE 32
#define LOAD 64
#define STORE 128
#define ADD 256
#define SUB 512
#define MUL 1024
#define DIV 2048
#define JMP 4096
#define JGTZ 8192
#define JZ 16384
#define ASTERISK 32768
#define EQUAL 65536
#define COLON 131072
#define COMMENT 262144
#define END 524288
/* FIRST sets */
#define F_Instruction (HALT|READ|WRITE|LOAD|STORE|ADD|SUB|MUL|DIV|JMP|JGTZ|JZ)
#define F_Label LABELTEXT
#define F_Row (F_Label|F_Instruction)
#define F_Start F_Row
/* FOLLOW sets */
#define FO_Start END
#define FO_Row (F_Start|FO_Start)
#define FO_Label F_Instruction
#define FO_Instruction FO_Row
/* Error constants */
#define COMPILER_OK 0
#define COMPILER_ERROR 1
/* Compiler code generator codes */
#define C_HALT 0
#define C_READ 1
#define C_WRITE 4
#define C_LOAD 7
#define C_STORE 9
#define C_ADD 12
#define C_SUB 15
#define C_MUL 18
#define C_DIV 21
#define C_JMP 23
#define C_JGTZ 24
#define C_JZ 25
typedef unsigned long SET;
#ifdef __cplusplus
extern "C" {
#endif
int compile(const char *input, const char* output);
#ifdef __cplusplus
}
#endif
#endif