瀏覽代碼

Parser now treats ':' punctuations at the beginning of a line as a 'temp label' definition. Temp labels can be referenced by ':<num>' where <num> is the index number (zero-based) of the temp label.

master
Bryan Miller 5 年之前
父節點
當前提交
fc75246fe3
共有 1 個檔案被更改,包括 25 行新增3 行删除
  1. +25
    -3
      src/assembler/parser.js

+ 25
- 3
src/assembler/parser.js 查看文件

@@ -225,6 +225,26 @@ class Parser{
return t;
}

parseTempLabel(){
let isEOL = this.stream.eol();
this.stream.next();
if (isEOL){
this.__SKIPEOL = true;
return {
type:"temp-label",
val:-1, // Value of -1 means "set new temp label"
line:this.stream.line(),
col:this.stream.col()
};
}
let t = this.stream.next();
if (t.type === "number"){
t.type = "temp-label";
return t;
}
this.stream.die("Temp label missing index. New temp labels must be defined at the start of the line.");
}

parseAtom(){
if (this.isPunc("(")){
this.stream.next();
@@ -233,6 +253,8 @@ class Parser{
this.stream.next();
return exp;
}
} else if (this.isPunc(":")){
return this.parseTempLabel();
} else if (this.isOpCode()){
return this.parseOpCode();
} else if (this.isDirective(".if")){
@@ -242,10 +264,10 @@ class Parser{
}

let tok = this.stream.next();
if (tok.type === "number" || tok.type === "string" || tok.type === "label"){
if (tok.type === "label")
return this.parseLabel(tok);
if (tok.type === "number" || tok.type === "string"){
return tok;
} else if (tok.type === "label"){
return this.parseLabel(tok);
}
this.stream.die("Unexpected token {type:" + tok.type + ", val:'" + tok.val + "'}.");
}

Loading…
取消
儲存