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
dd699e45
Commit
dd699e45
authored
Jun 13, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for curly bracket notation instead of parenthesis.
parent
68a227a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
src/parser.py
src/parser.py
+9
-4
tests/test_parser.py
tests/test_parser.py
+3
-0
No files found.
src/parser.py
View file @
dd699e45
...
@@ -96,8 +96,9 @@ class Parser(BisonParser):
...
@@ -96,8 +96,9 @@ class Parser(BisonParser):
# of tokens of the lex script.
# of tokens of the lex script.
tokens
=
[
'NUMBER'
,
'IDENTIFIER'
,
'NEWLINE'
,
'QUIT'
,
'RAISE'
,
'GRAPH'
,
tokens
=
[
'NUMBER'
,
'IDENTIFIER'
,
'NEWLINE'
,
'QUIT'
,
'RAISE'
,
'GRAPH'
,
'LPAREN'
,
'RPAREN'
,
'FUNCTION'
,
'FUNCTION_LPAREN'
,
'LBRACKET'
,
'LPAREN'
,
'RPAREN'
,
'FUNCTION'
,
'FUNCTION_LPAREN'
,
'LBRACKET'
,
'RBRACKET'
,
'PIPE'
,
'PRIME'
,
'DERIVATIVE'
]
\
'RBRACKET'
,
'LCBRACKET'
,
'RCBRACKET'
,
'PIPE'
,
'PRIME'
,
+
filter
(
lambda
t
:
t
!=
'FUNCTION'
,
TOKEN_MAP
.
values
())
'DERIVATIVE'
]
\
+
filter
(
lambda
t
:
t
!=
'FUNCTION'
,
TOKEN_MAP
.
values
())
# ------------------------------
# ------------------------------
# precedences
# precedences
...
@@ -468,6 +469,7 @@ class Parser(BisonParser):
...
@@ -468,6 +469,7 @@ class Parser(BisonParser):
| IDENTIFIER
| IDENTIFIER
| LPAREN exp RPAREN
| LPAREN exp RPAREN
| LBRACKET exp RBRACKET
| LBRACKET exp RBRACKET
| LCBRACKET exp RCBRACKET
| unary
| unary
| binary
| binary
| nary
| nary
...
@@ -482,10 +484,11 @@ class Parser(BisonParser):
...
@@ -482,10 +484,11 @@ class Parser(BisonParser):
if
option
==
1
:
# rule: IDENTIFIER
if
option
==
1
:
# rule: IDENTIFIER
return
Leaf
(
values
[
0
])
return
Leaf
(
values
[
0
])
if
option
in
(
2
,
3
):
# rule: LPAREN exp RPAREN | LBRACKET exp RBRACKET
if
2
<=
option
<=
4
:
# rule: LPAREN exp RPAREN | LBRACKET exp RBRACKET
# | LCBRACKET exp RCBRACKET
return
values
[
1
]
return
values
[
1
]
if
4
<=
option
<=
6
:
# rule: unary | binary | nary
if
5
<=
option
<=
7
:
# rule: unary | binary | nary
return
values
[
0
]
return
values
[
0
]
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
...
@@ -714,6 +717,8 @@ class Parser(BisonParser):
...
@@ -714,6 +717,8 @@ class Parser(BisonParser):
")" { returntoken(RPAREN); }
")" { returntoken(RPAREN); }
"[" { returntoken(LBRACKET); }
"[" { returntoken(LBRACKET); }
"]" { returntoken(RBRACKET); }
"]" { returntoken(RBRACKET); }
"{" { returntoken(LCBRACKET); }
"}" { returntoken(RCBRACKET); }
"'" { returntoken(PRIME); }
"'" { returntoken(PRIME); }
"|" { returntoken(PIPE); }
"|" { returntoken(PIPE); }
log_([0-9]+|[a-zA-Z])"*(" { returntoken(FUNCTION_LPAREN); }
log_([0-9]+|[a-zA-Z])"*(" { returntoken(FUNCTION_LPAREN); }
...
...
tests/test_parser.py
View file @
dd699e45
...
@@ -102,6 +102,9 @@ class TestParser(RulesTestCase):
...
@@ -102,6 +102,9 @@ class TestParser(RulesTestCase):
self
.
assertEqual
(
*
tree
(
'[x ^ 2], x ^ 2'
))
self
.
assertEqual
(
*
tree
(
'[x ^ 2], x ^ 2'
))
self
.
assertEqual
(
*
tree
(
'[x ^ 2](x), x ^ 2 * x'
))
self
.
assertEqual
(
*
tree
(
'[x ^ 2](x), x ^ 2 * x'
))
self
.
assertEqual
(
*
tree
(
'{x}, x'
))
self
.
assertEqual
(
*
tree
(
'{x ^ 2}, x ^ 2'
))
def
test_derivative
(
self
):
def
test_derivative
(
self
):
x
=
tree
(
'x'
)
x
=
tree
(
'x'
)
...
...
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