Browse Source

More 6502 assembly parser work.

master
Bryan Miller 5 years ago
parent
commit
aa79ab6340
1 changed files with 62 additions and 1 deletions
  1. +62
    -1
      src/MOS/6502/assembler/parser.js

+ 62
- 1
src/MOS/6502/assembler/parser.js View File

return (pos < input.length) ? input[pos].col : -1; return (pos < input.length) ? input[pos].col : -1;
} }


function eol(){
return (pos < input.length - 1) ? (input[pos].line !== input[pos+1].line) : true;
}

function eof(){ function eof(){
return (pos >= input.length); return (pos >= input.length);
} }
} }


function isPunc(ch){ function isPunc(ch){
return isTokenType("punk", ch);
return isTokenType("punc", ch);
} }


function isOpCode(ch){ function isOpCode(ch){
} }




function skipPunc(ch){
if (isPunc(ch)){
stream.next();
} else {
stream.die("Unexpected punctuation '" + ch + "'.");
}
}


parseDelimited(s,e,d,parser){
let toEOL = (s === null || e === null);
let a = [];
let first = true;
if (!toEOL){skipPunc(s);}
while (!stream.eof() && ((!toEOL && isPunc(e)) || (toEOL && !stream.eol()))){
if (first){
first = false;
} else {skipPunk(d);}
a.push(parser());
}
if (!toEOL){skipPunc(e);}
return a;
}


parseOpCode(){
let val = stream.next();
let mode = 0; // Guess between absolute and zero page.
let args = []; // TODO: Finish figuring out how to get the argument list!
if (isOp("#")){
stream.next();
mode = 1; // Immediate
} else if (isPunc("(")){
mode = 2; // Indirect
// TODO: Use parseDelimited()
}
return {
type: "opcode",
val: val,
args: args,
mode: mode
};
}

parseAtom(){
if (isPunc("(")){
stream.next();
let exp = parseExpression();
if (isPunc(")")){
stream.next();
return exp;
}
} else if (isOpCode()){
return parseOpCode();
}
}



parse(tokens){ parse(tokens){
let p = { let p = {

Loading…
Cancel
Save