Functional world processors

This commit is contained in:
Anuken
2022-02-08 12:18:48 -05:00
parent e4dd7bf14b
commit 38c0284bbe
21 changed files with 363 additions and 60 deletions

View File

@@ -19,18 +19,13 @@ public class LParser{
Seq<LStatement> statements = new Seq<>();
char[] chars;
int pos, line, tok;
boolean privileged;
LParser(String text){
LParser(String text, boolean privileged){
this.privileged = privileged;
this.chars = text.toCharArray();
}
/** Parses a sequence of statements from a string. */
public static Seq<LStatement> parse(String text){
//don't waste time parsing null/empty text
if(text == null || text.isEmpty()) return new Seq<>();
return new LParser(text).parse();
}
void comment(){
//read until \n or eof
while(pos < chars.length && chars[pos++] != '\n');
@@ -142,6 +137,11 @@ public class LParser{
st = new InvalidStatement();
}
//discard misplaced privileged instructions
if(!privileged && st != null && st.privileged()){
st = new InvalidStatement();
}
//store jumps that use labels
if(st instanceof JumpStatement jump && wasJump){
jumps.add(new JumpIndex(jump, jumpLoc));