mirror of
https://github.com/Asraelite/littlebigcomputer.git
synced 2025-07-18 00:26:50 +00:00
Init commit
This commit is contained in:
commit
c45ad79440
48 changed files with 6786 additions and 0 deletions
44
assembler/parse.ts
Normal file
44
assembler/parse.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
type Span = {
|
||||
start: [number, number];
|
||||
end: [number, number];
|
||||
text: string;
|
||||
};
|
||||
|
||||
type Context = {
|
||||
|
||||
};
|
||||
|
||||
type Token = {
|
||||
tag: 'opcode' | 'label' | 'string' | 'number' | 'register' | 'comment' | 'whitespace' | 'newline' | ''
|
||||
source: Span
|
||||
};
|
||||
|
||||
type Parser = (s: string, context: Context) => [Array<Token>, string] | null;
|
||||
|
||||
const literal = (stringLiteral) => (s, context) => s.startsWith(stringLiteral) ? [{
|
||||
tag: 'literal',
|
||||
source: {
|
||||
start: context.position,
|
||||
end: [context.position[0], context.position[1] + stringLiteral.length],
|
||||
text: stringLiteral
|
||||
}
|
||||
}, s.slice(stringLiteral.length)] : null;
|
||||
const wordBoundary = (s, context) => s.startsWith(' ') ? [{tag: 'whitespace', source: {start: context.position, end: [context.position[0], context.position[1] + 1], text: ' '}}, s.slice(1)] : null;
|
||||
|
||||
// const add: Parser = (s, context) => {
|
||||
// seq(reg4, reg3, reg).then((d, a, b) => {
|
||||
// return [{
|
||||
// tag: 'aluInstruction',
|
||||
|
||||
// }];
|
||||
// });
|
||||
|
||||
|
||||
// return null;
|
||||
// };
|
||||
|
||||
export function parse(text: string) {
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue