@@ -63,6 +63,18 @@ const CODES = { | |||
var NAMES = Object.keys(CODES); | |||
function ParseIndirectOpCode(parser){ | |||
let t = parser.stream.peek(2); | |||
if (t.type === "punc"){ | |||
if (t.val === ")"){ | |||
return parser.parseDelimited(null, null, ",", parser.parseExpression.bind(parser)) | |||
} else if (t.val === ","){ | |||
return parser.parseDelimited("(", ")", ",", parser.parseExpression.bind(parser)); | |||
} | |||
} | |||
} | |||
module.exports = Object.freeze({ | |||
OPInfo:{ | |||
@@ -106,7 +118,9 @@ module.exports = Object.freeze({ | |||
return { | |||
type: "opcode", | |||
op: val, | |||
args: this.parseDelimited(null, null, ",", this.parseExpression.bind(this)), | |||
args: ((mode === 2) ? | |||
ParseIndirectOpCode(parser) : | |||
this.parseDelimited(null, null, ",", this.parseExpression.bind(this))), | |||
mode: mode, | |||
line: line, | |||
col: col |
@@ -1,4 +1,4 @@ | |||
//const OP = require('./op.js'); | |||
const PRECEDENCE = { | |||
"#": 0, // Precedence 0 should be ignored! | |||
@@ -11,8 +11,9 @@ const PRECEDENCE = { | |||
function TokenStream(input){ | |||
var pos = 0; | |||
function peek(){ | |||
return (pos < input.length) ? input[pos] : null; | |||
function peek(off){ | |||
off = off || 0; | |||
return (pos+off < input.length) ? input[pos+off] : null; | |||
} | |||
function next(){ | |||
@@ -125,13 +126,13 @@ class Parser{ | |||
let a = []; | |||
let first = true; | |||
if (!toEOL){this.skipPunc(s);} | |||
while (!this.stream.eof() && ((!toEOL && this.isPunc(e)) || (toEOL && !this.stream.eol()))){ | |||
while (!this.stream.eof() && ((!toEOL && !this.isPunc(e)) || (toEOL && !this.stream.eol()))){ | |||
if (first){ | |||
first = false; | |||
} else {this.skipPunc(d);} | |||
a.push(parser()); | |||
} | |||
if (!toEOL){skipPunc(e);} | |||
if (!toEOL){this.skipPunc(e);} | |||
return a; | |||
} | |||
@@ -198,7 +199,8 @@ class Parser{ | |||
parseLabel(t){ | |||
if (!this.stream.eof()){ | |||
if (this.stream.peek().type === "opcode"){ | |||
let ct = this.stream.peek(); | |||
if (ct.type === "opcode" && t.col === t.val.length){ | |||
this.__SKIPEOL = true; | |||
return { | |||
type: "assign", |