Functional world processors
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user