|
|
1.1 root 1: //
2: // XM6i
1.1.1.2 ! root 3: // Copyright (C) 2013 Tetsuya Isaki
1.1 root 4: //
5: // 簡易アセンブラ
6: //
7:
8: #ifndef iasm_h
9: #define iasm_h
10:
11: #include <string>
12:
13: #define countof(x) (sizeof(x) / sizeof(x[0]))
14:
15: typedef std::string String;
16:
17: enum token_type_t {
18: T_END,
19: T_SPACE, /* 空白 */
20: T_CHAR, /* 文字 */
21: T_STRING, /* 文字列 */
22: T_NUMBER, /* 数字(16進、10進) */
23: T_LITERAL, /* リテラル(ラベル) */
24: T_SIZE, /* サイズサフィックス */
25: T_SHARP, /* '#' */
26: T_COLON, /* ':' */
27: T_COMMA,
28: T_LPAREN,
29: T_RPAREN,
30: T_PLUS,
31: T_MINUS,
32: T_MULTI,
33: T_DIVIDE,
34: T_LT,
35: T_GT,
36:
37: T_MAX,
38: };
39:
40: class Token
41: {
42: public:
43: token_type_t type; /* 種別 */
44: String word; /* 語 */
45: int number; /* (必要なら) 数値 */
46: public:
47: Token();
48:
49: void clear();
50:
51: const char *type_name() const;
52:
53: static const char *type_name(token_type_t t);
54:
55: static const char *type_str[];
56:
57: };
58:
59: class Scanner
60: {
61: /* 1文字の記号テーブル */
62: struct mark_t {
63: int chr; /* 文字 */
64: token_type_t type; /* トークン種別 */
65: };
66:
67: public:
68: Scanner(String& src);
69:
70: virtual ~Scanner();
71:
72: bool get_token(Token& t);
73:
74: String errmsg;
75:
76: int isSize(int c) const;
77:
78: static bool isLabel1(int c);
79:
80: static bool isLabel2(int c);
81:
82: private:
83: int getch(int offset = 0) const;
84:
85: String buf;
86:
87: int ptr;
88:
89: static mark_t mark[];
90:
91: };
92:
93: #endif /* !iasm_h */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.