Anonymous user
Extend your language: Difference between revisions
m
Edited XBS to properly fit the task requirement
(Added XBS language) |
m (Edited XBS to properly fit the task requirement) |
||
Line 3,323:
this.CodeBlock(Stack);
this.JumpBack(Stack);
while(this.CheckNext(Stack,\"Identifier\",\"otherwise\")||this.CheckNext(Stack,\"Identifier\",\"or\")){
this.Next(Stack);▼
if(this.
this.
this.
this.
this.TestNext(Stack,\"Bracket\",\"TK_BOPEN\");
this.CodeBlock(Stack);
this.JumpBack(Stack);
this.CloseChunk(Stack);
break;
}else{
this.OpenChunk(Stack);
this.ChunkWrite(Stack,\"elif\");
this.Move(Stack,2);
this.ChunkWrite(Stack,this.ParseExpression(Stack));
this.TestNext(Stack,\"Bracket\",\"TK_BOPEN\");
this.Move(Stack,2);
this.CodeBlock(Stack);
this.JumpBack(Stack);
this.CloseChunk(Stack);
}
}
this.CloseChunk(Stack);
}"
@Interpret:"function(AST,Token){
Line 3,336 ⟶ 3,354:
this.CondState(AST,Token[4]);
} else {
if(Conds.length<1){return}
this.CondState(AST,Token[5]);▼
let DidCond = false;
let ElseCond = undefined;
for(let v of Conds){
if(DidCond){break}
if(v[0]==\"else\"){
ElseCond=v;
break;
}else if(v[0]==\"elif\"){
let Exp = this.Parse(AST,v[1]);
if(Exp){
DidCond=true;
break;
}
}
}
if(!DidCond&&ElseCond){
this.CondState(AST,ElseCond[1]);
}
}
}"
<#
func
does a == 1 {
log(`Yep! {a} == 1`);
} or a == 2 {
log(`Yes, {a} == 2`);
} otherwise {
log(`Sorry, your number {a} must be greater than 0!`);
} otherwise {
log(`Nope. {a} != 1 or 2`);
}
}
}
equalsOneOrTwo(2);
equalsOneOrTwo(3);
equalsOneOrTwo(0);</lang>
{{out}}
<pre>
Yep! 1 == 1
Nope. 3 != 1 or 2
Sorry, your number 0 must be greater than 0!
</pre>
|