summaryrefslogtreecommitdiff
path: root/examples/SimpleCalc.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2018-12-22 09:28:48 -0800
committerJon Dufresne <jon.dufresne@gmail.com>2018-12-22 13:46:56 -0800
commitde8326d00dffdb500c02839a98330b869c2457f3 (patch)
tree6c5fdae41cf8b335ff1c64f37856786523e4fd0d /examples/SimpleCalc.py
parent59dfd314c23fd653271bdad37631f0497e8ad748 (diff)
downloadpyparsing-git-de8326d00dffdb500c02839a98330b869c2457f3.tar.gz
Trim trailing white space throughout the project
Many editors clean up trailing white space on save. By removing it all in one go, it helps keep future diffs cleaner by avoiding spurious white space changes on unrelated lines.
Diffstat (limited to 'examples/SimpleCalc.py')
-rw-r--r--examples/SimpleCalc.py34
1 files changed, 16 insertions, 18 deletions
diff --git a/examples/SimpleCalc.py b/examples/SimpleCalc.py
index 0bf62e4..15a1817 100644
--- a/examples/SimpleCalc.py
+++ b/examples/SimpleCalc.py
@@ -1,31 +1,31 @@
# SimpleCalc.py
#
-# Demonstration of the parsing module,
+# Demonstration of the parsing module,
# Sample usage
#
-# $ python SimpleCalc.py
+# $ python SimpleCalc.py
# Type in the string to be parse or 'quit' to exit the program
-# > g=67.89 + 7/5
+# > g=67.89 + 7/5
# 69.29
# > g
# 69.29
-# > h=(6*g+8.8)-g
+# > h=(6*g+8.8)-g
# 355.25
-# > h + 1
+# > h + 1
# 356.25
-# > 87.89 + 7/5
+# > 87.89 + 7/5
# 89.29
# > ans+10
# 99.29
# > quit
# Good bye!
#
-#
+#
# Uncomment the line below for readline support on interactive terminal
-# import readline
+# import readline
from pyparsing import ParseException, Word, alphas, alphanums
import math
@@ -64,11 +64,11 @@ pattern = assignment | arithExpr
if __name__ == '__main__':
# input_string
input_string=''
-
+
# Display instructions on how to quit the program
print("Type in the string to be parsed or 'quit' to exit the program")
input_string = input("> ")
-
+
while input_string.strip().lower() != 'quit':
if input_string.strip().lower() == 'debug':
debug_flag=True
@@ -77,19 +77,19 @@ if __name__ == '__main__':
# Reset to an empty exprStack
del exprStack[:]
-
+
if input_string != '':
# try parsing the input string
try:
L=pattern.parseString(input_string, parseAll=True)
except ParseException as err:
L=['Parse Failure', input_string, (str(err), err.line, err.column)]
-
+
# show result of parsing the input string
if debug_flag: print(input_string, "->", L)
if len(L)==0 or L[0] != 'Parse Failure':
if debug_flag: print("exprStack=", exprStack)
-
+
# calculate result , store a copy in ans , display the result to user
try:
result=evaluateStack(exprStack)
@@ -98,7 +98,7 @@ if __name__ == '__main__':
else:
variables['ans']=result
print(result)
-
+
# Assign result to a variable if required
if L.varname:
variables[L.varname] = result
@@ -109,11 +109,9 @@ if __name__ == '__main__':
print(err_line)
print(" "*(err_col-1) + "^")
print(err_str)
-
+
# obtain new input string
input_string = input("> ")
-
+
# if user type 'quit' then say goodbye
print("Good bye!")
-
-