Skip to content

Commit

Permalink
Ans support
Browse files Browse the repository at this point in the history
  • Loading branch information
TabulateJarl8 committed Jul 22, 2021
1 parent b5b7274 commit 8a082f0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ ti842py is a TI-BASIC to Python 3 transpiler. A transpiler is a piece of softwar
- `Menu()`
- `toString()`
- `randInt()`/`rand`
- **Some drawing functions**
- Most drawing functions
- List subscripting
- Matrices
- `Ans`

### Planned Features
- `round()`
- `Return`
- `eval()`/`expr()`
- `Ans`

### Known issues

Expand Down
2 changes: 1 addition & 1 deletion ti842py/__version__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__title__ = "ti842py"
__description__ = "TI-BASIC to Python 3 Transpiler"
__url__ = "https://github.com/TabulateJarl8/ti842py"
__version__ = "0.9.3"
__version__ = "0.9.4"
__author__ = "Tabulate"
__author_email__ = "[email protected]"
__license__ = "GPLv3"
Expand Down
26 changes: 26 additions & 0 deletions ti842py/parsing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ def parenthesis_split(sentence, separator=" ", lparen="(", rparen=")"):
return([sentence[i:j].strip(separator) for i, j in zip(l, l[1:])])


def last_line_without_variable_assignment_ans(full_code):
'''
Used for determining Ans
'''

full_code = full_code[::-1]

for i in range(len(full_code)):
if (not full_code[i].strip().endswith(':')) and \
(noStringReplace(r'(?<!Ans )=', '', [full_code[i]]) == [full_code[i]]) and \
not full_code[i].strip().startswith('#') and \
'.lbl' not in full_code[i]:
# no loops etc that end with : and nothing with item assignments or comparisons
# no comments
# if we come across an Ans before finding a statmenet that can use Ans, just use the last Ans statement
if not full_code[i].strip().startswith('Ans = '):
old_whitespace = full_code[i][:-len(full_code[i].lstrip())]
full_code[i] = old_whitespace + 'Ans = ' + full_code[i].lstrip()

break


return full_code[::-1]



def menu(title, args):
choices = []
for i in range(0, len(args), 2):
Expand Down
3 changes: 3 additions & 0 deletions ti842py/tiParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ def convertLine(self, index, line):
for statement_index, item in enumerate(statement):
statement[statement_index] = parsing_utils.toValidEqn(item)

if 'Ans' in ''.join(statement):
self.pythonCode = parsing_utils.last_line_without_variable_assignment_ans(self.pythonCode)

if isinstance(statement, list) and len(statement) == 1:
statement = statement[0]

Expand Down

0 comments on commit 8a082f0

Please sign in to comment.