diff --git a/README.md b/README.md index 553c50b..438d4d3 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ POSIXLY_CORRECT=1 awk -f lvtl-x.awk -- [/path/to/your/vtl/program.vtl] - If running without a wrapper and specifying a program to preload, don't forget to put another `-` after it. +See some of the example programs in the [examples](examples/) subdirectory to get some ideas of what can be done with the language. + ## Differences from the Altair original LVTL-X stands out from other LVTL versions by being closer to the original VTL-2, but still has some important differences that shouldn't be ignored: diff --git a/examples/beer.vtl b/examples/beer.vtl new file mode 100644 index 0000000..786c58f --- /dev/null +++ b/examples/beer.vtl @@ -0,0 +1,26 @@ +10 B=99 +20 #=200 +30 ?=" of beer on the wall," +40 #=200 +50 ?=" of beer," +60 ?="Take "; +70 #=B=1*100 +80 ?="one"; +90 #=110 +100 ?="it"; +110 ?=" down and pass it around," +120 B=B-1 +130 #=200 +140 ?=" of beer on the wall!" +150 ?="" +160 #=B=0=0*20 +170 #=999 +200 L=! +210 #=B=0*270 +220 ?=B +230 ?=" bottle"; +240 #=B=1*L +250 ?="s"; +260 #=L +270 ?="No more"; +280 #=!+10 diff --git a/examples/bf.vtl b/examples/bf.vtl new file mode 100644 index 0000000..a777a5d --- /dev/null +++ b/examples/bf.vtl @@ -0,0 +1,72 @@ +10 ?="BF-VTL BY LUXFERRE" +11 ?="CREATED in 2023, PUBLIC DOMAIN" +12 L=*-&) memory limit +13 L=L>30000*30000) hard limit to 30k +15 I=0) start pre-clearing the memory +16 :I)=0 +17 I=I+1 +18 #=I +76 #=C=91*81) 91 [ +77 #=C=35*90) EOC with # +78 #=C=93*81) 93 ] +79 #=C=4*90) EOC with Ctrl+D +80 #=60) skip +81 :P)=C +82 P=P+1 +84 #=60) input next char +90 :P)=65535) set end of code marker +91 ?="" +92 ?="EXEC" +96 M=P+1) set memory start +100 P=0) start execution +110 I=M) reset mem cell index +120 C=:P)) loop start +130 #=C=43*250) call + routine +140 #=C=45*270) call - routine +150 #=C=44*290) call , routine +160 #=C=46*310) call . routine +170 #=C=60*330) call < routine +180 #=C=62*360) call > routine +190 #=:I)=0*(C=91)*400) call [ routine if cell=0 +200 #=1-(:I)=0)*(C=93)*430) call ] routine if cell>0 +210 #=C=65535*240) exit code loop +220 P=P+1) go to the next cmd +230 #=120) process next cmd +240 #=15) return to the start +250 :I)=:I)+1/256*0+%) 8-bit wrap +260 #=! +270 :I)=:I)-1/256*0+%) 8-bit wrap +280 #=! +290 :I)=$) getchar +300 #=! +310 $=:I)) putchar +320 #=! +330 I=I-1) pointer decrement +340 I=IL)*(L-M))) wrap around mem limit +380 #=! +400 D=1) set the direction to find the ] +410 X=93) set the ] code to decrease BL +415 Y=91) set the [ countercode to increase BL +420 #=450) jump to the common part +430 D=65535) set the direction to find the [ +440 X=91) set the [ code to decrease BL +445 Y=93) set the ] countercode to increase BL +450 B=1) starting bracket level +460 R=P) start with current program pointer +470 R=R+D) move along the program tape +480 B=B+(:R)=Y)-(:R)=X)) update the bracket level +490 #=470*(1-(B=0))) proceed while B>0 +500 P=R+1) update the program pointer +510 #=120) restart processing loop diff --git a/examples/bulls.vtl b/examples/bulls.vtl new file mode 100644 index 0000000..ed2006d --- /dev/null +++ b/examples/bulls.vtl @@ -0,0 +1,53 @@ +10 I=1 +20 J=1 +30 :I)='/10*0+% +40 #=:I)=0*30+(0<:I)*70) +50 #=:I)=:J)*20 +60 J=J+1 +70 #=JI*20 +100 ?="BULLS AND COWS" +110 ?="--------------" +120 ?="" +125 T=0 +130 T=T+1 +140 ?="GUESS? "; +150 G=? +160 #=G<1234+(G>9877)*510 +170 I=8 +180 G=G/10 +190 :I)=% +200 I=I-1 +210 #=4J*350 +380 I=I+1 +390 #=4>I*330 +400 ?="BULLS: "; +410 ?=B +420 ?=", COWS: "; +430 ?=C +440 ?="" +450 #=B<4*130 +460 ?="" +470 ?="YOU GOT IT IN "; +480 ?=T +490 ?=" TRIES!" +500 #=1000 +510 ?="BAD GUESS - GUESS NEEDS TO BE 4 UNIQUE DIGITS WITHOUT ZEROES" +520 #=140 diff --git a/examples/dlyat.vtl b/examples/dlyat.vtl new file mode 100644 index 0000000..e643d70 --- /dev/null +++ b/examples/dlyat.vtl @@ -0,0 +1,61 @@ +10 T=0 +20 L=0 +30 ?="DON'T LOSE YOUR 'AT'" +40 X='/9*0+%+1 +50 Y='/9*0+%+1 +60 #=X=Y*40 +70 Z='/9*0+%+1 +80 #=X=Z*40 +90 #=Y=Z*40 +100 ?="I'VE GOT A NUMBER." +105 L=L+1 +110 P=10000 +120 ?="" +130 ?="YOU HAVE "; +140 ?=P/100 +150 ?="."; +160 ?=%/10 +170 ?=% +180 ?=" POINTS LEFT" +190 ?="" +200 ?="WHAT'S YOUR GUESS? -- "; +210 G=? +220 A=G/100 +230 B=%/10 +240 C=% +260 S=600 +270 #=A=Y*S +280 #=A=Z*S +290 #=B=X*S +300 #=B=Z*S +310 #=C=X*S +320 #=C=Y*S +330 K=0 +340 S=620 +350 #=A=X*S +360 #=B=Y*S +370 #=C=Z*S +380 #=K<3*580 +390 ?="" +400 ?="YOU WIN "; +410 ?=P/100 +420 ?="."; +430 ?=%/10 +440 ?=% +450 ?=" POINTS FOR A TOTAL OF "; +460 T=T+P +490 ?=T/100 +500 ?="."; +510 ?=%/10 +520 ?=% +540 ?=" POINTS IN "; +550 ?=L +560 ?=" GAMES." +570 #=30 +580 P=P/20*19 +590 #=120 +600 ?="IT "; +610 #=! +620 ?="AT "; +630 K=K+1 +640 #=! diff --git a/examples/fact.vtl b/examples/fact.vtl new file mode 100644 index 0000000..613ef00 --- /dev/null +++ b/examples/fact.vtl @@ -0,0 +1,37 @@ +10 A=1 +20 L=2 +30 :1)=1 +40 I=2 +50 :I)=0 +60 I=I+1 +70 #=L>I*50 +80 ?="" +90 ?="" +100 ?=A +110 ?="! =" +120 ?="" +130 I=L+1 +140 I=I-1 +150 #=:I)=0*140 +160 ?=:I) +170 I=I-1 +180 #=I=0*220 +190 ?=:I)/10 +200 ?=% +210 #=170 +220 A=A+1 +230 I=1 +240 C=0 +250 X=:I) +260 :I)=A*X +270 #=:I)I*250 +330 #=C=0*80 +340 L=L+1 +350 #=*-&/2Q*300 +120 D=D+2 +130 #=90 +140 ?="EVEN." +150 #=10 +160 ?="" +170 ?=D +180 N=Q +190 Q=N/D +200 #=%=0*220 +210 #=120 +220 ?="^"; +230 P=1 +240 N=Q +250 Q=N/D +260 P=P+1 +270 #=%=0*240 +280 ?=P +290 #=120 +300 #=N=1*340 +310 #=N=X*390 +320 ?="" +330 ?=N +340 ?="" +350 ?="DONE" +370 ?="" +380 #=10 +390 ?="PRIME." +400 ?="" +410 #=340 diff --git a/examples/fizzbuzz.vtl b/examples/fizzbuzz.vtl new file mode 100644 index 0000000..910ad61 --- /dev/null +++ b/examples/fizzbuzz.vtl @@ -0,0 +1,15 @@ +10 N=1 +20 #=30 +30 #=N/3*0+%=0*110 +40 #=N/5*0+%=0*130 +50 #=!+30 +60 ?=N +70 ?="" +80 N=N+1 +90 #=100>N*20 +100 #=999 +110 ?="Fizz"; +120 #=! +130 ?="Buzz"; +140 #=! +180 #=70 diff --git a/examples/hanoi.vtl b/examples/hanoi.vtl new file mode 100644 index 0000000..6db614c --- /dev/null +++ b/examples/hanoi.vtl @@ -0,0 +1,51 @@ +1000 N=4 +1010 F=1 +1020 T=2 +1030 V=3 +1040 S=0 +1050 #=2000 +1060 #=9999 +2000 R=! +2010 #=N<1*2210 +2020 #=4000 +2030 N=N-1 +2040 A=T +2050 T=V +2060 V=A +2070 #=2000 +2080 #=5000 +2090 ?="Move disk from peg: "; +2100 ?=F +2110 ?=" to peg: "; +2120 ?=T +2130 ?="" +2140 #=4000 +2150 N=N-1 +2160 A=F +2170 F=V +2180 V=A +2190 #=2000 +2200 #=5000 +2210 #=R +4000 S=S+1 +4010 :S)=R +4020 S=S+1 +4030 :S)=N +4040 S=S+1 +4050 :S)=F +4060 S=S+1 +4070 :S)=V +4080 S=S+1 +4090 :S)=T +4100 #=! +5000 T=:S) +5010 S=S-1 +5020 V=:S) +5030 S=S-1 +5040 F=:S) +5050 S=S-1 +5060 N=:S) +5070 S=S-1 +5080 R=:S) +5090 S=S-1 +5100 #=! diff --git a/examples/hurkle.vtl b/examples/hurkle.vtl new file mode 100644 index 0000000..3597f48 --- /dev/null +++ b/examples/hurkle.vtl @@ -0,0 +1,48 @@ +100 ?="" +110 ?="A HURKLE IS HIDING ON A" +120 ?="10 BY 10 GRID. HOMEBASE" +130 ?="ON THE GRID IS POINT 00" +140 ?="AND A GRIDPOINT IS ANY" +150 ?="PAIR OF WHOLE NUMBERS" +160 ?="TRY TO GUESS THE HURKLE'S" +170 ?="GRIDPOINT. YOU GET 5 GUESSES" +180 ?="" +190 R='/100*0+% +200 A=R/10 +210 B=% +220 K=1 +230 ?="GUESS #"; +240 ?=K +250 ?=" ?"; +260 X=?/10 +270 Y=% +280 ?="" +290 #=X*10+Y=R*540 +300 K=K+1 +310 #=K=6*440 +320 ?="GO "; +330 #=Y=B*370+(YN*20 +50 A=0 +60 B=A +70 C=B +80 :C+1)=160 +90 C=C+20 +100 #=100>C*80 +110 B=B+9 +120 #=100>B*70 +130 A=A+6 +140 #=100>A*60 +150 N=101 +160 N=N-1 +170 #=:N+1) +180 ?="Largest non-McNuggets number: "; +190 ?=N diff --git a/examples/memtest.vtl b/examples/memtest.vtl new file mode 100644 index 0000000..8febd2b --- /dev/null +++ b/examples/memtest.vtl @@ -0,0 +1,55 @@ +10 A=0 +20 ?="MEMORY SIZE? "; +30 B=? +40 A=A+257 +50 C=A +60 I=0 +70 I=I+1 +80 :I)=C +90 C=C+769 +95 ?=""; +100 #=I*2+&