mirror of
https://github.com/usatiuk/psil.git
synced 2025-10-28 18:57:48 +01:00
secd parser
This commit is contained in:
@@ -16,6 +16,20 @@ TEST(VMWithParserTest, BasicHello) {
|
||||
EXPECT_EQ(ssout.str(), "h");
|
||||
}
|
||||
|
||||
TEST(VMWithParserTest, BasicBranch) {
|
||||
std::stringstream ssin;
|
||||
std::stringstream ssout;
|
||||
{
|
||||
VM vm(ssin, ssout);
|
||||
Parser parser(vm);
|
||||
parser.loadSecd(
|
||||
"( LDC 1 SEL ( LDC 10 PUTNUM JOIN ) ( LDC 20 PUTNUM JOIN ) LDC 0 SEL ( LDC 30 PUTNUM JOIN ) ( LDC 40 PUTNUM JOIN ) STOP )");
|
||||
vm.run();
|
||||
}
|
||||
ssout.flush();
|
||||
EXPECT_EQ(ssout.str(), "1040");
|
||||
}
|
||||
|
||||
TEST(VMWithParserTest, BasicFunction) {
|
||||
std::stringstream ssin;
|
||||
std::stringstream ssout;
|
||||
@@ -27,4 +41,18 @@ TEST(VMWithParserTest, BasicFunction) {
|
||||
}
|
||||
ssout.flush();
|
||||
EXPECT_EQ(ssout.str(), "3");
|
||||
}
|
||||
|
||||
TEST(VMWithParserTest, RecFunction) {
|
||||
std::stringstream ssin;
|
||||
std::stringstream ssout;
|
||||
{
|
||||
VM vm(ssin, ssout);
|
||||
Parser parser(vm);
|
||||
parser.loadSecd(
|
||||
"( DUM NIL LDF ( LD ( 1 . 1 ) SEL ( LD ( 1 . 1 ) LDC -1 ADD SEL ( NIL LD ( 1 . 1 ) LDC -1 ADD CONS LD ( 2 . 1 ) AP NIL LD ( 1 . 1 ) LDC -2 ADD CONS LD ( 2 . 1 ) AP ADD JOIN ) ( LDC 1 JOIN ) JOIN ) ( LDC 0 JOIN ) RET ) CONS LDF ( NIL LDC 20 CONS LD ( 1 . 1 ) AP RET ) RAP PUTNUM STOP )");
|
||||
vm.run();
|
||||
}
|
||||
ssout.flush();
|
||||
EXPECT_EQ(ssout.str(), "6765");
|
||||
}
|
||||
Reference in New Issue
Block a user