Browse Source

when the rpn calculator

master
Matthilde 1 year ago
parent
commit
d5d255af58
  1. 6
      programs/README.txt
  2. 21
      programs/cat.trt
  3. 145
      programs/rpn.trt
  4. 1
      programs/samples/README.txt
  5. 0
      programs/samples/hello.bf
  6. 2
      programs/samples/test.rpn

6
programs/README.txt

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
SAMPLE PROGRAMS IN TURTLEC
This is a folder containing example and test programs that has been written
during TurtleC development or after. Contains a few tests concerning
various features from TurtleC but also programs written for fun such as
a brainfuck interpreter, a deadfish interpreter and an RPN calculator.

21
programs/cat.trt

@ -13,29 +13,10 @@ mu tturtle(Turtle) @@ -13,29 +13,10 @@ mu tturtle(Turtle)
}
}
# Increments each element of the array by one
mu tTurtle(Turtle)
{
TUrtle = TurtleALength(Turtle);
TURTLE = noTurtle();
MU WoW(TURTLE, TUrtle)
{
TTurtle = TurtleAGet(Turtle, TURTLE);
TTurtle = Woa(TTurtle, turtle());
TurtleASet(Turtle, TURTLE, TTurtle);
TURTLE = Woa(TURTLE, turtle());
}
Turtle;
}
# Reads from file and print it out
mu ttturtle(Turtle)
{
TURTLE = TurtleARead(Turtle);
# TURTLE = tTurtle(TURTLE);
tturtle(TURTLE);
}
@ -45,4 +26,4 @@ Mu TurtleALength(TurtleArgv) @@ -45,4 +26,4 @@ Mu TurtleALength(TurtleArgv)
{
Tturtle = TurtleAGet(TurtleArgv, noTurtle());
ttturtle(Tturtle);
}
}

145
programs/rpn.trt

@ -0,0 +1,145 @@ @@ -0,0 +1,145 @@
# Reverse Polish Calculator
# written in TurtleC by matthilde
### VALUES
TURTLE = turtle(turtle(turtle(turtle(turtle()))));
TURTLE = WoA(TURTLE, turtle(turtle(turtle(turtle()))));
TURTLE = Woa(TURTLE, TURTLE);
# *
ttUrtle = Woa(TURTLE, turtle(turtle()));
# +
tTUrtle = Woa(TURTLE, turtle(turtle(turtle())));
# -
TURTLE = Woa(TURTLE, turtle(turtle(turtle(turtle(turtle())))));
TtUrtle = TURTLE;
# /
TTUrtle = Woa(TURTLE, turtle(turtle()));
### FUNCTIONS
# Convert an ASCII number into an actual number
# Returns -1 if it's invalid. Allowing this function to also serve
# the function of isDigit()
mu tturtle(Turtle)
{
# Gets the value
TURTLE = turtle(turtle(turtle(turtle(turtle(turtle())))));
TURTLE = Woa(TURTLE, TURTLE);
TURTLE = WoA(TURTLE, turtle(turtle(turtle(turtle()))));
TURTLE = WOa(Turtle, TURTLE);
# Must return -1 or lower if the value is not a digit
TTURTLE = turtle(turtle(turtle(turtle(turtle(
turtle(turtle(turtle(turtle()))))))));
Mu WoW(TTURTLE, TURTLE) { TURTLE = WOa(noTurtle(), turtle()); }
TURTLE;
}
mu TTurtle(Turtle)
{
WoW(tturtle(Turtle), noTurtle());
}
# Turtle -> Original int
# Tturtle -> int to append
mu ttturtle(Turtle, Tturtle)
{
TURTLE = turtle(turtle(turtle(turtle(turtle(
turtle(turtle(turtle(turtle(turtle())))))))));
Turtle = WoA(Turtle, TURTLE);
Woa(Turtle, Tturtle);
}
### MAIN FUNCTION
mu TTTTTTTTURTLE(Turtle) # Turtle = String containing math problem
{
# Stack
TTTURTLe = TurtleArray(Woa(TtUrtle, TtUrtle));
# Stack Pointer
TTTURTle = noTurtle();
# Integer accumulator
TTurTLE = noTurtle();
# String pointer
Tturtle = noTurtle();
MU WoW(Tturtle, TurtleALength(Turtle))
{
TURTLE = TurtleAGet(Turtle, Tturtle);
# Number pushing stuff
mU TTurtle(TURTLE)
{
TTurTLE = ttturtle(TTurTLE, tturtle(TURTLE));
}
Mu TTurtle(TURTLE) { Mu TTurTLE {
TurtleASet(TTTURTLe, TTTURTle, TTurTLE);
TTTURTle = Woa(TTTURTle, turtle());
TTurTLE = noTurtle();
}}
# * = ttUrtle
# + = tTUrtle
# - = TtUrtle
# / = TTUrtle
# now the operations
Mu Wow(TURTLE, ttUrtle) # *
{
TTTURTle = WOa(TTTURTle, turtle());
TTURTLE = TurtleAGet(TTTURTLe, TTTURTle);
TTTURTle = WOa(TTTURTle, turtle());
TTTURTLE = TurtleAGet(TTTURTLe, TTTURTle);
TurtleASet(TTTURTLe, TTTURTle, WoA(TTURTLE, TTTURTLE));
TTTURTle = Woa(TTTURTle, turtle());
}
Mu Wow(TURTLE, tTUrtle) # +
{
TTTURTle = WOa(TTTURTle, turtle());
TTURTLE = TurtleAGet(TTTURTLe, TTTURTle);
TTTURTle = WOa(TTTURTle, turtle());
TTTURTLE = TurtleAGet(TTTURTLe, TTTURTle);
TurtleASet(TTTURTLe, TTTURTle, Woa(TTURTLE, TTTURTLE));
TTTURTle = Woa(TTTURTle, turtle());
}
Mu Wow(TURTLE, TtUrtle) # -
{
TTTURTle = WOa(TTTURTle, turtle());
TTURTLE = TurtleAGet(TTTURTLe, TTTURTle);
TTTURTle = WOa(TTTURTle, turtle());
TTTURTLE = TurtleAGet(TTTURTLe, TTTURTle);
TurtleASet(TTTURTLe, TTTURTle, WOa(TTTURTLE, TTURTLE));
TTTURTle = Woa(TTTURTle, turtle());
}
Mu Wow(TURTLE, TTUrtle) # /
{
TTTURTle = WOa(TTTURTle, turtle());
TTURTLE = TurtleAGet(TTTURTLe, TTTURTle);
TTTURTle = WOa(TTTURTle, turtle());
TTTURTLE = TurtleAGet(TTTURTLe, TTTURTle);
TurtleASet(TTTURTLe, TTTURTle, WOA(TTTURTLE, TTURTLE));
TTTURTle = Woa(TTTURTle, turtle());
}
Tturtle = Woa(Tturtle, turtle());
}
# Reusing this variable cus it's useless now.
Tturtle = noTurtle();
MU WoW(Tturtle, TTTURTle)
{
wOA(TurtleAGet(TTTURTLe, Tturtle));
Tturtle = Woa(Tturtle, turtle());
}
}
Mu TurtleALength(TurtleArgv)
{
Turtle = TurtleARead(TurtleAGet(TurtleArgv, noTurtle()));
TTTTTTTTURTLE(Turtle);
}

1
programs/samples/README.txt

@ -0,0 +1 @@ @@ -0,0 +1 @@
This folder contain sample files that are used to test programs.

0
programs/hello.bf → programs/samples/hello.bf

2
programs/samples/test.rpn

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
10 2 * 13 + 10 5 / -
1 1 +
Loading…
Cancel
Save