Przeglądaj źródła

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 lat temu
rodzic
commit
fc75246fe3
1 zmienionych plików z 25 dodań i 3 usunięć
  1. +25
    -3
      src/assembler/parser.js

+ 25
- 3
src/assembler/parser.js Wyświetl plik

@@ -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 + "'}.");
}

Ładowanie…
Anuluj
Zapisz