Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
trs
Commits
58a456b5
Commit
58a456b5
authored
Dec 11, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preprocessor now converts '4 4' into '4 * 4'.
parent
7aee3e1c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
src/parser.py
src/parser.py
+8
-7
No files found.
src/parser.py
View file @
58a456b5
...
...
@@ -90,12 +90,13 @@ class Parser(BisonParser):
# - "4a" with "4*a".
# - "a4" with "a^4".
pattern
=
(
'(?:(
\
))
\
s*(
\
()
'
# match: )(
+ '
|
([
a
-
z0
-
9
])
\
s
*
(
\
()
' # match: a(
+ '
|
(
\
))
\
s
*
([
a
-
z0
-
9
])
' # match: )a
+ '
|
([
a
-
z
])
\
s
*
([
a
-
z
]
+
)
' # match: ab
+ '
|
([
0
-
9
])
\
s
*
([
a
-
z
])
' # match: 4a
+ '
|
([
a
-
z
])
\
s
*
([
0
-
9
]))
') # match: a4
pattern
=
(
'(?:(
\
))
\
s*(
\
()
'
# match: )( result: ) * (
+ '
|
([
a
-
z0
-
9
])
\
s
*
(
\
()
' # match: a( result: a * (
+ '
|
(
\
))
\
s
*
([
a
-
z0
-
9
])
' # match: )a result: ) * a
+ '
|
([
a
-
z
])
\
s
*
([
a
-
z
]
+
)
' # match: ab result: a * b
+ '
|
([
0
-
9
])
\
s
*
([
a
-
z
])
' # match: 4a result: 4 * a
+ '
|
([
a
-
z
])
\
s
*
([
0
-
9
])
' # match: a4 result: a ^ 4
+ '
|
([
0
-
9
])
\
s
+
([
0
-
9
]))
') # match: 4 4 result: 4 * 4
def preprocess_data(match):
left, right = filter(None, match.groups())
...
...
@@ -107,7 +108,7 @@ class Parser(BisonParser):
# If all characters on the right are numbers. e.g. "a4", the
# expression implies exponentiation. Make sure ")4" is not
# converted into an exponentiation, because that'
s
multiplication
.
if
left
!=
')'
\
if
left
!=
')'
and
not
48
<=
ord
(
left
)
<
58
\
and
all
(
map
(
lambda
x
:
48
<=
ord
(
x
)
<
58
,
list
(
right
))):
return
'%s^%s'
%
(
left
,
right
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment