| var NAMES = Object.keys(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({ | module.exports = Object.freeze({ | ||||
| OPInfo:{ | OPInfo:{ | ||||
| return { | return { | ||||
| type: "opcode", | type: "opcode", | ||||
| op: val, | 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, | mode: mode, | ||||
| line: line, | line: line, | ||||
| col: col | col: col |
| //const OP = require('./op.js'); | |||||
| const PRECEDENCE = { | const PRECEDENCE = { | ||||
| "#": 0, // Precedence 0 should be ignored! | "#": 0, // Precedence 0 should be ignored! | ||||
| function TokenStream(input){ | function TokenStream(input){ | ||||
| var pos = 0; | 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(){ | function next(){ | ||||
| let a = []; | let a = []; | ||||
| let first = true; | let first = true; | ||||
| if (!toEOL){this.skipPunc(s);} | 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){ | if (first){ | ||||
| first = false; | first = false; | ||||
| } else {this.skipPunc(d);} | } else {this.skipPunc(d);} | ||||
| a.push(parser()); | a.push(parser()); | ||||
| } | } | ||||
| if (!toEOL){skipPunc(e);} | |||||
| if (!toEOL){this.skipPunc(e);} | |||||
| return a; | return a; | ||||
| } | } | ||||
| parseLabel(t){ | parseLabel(t){ | ||||
| if (!this.stream.eof()){ | 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; | this.__SKIPEOL = true; | ||||
| return { | return { | ||||
| type: "assign", | type: "assign", |