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);
if(this.CheckNextOpenChunk(Stack,\"Identifier\",\"otherwise\")){;
while(this.CheckNext(Stack,\"Identifier\",\"otherwise\")||this.CheckNext(Stack,\"Identifier\",\"or\")){
this.Next(Stack);
if(this.TestNextCheckNext(Stack,\"BracketIdentifier\",\"TK_BOPENotherwise\");){
this.MoveOpenChunk(Stack,2);
this.CodeBlockChunkWrite(Stack,\"else\");
this.JumpBackNext(Stack);
this.TestNext(Stack,\"Bracket\",\"TK_BOPEN\");
this.NextMove(Stack,2);
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(let Conds = Token[5]){;
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;
this.CondState(AST,Tokenv[52]);
break;
}
}
}
if(!DidCond&&ElseCond){
this.CondState(AST,ElseCond[1]);
}
}
}"
<#
 
func equalsOneequalsOneOrTwo(a){
does a == 1 {
log(`Yep! {a} == 1`);
} or a == 2 {
log(`Yes, {a} == 2`);
} otherwise {
log(`Nope.does {a} !<= 1`);0 {
log(`Sorry, your number {a} must be greater than 0!`);
} otherwise {
log(`Nope. {a} != 1 or 2`);
}
}
}
 
equalsOneequalsOneOrTwo(1);
equalsOneOrTwo(2);
equalsOne(2);</lang>
equalsOneOrTwo(3);
equalsOneOrTwo(0);</lang>
{{out}}
<pre>
Yep! 1 == 1
Nope.Yes, 2 !== 12
Nope. 3 != 1 or 2
Sorry, your number 0 must be greater than 0!
</pre>
 
Anonymous user