-
Notifications
You must be signed in to change notification settings - Fork 0
/
6502.js
117 lines (112 loc) · 3.68 KB
/
6502.js
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
define(function () {
return {
defaultToken: 'invalid',
brackets: [
['{', '}', 'delimiter.curly'],
['[', ']', 'delimiter.square'],
['(', ')', 'delimiter.parenthesis'],
],
opcodes: [
'LDA', 'LDX', 'LDY',
'STA', 'STX', 'STY',
'TAX', 'TAY', 'TXA', 'TYA', 'TSX',
'ADC', 'SBC', 'SEC', 'CLC',
'INC', 'DEC',
'INY', 'DEY',
'INX', 'DEX',
'CLI', 'SEI',
'CLD', 'SED',
'CMP', 'CPX', 'CPY',
'AND', 'ORA', 'EOR',
'BPL', 'BMI', 'BEQ', 'BNE', 'BRA', 'BCC', 'BCS', 'BVS', 'BVC',
'JMP', 'BRK', 'JSR', 'RTS',
'ROL', 'ROR', 'ASL', 'LSR',
'PHA', 'PHP', 'PLA', 'PLP',
'BIT'
],
directives: [
'ORG',
'CPU',
'SKIP',
'SKIPTO',
'ALIGN',
'COPYBLOCK',
'INCLUDE',
'INCBIN', 'INCBMP',
'EQUB',
'EQUW',
'EQUD',
'EQUS',
'MAPCHAR',
'GUARD',
'CLEAR',
'SAVE',
'PRINT',
'ERROR',
'FOR', 'NEXT',
'IF', 'ELIF', 'ELSE', 'ENDIF',
'PUTFILE',
'PUTBASIC',
'MACRO',
'ENDMACRO'
],
intrinsics: [
'LO', 'HI',
'SIN', 'COS', 'TAN', 'ATN', 'ABS', 'SQR',
'PI', 'FALSE', 'TRUE'
],
operators: [
'#', // immediate
'+', '-', '*', '/', '<<', '>>', '^', '=', '==', '<>', '!=', '<', '>', '<=', '>=',
'{', '}', ':'
],
symbols: /[-+#=><!*\/{}:]+/,
// C# style strings
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
ignoreCase: true,
tokenizer: {
root: [
[/\#\$[0-9a-fA-F]+/, 'number.lit'],
[/\$[0-9a-fA-F]+/, 'number.addr'],
[/&[0-9a-fA-F]+/, 'number.addr'],
// identifiers and keywords
[/[a-zA-Z_$][\w$]*/, {
cases: {
'@directives': 'keyword',
'@opcodes': 'keyword',
'@intrinsics': 'keyword',
'@default': 'identifier'
}
}],
[/,\s*[XY]/, 'keyword'],
// whitespace
{include: '@whitespace'},
// labels
[/\.[a-zA-Z_$][\w$]*/, 'type.identifier'],
// immediate
[/@symbols/, { cases: {'@operators' : 'operator', '@default': ''}}],
// numbers
[/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
[/\d+/, 'number'],
[/[{}()\[\]]/, '@brackets'],
// strings
[/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string
[/"/, { token: 'string.quote', bracket: '@open', next: '@string' } ],
// characters
[/'[^\\']'/, 'string'],
[/(')(@escapes)(')/, ['string','string.escape','string']],
[/'/, 'string.invalid']
],
string: [
[/[^\\"]+/, 'string'],
[/@escapes/, 'string.escape'],
[/\\./, 'string.escape.invalid'],
[/"/, { token: 'string.quote', bracket: '@close', next: '@pop' } ]
],
whitespace: [
[/[ \t\r\n]+/, 'white'],
[/[;\\\\].*/, 'comment']
]
}
};
});