Ejemplo n.º 1
0
#!/usr/bin/env python
from athstmt import *
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    AthTokenStatement('PROCREATE',
                      [IdentifierToken('LOOP'),
                       LiteralToken(0, int)]),
    TildeAthLoop(
        True,
        AthStatementList([
            AthTokenStatement('print',
                              [LiteralToken("This shouldn't print.\\n", str)]),
        ],
                         pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('print', [LiteralToken('Yay.\\n', str)]),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('Negation.~ATH', stmts)
Ejemplo n.º 2
0
            AthTokenStatement(
                'print', [LiteralToken('~d', str),
                          IdentifierToken('LOOP')]),
            CondiJump([
                BnaryExpr(['>',
                           IdentifierToken('LOOP'),
                           LiteralToken(0, int)]), 3
            ]),
            AthTokenStatement('REPLICATE', [
                IdentifierToken('LOOP'),
                BnaryExpr(['-',
                           IdentifierToken('LOOP'),
                           LiteralToken(1, int)])
            ]),
            AthTokenStatement('print', [LiteralToken(', ', str)]),
            AthTokenStatement('DIE', [IdentifierToken('LOOP')]),
            AthTokenStatement('REPLICATE', [
                IdentifierToken('LOOP'),
                UnaryExpr(['!', IdentifierToken('LOOP')])
            ]),
            AthTokenStatement('print', [LiteralToken('\\n', str)]),
        ],
                         pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('LoopTypes.~ATH', stmts)
Ejemplo n.º 3
0
                ], pendant='END'),
                AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
            ], pendant='END'),
            AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
        CondiJump([IdentifierToken('A'), 2]),
        AthTokenStatement('print', [LiteralToken('Aw, you wee bab. Do you want me to kiss your booboos away?', str)]),
        CondiJump([None, 13]),
        CondiJump([IdentifierToken('B'), 2]),
        AthTokenStatement('print', [LiteralToken('Fortify!', str)]),
        CondiJump([None, 10]),
        CondiJump([IdentifierToken('C'), 2]),
        AthTokenStatement('print', [LiteralToken(':wackyZany:', str)]),
        CondiJump([None, 7]),
        CondiJump([IdentifierToken('D'), 2]),
        AthTokenStatement('print', [LiteralToken('Have you tried mixing coffee and energy drinks yet.', str)]),
        CondiJump([None, 4]),
        CondiJump([IdentifierToken('E'), 2]),
        AthTokenStatement('print', [LiteralToken('Same.', str)]),
        CondiJump([None, 1]),
        AthTokenStatement('print', [LiteralToken("You're overreacting. Calm your shit.", str)]),
        AthTokenStatement('print', [LiteralToken('\\n', str)]),
        AthTokenStatement('INSPECT', [UnaryExpr(['-', LiteralToken(1, int)])]),
        AthTokenStatement('DIE', [IdentifierToken('LOOP')]),
        ], pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('NotConditionals.~ATH', stmts)
Ejemplo n.º 4
0
            AthTokenStatement('DIE', [IdentifierToken('SUITCHECK')]),
            ], pendant='SUITCHECK'),
            AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
        AthTokenStatement('REPLICATE', [IdentifierToken('SUITCHECK'), BnaryExpr(['==', IdentifierToken('SUIT'), LiteralToken('C', str)])]),
        TildeAthLoop(False, AthStatementList([
            AthTokenStatement('PROCREATE', [IdentifierToken('SUITNAME'), LiteralToken('Clubs', str)]),
            AthTokenStatement('DIE', [IdentifierToken('SUITCHECK')]),
            ], pendant='SUITCHECK'),
            AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
        AthTokenStatement('REPLICATE', [IdentifierToken('SUITCHECK'), BnaryExpr(['==', IdentifierToken('SUITNAME'), LiteralToken('', str)])]),
        TildeAthLoop(False, AthStatementList([
            AthTokenStatement('PROCREATE', [IdentifierToken('SUITNAME'), LiteralToken('WRONG', str)]),
            AthTokenStatement('print', [LiteralToken("This isn't a real card suit!\\n", str)]),
            AthTokenStatement('DIE', [IdentifierToken('SUITCHECK')]),
            ], pendant='SUITCHECK'),
            AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
        AthTokenStatement('REPLICATE', [IdentifierToken('VALID'), BnaryExpr(['l&', BnaryExpr(['~=', IdentifierToken('SUITNAME'), LiteralToken('WRONG', str)]), BnaryExpr(['~=', IdentifierToken('FACENAME'), LiteralToken('WRONG', str)])])]),
        TildeAthLoop(False, AthStatementList([
            AthTokenStatement('print', [LiteralToken('Your card is the ~s of ~s.\\n', str), IdentifierToken('FACENAME'), IdentifierToken('SUITNAME')]),
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
            ], pendant='VALID'),
            AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
        AthTokenStatement('print', [LiteralToken('Go back and try again with a REAL deck of cards!\\n', str)]),
        AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ], pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('LoopHell.~ATH', stmts)
Ejemplo n.º 5
0
        AthCustomFunction(
            'G', ['J'],
            AthStatementList([
                AthTokenStatement('PROCREATE', [
                    IdentifierToken('J'),
                    BnaryExpr(
                        ['+', IdentifierToken('J'),
                         LiteralToken(1, int)])
                ])
            ],
                             pendant='G'))
    ]),
    TildeAthLoop(
        False,
        AthStatementList([
            AthTokenStatement('EXECUTE',
                              [IdentifierToken('F'),
                               IdentifierToken('X')]),
            AthTokenStatement(
                'print', [LiteralToken('~d\\n', str),
                          IdentifierToken('X')]),
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ],
                         pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('ScopeTest2.~ATH', stmts)
        AthTokenStatement('AGGREGATE', [IdentifierToken('LIST'), IdentifierToken('L'), IdentifierToken('R')]),
        AthTokenStatement('REPLICATE', [IdentifierToken('TEMP'), IdentifierToken('LIST')]),
        AthTokenStatement('print', [LiteralToken('The items in sorted ascending order are:\\n[', str)]),
        TildeAthLoop(False, AthStatementList([
            AthTokenStatement('BIFURCATE', [IdentifierToken('TEMP'), IdentifierToken('HEAD'), IdentifierToken('TEMP')]),
            AthTokenStatement('print', [LiteralToken('~s', str), IdentifierToken('HEAD')]),
            CondiJump([IdentifierToken('TEMP'), 1]),
            AthTokenStatement('print', [LiteralToken(', ', str)]),
            ], pendant='TEMP'),
            AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
        AthTokenStatement('print', [LiteralToken(']\\n', str)]),
        CondiJump([None, 12]),
        AthTokenStatement('print', [LiteralToken('List is empty, oops.\\n', str)]),
        CondiJump([None, 10]),
        CondiJump([BnaryExpr(['==', IdentifierToken('CHOICE'), LiteralToken(1, int)]), 8]),
        AthTokenStatement('REPLICATE', [IdentifierToken('ITEM'), LiteralToken('', str)]),
        AthTokenStatement('input', [IdentifierToken('ITEM'), LiteralToken('Input string to add: ', str)]),
        CondiJump([BnaryExpr(['==', IdentifierToken('LLEN'), LiteralToken(0, int)]), 2]),
        AthTokenStatement('AGGREGATE', [IdentifierToken('LIST'), IdentifierToken('ITEM'), IdentifierToken('NULL')]),
        CondiJump([None, 1]),
        AthTokenStatement('AGGREGATE', [IdentifierToken('LIST'), IdentifierToken('ITEM'), IdentifierToken('LIST')]),
        AthTokenStatement('PROCREATE', [IdentifierToken('LLEN'), BnaryExpr(['+', IdentifierToken('LLEN'), LiteralToken(1, int)])]),
        CondiJump([None, 1]),
        AthTokenStatement('print', [LiteralToken('Invalid choice, try again.\\n', str)]),
        ], pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('MergeImplementation.~ATH', stmts)
Ejemplo n.º 7
0
                AthTokenStatement('PROCREATE', [
                    IdentifierToken('A'),
                    BnaryExpr(
                        ['+', IdentifierToken('A'),
                         LiteralToken(1, int)])
                ]),
                AthTokenStatement(
                    'print', [LiteralToken('~s ', str),
                              IdentifierToken('A')]),
                AthTokenStatement('EXECUTE', [IdentifierToken('COUNT')])
            ],
                             pendant='COUNT'))
    ]),
    AthTokenStatement('PROCREATE',
                      [IdentifierToken('LOOP'),
                       LiteralToken(0, int)]),
    TildeAthLoop(
        False,
        AthStatementList([
            AthTokenStatement('EXECUTE', [IdentifierToken('COUNT')]),
            AthTokenStatement('DIE', [IdentifierToken('LOOP')]),
        ],
                         pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('CountTo100.~ATH', stmts)
Ejemplo n.º 8
0
#!/usr/bin/env python
from athstmt import *
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    AthTokenStatement('import', ['MATH', 'LOGBN']),
    TildeAthLoop(
        False,
        AthStatementList([
            AthTokenStatement(
                'input',
                [IdentifierToken('NUM'),
                 LiteralToken('Enter number: ', str)]),
            AthTokenStatement('print', [
                LiteralToken('Log base 2 of ~0.3f is ~0.3f.\\n', str),
                IdentifierToken('NUM'),
                AthTokenStatement(
                    'EXECUTE',
                    [IdentifierToken('LOGBN'),
                     IdentifierToken('NUM')])
            ]),
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ],
                         pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('MathTest.~ATH', stmts)
Ejemplo n.º 9
0
                                IdentifierToken('N2')
                            ])
                        ]),
                        AthTokenStatement('REPLICATE', [
                            IdentifierToken('LENGTH'),
                            BnaryExpr([
                                '-',
                                IdentifierToken('LENGTH'),
                                LiteralToken(1, int)
                            ])
                        ]),
                    ],
                                     pendant='LOOP'),
                    AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
                AthTokenStatement('DIVULGATE', [IdentifierToken('N3')])
            ],
                             pendant='FIB'))
    ]),
    TildeAthLoop(
        False,
        AthStatementList([
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ],
                         pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('ModuleTest.~ATH', stmts)
Ejemplo n.º 10
0
                IdentifierToken('Z'),
                IdentifierToken('X'),
                IdentifierToken('Y')
            ]),
            AthTokenStatement('PROCREATE',
                              [IdentifierToken('A'),
                               LiteralToken(3, int)]),
            AthTokenStatement('REPLICATE',
                              [IdentifierToken('Y'),
                               IdentifierToken('A')]),
            AthTokenStatement('BIFURCATE', [
                IdentifierToken('Z'),
                IdentifierToken('B'),
                IdentifierToken('C')
            ]),
            AthTokenStatement('print', [
                LiteralToken('~s, ~s', str),
                IdentifierToken('B'),
                IdentifierToken('C')
            ]),
            AthTokenStatement('DIE', [IdentifierToken('LOOP')]),
        ],
                         pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('Aggregate-BifurcateTest.~ATH', stmts)
Ejemplo n.º 11
0
                        '==',
                        IdentifierToken('SUITNAME'),
                        LiteralToken('WRONG', str)
                    ]),
                    BnaryExpr([
                        '==',
                        IdentifierToken('FACENAME'),
                        LiteralToken('WRONG', str)
                    ])
                ]), 2
            ]),
            AthTokenStatement('print', [
                LiteralToken(
                    'Go back and try again with a REAL deck of cards!\\n', str)
            ]),
            CondiJump([None, 1]),
            AthTokenStatement('print', [
                LiteralToken('Your card is the ~s of ~ss.\\n', str),
                IdentifierToken('FACENAME'),
                IdentifierToken('SUITNAME')
            ]),
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ],
                         pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('CardParser.~ATH', stmts)
Ejemplo n.º 12
0
#!/usr/bin/env python
from athstmt import *
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    AthTokenStatement('PROCREATE',
                      [IdentifierToken('LOOP'),
                       IdentifierToken('NULL')]),
    TildeAthLoop(
        False,
        AthStatementList([
            AthTokenStatement('print',
                              [LiteralToken('Are you there.\\n', str)]),
            AthTokenStatement('DIE', [IdentifierToken('LOOP')]),
        ],
                         pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('NullInstance.~ATH', stmts)
Ejemplo n.º 13
0
#!/usr/bin/env python
from athstmt import *
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    AthTokenStatement('FABRICATE', [AthCustomFunction('ACK', ['M', 'N'], AthStatementList([
        CondiJump([BnaryExpr(['==', IdentifierToken('M'), LiteralToken(0, int)]), 2]),
        AthTokenStatement('DIVULGATE', [BnaryExpr(['+', IdentifierToken('N'), LiteralToken(1, int)])]),
        CondiJump([None, 4]),
        CondiJump([BnaryExpr(['==', IdentifierToken('N'), LiteralToken(0, int)]), 2]),
        AthTokenStatement('DIVULGATE', [AthTokenStatement('EXECUTE', [IdentifierToken('ACK'), BnaryExpr(['-', IdentifierToken('M'), LiteralToken(1, int)]), LiteralToken(1, int)])]),
        CondiJump([None, 1]),
        AthTokenStatement('DIVULGATE', [AthTokenStatement('EXECUTE', [IdentifierToken('ACK'), BnaryExpr(['-', IdentifierToken('M'), LiteralToken(1, int)]), AthTokenStatement('EXECUTE', [IdentifierToken('ACK'), IdentifierToken('M'), BnaryExpr(['-', IdentifierToken('N'), LiteralToken(1, int)])])])])
        ], pendant='ACK'))]),
    TildeAthLoop(False, AthStatementList([
        AthTokenStatement('input', [IdentifierToken('NUM'), LiteralToken('Get the ackermann function of: ', str)]),
        AthTokenStatement('print', [LiteralToken('The value of A(n, n) is ~d.\\n', str), AthTokenStatement('EXECUTE', [IdentifierToken('ACK'), IdentifierToken('NUM'), IdentifierToken('NUM')])]),
        AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ], pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('Ackermann.~ATH', stmts)
Ejemplo n.º 14
0
#!/usr/bin/env python
from athstmt import *
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    TildeAthLoop(
        False,
        AthStatementList([
            AthTokenStatement('print', [
                LiteralToken('~d is twelve.', str),
                BnaryExpr([
                    '+',
                    LiteralToken(5, int),
                    UnaryExpr(['+', LiteralToken(7, int)])
                ])
            ]),
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ],
                         pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('BadUnaryTest.~ATH', stmts)
Ejemplo n.º 15
0
stmts = AthStatementList([
    TildeAthLoop(
        False,
        AthStatementList([
            AthTokenStatement(
                'input',
                [IdentifierToken('NUM'),
                 LiteralToken('Enter number: ', str)]),
            AthTokenStatement('print', [
                LiteralToken('Log base 2 of ~0.3f is ~0.3f.\\n', str),
                IdentifierToken('NUM'),
                AthTokenStatement('EXECUTE', [
                    AthTokenStatement('EXECUTE', [
                        IdentifierToken('import'),
                        LiteralToken('MATH', str),
                        LiteralToken('LOGBN', str)
                    ]),
                    IdentifierToken('NUM')
                ])
            ]),
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ],
                         pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('StatementFuncTest.~ATH', stmts)
Ejemplo n.º 16
0
#!/usr/bin/env python
from athstmt import *
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    TildeAthLoop(False, AthStatementList([
        AthTokenStatement('print', [LiteralToken('Hello World!\\n', str)]),
        AthTokenStatement('print', [LiteralToken('This is the script ~s!\\n', str), IdentifierToken('THIS')]),
        AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ], pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('Hello.~ATH', stmts)
Ejemplo n.º 17
0
#!/usr/bin/env python
from athstmt import *
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    AthTokenStatement('import', ['ModuleTest', 'FIB']),
    AthTokenStatement('PROCREATE', [IdentifierToken('MAIN'), None]),
    AthTokenStatement('PROCREATE', [IdentifierToken('COUNT'), LiteralToken(1, int)]),
    TildeAthLoop(False, AthStatementList([
        AthTokenStatement('print', [LiteralToken('F~d = ~d\\n', str), IdentifierToken('COUNT'), AthTokenStatement('EXECUTE', [IdentifierToken('FIB'), IdentifierToken('COUNT')])]),
        CondiJump([BnaryExpr(['>=', IdentifierToken('COUNT'), LiteralToken(10, int)]), 1]),
        AthTokenStatement('DIE', [IdentifierToken('MAIN')]),
        AthTokenStatement('PROCREATE', [IdentifierToken('COUNT'), BnaryExpr(['+', IdentifierToken('COUNT'), LiteralToken(1, int)])]),
        ], pendant='MAIN'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('ImportTest.~ATH', stmts)
Ejemplo n.º 18
0
                        ])
                    ])
                ])
            ],
                             pendant='COUNTER'))
    ]),
    TildeAthLoop(
        False,
        AthStatementList([
            AthTokenStatement('input', [
                IdentifierToken('NUM'),
                LiteralToken('Give an integer to count the digits of: ', str)
            ]),
            AthTokenStatement('print', [
                LiteralToken('There are ~d digits in that integer.\\n', str),
                AthTokenStatement('EXECUTE', [
                    IdentifierToken('COUNTER'),
                    IdentifierToken('NUM'),
                    LiteralToken(0, int)
                ])
            ]),
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ],
                         pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('DigitCounter.~ATH', stmts)
Ejemplo n.º 19
0
        AthTokenStatement('print', [LiteralToken('[3] Exit\\n', str)]),
        AthTokenStatement('input', [IdentifierToken('CHOICE'), LiteralToken('', str)]),
        CondiJump([BnaryExpr(['==', IdentifierToken('CHOICE'), LiteralToken(3, int)]), 2]),
        AthTokenStatement('DIE', [IdentifierToken('LOOP')]),
        CondiJump([None, 14]),
        CondiJump([BnaryExpr(['==', IdentifierToken('CHOICE'), LiteralToken(2, int)]), 3]),
        AthTokenStatement('REPLICATE', [IdentifierToken('TEMP'), IdentifierToken('STACK')]),
        TildeAthLoop(False, AthStatementList([
            AthTokenStatement('BIFURCATE', [IdentifierToken('TEMP'), IdentifierToken('HEAD'), IdentifierToken('TEMP')]),
            AthTokenStatement('print', [LiteralToken('~s\\n', str), IdentifierToken('HEAD')]),
            ], pendant='TEMP'),
            AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
        CondiJump([None, 10]),
        CondiJump([BnaryExpr(['==', IdentifierToken('CHOICE'), LiteralToken(1, int)]), 8]),
        AthTokenStatement('REPLICATE', [IdentifierToken('ITEM'), LiteralToken('', str)]),
        AthTokenStatement('input', [IdentifierToken('ITEM'), LiteralToken('Input string to add: ', str)]),
        CondiJump([IdentifierToken('FLAG'), 3]),
        AthTokenStatement('AGGREGATE', [IdentifierToken('STACK'), IdentifierToken('ITEM'), IdentifierToken('NULL')]),
        AthTokenStatement('DIE', [IdentifierToken('FLAG')]),
        CondiJump([None, 3]),
        AthTokenStatement('AGGREGATE', [IdentifierToken('STACK'), IdentifierToken('ITEM'), IdentifierToken('STACK')]),
        CondiJump([None, 1]),
        AthTokenStatement('print', [LiteralToken('Invalid input.', str)]),
        ], pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('StackTest.~ATH', stmts)
Ejemplo n.º 20
0
#!/usr/bin/env python
from athstmt import *
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    AthTokenStatement('PROCREATE', [IdentifierToken('LOOP'), LiteralToken(0, int)]),
    AthTokenStatement('PROCREATE', [IdentifierToken('A'), LiteralToken(0, int)]),
    AthTokenStatement('FABRICATE', [AthCustomFunction('ADDONE', [], AthStatementList([
        AthTokenStatement('AGGREGATE', [IdentifierToken('A'), BnaryExpr(['+', IdentifierToken('A'), LiteralToken(1, int)]), IdentifierToken('NULL')]),
        AthTokenStatement('BIFURCATE', [IdentifierToken('A'), IdentifierToken('A'), IdentifierToken('NULL')])
        ], pendant='ADDONE'))]),
    TildeAthLoop(False, AthStatementList([
        AthTokenStatement('EXECUTE', [IdentifierToken('ADDONE')]),
        AthTokenStatement('print', [LiteralToken('~s ', str), IdentifierToken('A')]),
        CondiJump([BnaryExpr(['==', IdentifierToken('A'), LiteralToken(256, int)]), 2]),
        AthTokenStatement('print', [LiteralToken('\\n', str)]),
        AthTokenStatement('DIE', [IdentifierToken('LOOP')]),
        ], pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('AddOneFunc.~ATH', stmts)
Ejemplo n.º 21
0
        CondiJump([BnaryExpr(['==', IdentifierToken('K'), LiteralToken(0, int)]), 4]),
        AthTokenStatement('PROCREATE', [IdentifierToken('X1'), BnaryExpr(['/', UnaryExpr(['-', IdentifierToken('B')]), BnaryExpr(['*', LiteralToken(3, int), IdentifierToken('A')])])]),
        AthTokenStatement('PROCREATE', [IdentifierToken('X2'), IdentifierToken('X1')]),
        AthTokenStatement('PROCREATE', [IdentifierToken('X3'), IdentifierToken('X1')]),
        CondiJump([None, 16]),
        AthTokenStatement('PROCREATE', [IdentifierToken('X1'), BnaryExpr(['/', BnaryExpr(['-', BnaryExpr(['*', IdentifierToken('B'), BnaryExpr(['-', BnaryExpr(['*', BnaryExpr(['*', LiteralToken(4, int), IdentifierToken('A')]), IdentifierToken('C')]), BnaryExpr(['*', IdentifierToken('B'), IdentifierToken('B')])])]), BnaryExpr(['*', BnaryExpr(['*', BnaryExpr(['*', LiteralToken(9, int), IdentifierToken('A')]), IdentifierToken('A')]), IdentifierToken('D')])]), BnaryExpr(['*', IdentifierToken('A'), IdentifierToken('K')])])]),
        AthTokenStatement('PROCREATE', [IdentifierToken('X2'), BnaryExpr(['/', BnaryExpr(['-', BnaryExpr(['*', BnaryExpr(['*', LiteralToken(9, int), IdentifierToken('A')]), IdentifierToken('D')]), BnaryExpr(['*', IdentifierToken('B'), IdentifierToken('C')])]), BnaryExpr(['*', LiteralToken(2, int), IdentifierToken('K')])])]),
        AthTokenStatement('PROCREATE', [IdentifierToken('X3'), IdentifierToken('X2')]),
        CondiJump([None, 12]),
        AthTokenStatement('PROCREATE', [IdentifierToken('R'), BnaryExpr(['+', UnaryExpr(['-', LiteralToken(0.5, float)]), BnaryExpr(['*', BnaryExpr(['^', LiteralToken(0.75, float), LiteralToken(0.5, float)]), LiteralToken(1j, complex)])])]),
        AthTokenStatement('PROCREATE', [IdentifierToken('L'), BnaryExpr(['+', BnaryExpr(['*', BnaryExpr(['*', BnaryExpr(['*', LiteralToken(2, int), IdentifierToken('B')]), IdentifierToken('B')]), IdentifierToken('B')]), BnaryExpr(['*', BnaryExpr(['*', LiteralToken(9, int), IdentifierToken('A')]), BnaryExpr(['-', BnaryExpr(['*', BnaryExpr(['*', LiteralToken(3, int), IdentifierToken('A')]), IdentifierToken('D')]), BnaryExpr(['*', IdentifierToken('B'), IdentifierToken('C')])])])])]),
        AthTokenStatement('PROCREATE', [IdentifierToken('M'), BnaryExpr(['^', BnaryExpr(['*', BnaryExpr(['*', BnaryExpr(['*', UnaryExpr(['-', LiteralToken(27, int)]), IdentifierToken('A')]), IdentifierToken('A')]), IdentifierToken('J')]), LiteralToken(0.5, float)])]),
        CondiJump([BnaryExpr(['==', IdentifierToken('L'), IdentifierToken('M')]), 2]),
        AthTokenStatement('PROCREATE', [IdentifierToken('C1'), BnaryExpr(['^', BnaryExpr(['/', BnaryExpr(['+', IdentifierToken('L'), IdentifierToken('M')]), LiteralToken(2, int)]), BnaryExpr(['/', LiteralToken(1, int), LiteralToken(3, int)])])]),
        CondiJump([None, 1]),
        AthTokenStatement('PROCREATE', [IdentifierToken('C1'), BnaryExpr(['^', BnaryExpr(['/', BnaryExpr(['-', IdentifierToken('L'), IdentifierToken('M')]), LiteralToken(2, int)]), BnaryExpr(['/', LiteralToken(1, int), LiteralToken(3, int)])])]),
        AthTokenStatement('PROCREATE', [IdentifierToken('C2'), BnaryExpr(['*', IdentifierToken('C1'), IdentifierToken('R')])]),
        AthTokenStatement('PROCREATE', [IdentifierToken('C3'), BnaryExpr(['/', IdentifierToken('C1'), IdentifierToken('R')])]),
        AthTokenStatement('PROCREATE', [IdentifierToken('X1'), BnaryExpr(['/', UnaryExpr(['-', BnaryExpr(['+', BnaryExpr(['+', IdentifierToken('B'), IdentifierToken('C1')]), BnaryExpr(['/', IdentifierToken('K'), IdentifierToken('C1')])])]), BnaryExpr(['*', LiteralToken(3, int), IdentifierToken('A')])])]),
        AthTokenStatement('PROCREATE', [IdentifierToken('X2'), BnaryExpr(['/', UnaryExpr(['-', BnaryExpr(['+', BnaryExpr(['+', IdentifierToken('B'), IdentifierToken('C2')]), BnaryExpr(['/', IdentifierToken('K'), IdentifierToken('C2')])])]), BnaryExpr(['*', LiteralToken(3, int), IdentifierToken('A')])])]),
        AthTokenStatement('PROCREATE', [IdentifierToken('X3'), BnaryExpr(['/', UnaryExpr(['-', BnaryExpr(['+', BnaryExpr(['+', IdentifierToken('B'), IdentifierToken('C3')]), BnaryExpr(['/', IdentifierToken('K'), IdentifierToken('C3')])])]), BnaryExpr(['*', LiteralToken(3, int), IdentifierToken('A')])])]),
        AthTokenStatement('print', [LiteralToken('The three roots are ~.4f, ~.4f, ~.4f\\n', str), IdentifierToken('X1'), IdentifierToken('X2'), IdentifierToken('X3')]),
        AthTokenStatement('DIE', [IdentifierToken('LOOP')]),
        ], pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('CubicRoots.~ATH', stmts)
Ejemplo n.º 22
0
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    AthTokenStatement('PROCREATE', [IdentifierToken('FOO'), None]),
    AthTokenStatement('PROCREATE', [IdentifierToken('BAR'), None]),
    TildeAthLoop(
        False,
        AthStatementList([
            TildeAthLoop(
                False,
                AthStatementList([
                    AthTokenStatement('print', [LiteralToken('Oof.\\n', str)]),
                    AthTokenStatement(
                        'DIE',
                        [IdentifierToken('FOO'),
                         IdentifierToken('BAR')]),
                ],
                                 pendant='BAR'),
                AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
            AthTokenStatement('print',
                              [LiteralToken('Well hello there.\\n', str)]),
        ],
                         pendant='FOO'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('SerialKiller.~ATH', stmts)
Ejemplo n.º 23
0
        CondiJump([BnaryExpr(['==', IdentifierToken('NUM'), LiteralToken(7, int)]), 3]),
        AthTokenStatement('print', [LiteralToken('Congrats, your number is 7.\\n', str)]),
        AthTokenStatement('print', [LiteralToken('Look at how achieved you are.\\n', str)]),
        CondiJump([None, 18]),
        AthTokenStatement('print', [LiteralToken('This should never f****n print.\\n', str)]),
        CondiJump([None, 16]),
        AthTokenStatement('print', [LiteralToken('Congrats, your number is 4.\\n', str)]),
        AthTokenStatement('print', [LiteralToken('Look at how achieved you are.\\n', str)]),
        CondiJump([None, 13]),
        CondiJump([BnaryExpr(['>', IdentifierToken('NUM'), LiteralToken(8, int)]), 10]),
        AthTokenStatement('print', [LiteralToken('Your number is more than 8.\\n', str)]),
        CondiJump([BnaryExpr(['<', IdentifierToken('NUM'), LiteralToken(12, int)]), 2]),
        AthTokenStatement('print', [LiteralToken('Your number is less than 12.\\n', str)]),
        CondiJump([None, 8]),
        CondiJump([BnaryExpr(['>', IdentifierToken('NUM'), LiteralToken(12, int)]), 2]),
        AthTokenStatement('print', [LiteralToken('Your number is more than 12.\\n', str)]),
        CondiJump([None, 5]),
        AthTokenStatement('print', [LiteralToken('Congrats, your number is 12.\\n', str)]),
        AthTokenStatement('print', [LiteralToken('Look at how achieved you are.\\n', str)]),
        CondiJump([None, 2]),
        AthTokenStatement('print', [LiteralToken('Congrats, your number is 8.\\n', str)]),
        AthTokenStatement('print', [LiteralToken('Look at how achieved you are.\\n', str)]),
        AthTokenStatement('print', [LiteralToken('Time to end the program, mate.\\n', str)]),
        AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ], pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('Nesting.~ATH', stmts)
Ejemplo n.º 24
0
                    ]),
                    BnaryExpr(
                        ['*', LiteralToken(2, int),
                         IdentifierToken('A')])
                ])
            ]),
            AthTokenStatement('print', [
                LiteralToken(
                    'The roots of the quadratic equation ~dx^2 + ~dx + ~d are ~.4f and ~.4f.',
                    str),
                IdentifierToken('A'),
                IdentifierToken('B'),
                IdentifierToken('C'),
                BnaryExpr(['+',
                           IdentifierToken('R'),
                           IdentifierToken('I')]),
                BnaryExpr(['-',
                           IdentifierToken('R'),
                           IdentifierToken('I')])
            ]),
            AthTokenStatement('DIE', [IdentifierToken('LOOP')]),
        ],
                         pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('GetRoots.~ATH', stmts)
Ejemplo n.º 25
0
                    ])
                ]),
                AthTokenStatement('DIVULGATE', [IdentifierToken('PROD')])
            ],
                             pendant='FACT'))
    ]),
    TildeAthLoop(
        False,
        AthStatementList([
            AthTokenStatement('input', [
                IdentifierToken('NUM'),
                LiteralToken('Get the factorial of: ', str)
            ]),
            AthTokenStatement('print', [
                LiteralToken('The factorial is ~d.\\n', str),
                AthTokenStatement('EXECUTE', [
                    IdentifierToken('FACT'),
                    LiteralToken(1, int),
                    IdentifierToken('NUM')
                ])
            ]),
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ],
                         pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('Factorial.~ATH', stmts)
Ejemplo n.º 26
0
#!/usr/bin/env python
from athstmt import *
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    AthTokenStatement('PROCREATE', [IdentifierToken('TEST'), None]),
    TildeAthLoop(
        False,
        AthStatementList([
            CondiJump([IdentifierToken('TEST'), 3]),
            AthTokenStatement('print', [LiteralToken('Test!\\n', str)]),
            AthTokenStatement('REPLICATE', [
                IdentifierToken('TEST'),
                UnaryExpr(['!', IdentifierToken('TEST')])
            ]),
            CondiJump([None, 5]),
            CondiJump([UnaryExpr(['!', IdentifierToken('TEST')]), 3]),
            AthTokenStatement('print', [LiteralToken('Test died\\n', str)]),
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
            CondiJump([None, 1]),
            AthTokenStatement('print',
                              [LiteralToken('should not print\\n', str)]),
        ],
                         pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('IfJump.~ATH', stmts)
Ejemplo n.º 27
0
                    'l|',
                    BnaryExpr([
                        '==',
                        IdentifierToken('CHOICE'),
                        LiteralToken('DIE', str)
                    ]),
                    BnaryExpr([
                        '==',
                        IdentifierToken('CHOICE'),
                        LiteralToken('die', str)
                    ])
                ]), 3
            ]),
            AthTokenStatement('print', [LiteralToken('Hmph. Ninny.\\n', str)]),
            AthTokenStatement('DIE', [IdentifierToken('LOOP')]),
            CondiJump([None, 1]),
            AthTokenStatement('print', [
                LiteralToken("HA! Loser can't even guess the cheat code.\\n",
                             str)
            ]),
            AthTokenStatement('print', [LiteralToken('\\n', str)]),
        ],
                         pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('1ItemTest.~ATH', stmts)
Ejemplo n.º 28
0
                        '==',
                        IdentifierToken('SUITNAME'),
                        LiteralToken('WRONG', str)
                    ]),
                    BnaryExpr([
                        '==',
                        IdentifierToken('FACENAME'),
                        LiteralToken('WRONG', str)
                    ])
                ]), 2
            ]),
            AthTokenStatement('print', [
                LiteralToken(
                    'Go back and try again with a REAL deck of cards!\\n', str)
            ]),
            CondiJump([None, 1]),
            AthTokenStatement('print', [
                LiteralToken('Your card is the ~s of ~ss.\\n', str),
                IdentifierToken('FACENAME'),
                IdentifierToken('SUITNAME')
            ]),
            AthTokenStatement('DIE', [IdentifierToken('THIS')]),
        ],
                         pendant='THIS'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('WoC.~ATH', stmts)
Ejemplo n.º 29
0
            AthTokenStatement('BIFURCATE', [IdentifierToken('TEMP'), IdentifierToken('HEAD'), IdentifierToken('TEMP')]),
            AthTokenStatement('AGGREGATE', [IdentifierToken('STACK'), IdentifierToken('HEAD'), IdentifierToken('STACK')]),
            ], pendant='TEMP'),
            AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
        TildeAthLoop(False, AthStatementList([
            AthTokenStatement('BIFURCATE', [IdentifierToken('STACK'), IdentifierToken('HEAD'), IdentifierToken('STACK')]),
            AthTokenStatement('print', [LiteralToken('~s\\n', str), IdentifierToken('HEAD')]),
            ], pendant='STACK'),
            AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
        AthTokenStatement('print', [LiteralToken('Queue print done.\\n', str)]),
        CondiJump([None, 12]),
        AthTokenStatement('print', [LiteralToken('Queue is empty.\\n', str)]),
        CondiJump([None, 10]),
        CondiJump([BnaryExpr(['==', IdentifierToken('CHOICE'), LiteralToken(1, int)]), 8]),
        AthTokenStatement('REPLICATE', [IdentifierToken('ITEM'), LiteralToken('', str)]),
        AthTokenStatement('input', [IdentifierToken('ITEM'), LiteralToken('Input string to add: ', str)]),
        CondiJump([IdentifierToken('FLAG'), 3]),
        AthTokenStatement('AGGREGATE', [IdentifierToken('QUEUE'), IdentifierToken('ITEM'), IdentifierToken('NULL')]),
        AthTokenStatement('DIE', [IdentifierToken('FLAG')]),
        CondiJump([None, 3]),
        AthTokenStatement('AGGREGATE', [IdentifierToken('QUEUE'), IdentifierToken('ITEM'), IdentifierToken('QUEUE')]),
        CondiJump([None, 1]),
        AthTokenStatement('print', [LiteralToken('Invalid input.', str)]),
        ], pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')])),
    AthTokenStatement('DIE', [IdentifierToken('THIS')])
    ], pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('QueueTest.~ATH', stmts)
Ejemplo n.º 30
0
#!/usr/bin/env python
from athstmt import *
from athinterpreter import TildeAthInterp

stmts = AthStatementList([
    AthTokenStatement('PROCREATE', [IdentifierToken('LOOP'), None]),
    TildeAthLoop(
        False,
        AthStatementList([
            AthTokenStatement('print', [LiteralToken('Hi.\\n', str)]),
        ],
                         pendant='LOOP'),
        AthTokenStatement('EXECUTE', [IdentifierToken('NULL')]))
],
                         pendant='THIS')

if __name__ == '__main__':
    TildeAthInterp().exec_stmts('InfiniteLoopTest.~ATH', stmts)