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
1752a601
Commit
1752a601
authored
Feb 23, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started implementing function parsing.
parent
ab2c06a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
3 deletions
+47
-3
src/node.py
src/node.py
+2
-0
src/parser.py
src/parser.py
+45
-3
No files found.
src/node.py
View file @
1752a601
...
...
@@ -92,6 +92,8 @@ TOKEN_MAP = {
OP_REWRITE
:
'REWRITE'
,
}
FUNCTIONS
=
[
OP_SQRT
,
OP_SIN
,
OP_COS
,
OP_TAN
,
OP_INT
,
OP_SOLVE
]
def
to_expression
(
obj
):
return
obj
if
isinstance
(
obj
,
ExpressionBase
)
else
ExpressionLeaf
(
obj
)
...
...
src/parser.py
View file @
1752a601
...
...
@@ -307,6 +307,7 @@ class Parser(BisonParser):
"""
exp : NUMBER
| IDENTIFIER
| function
| LPAREN exp RPAREN
| unary
| binary
...
...
@@ -322,10 +323,13 @@ class Parser(BisonParser):
if
option
==
1
:
# rule: IDENTIFIER
return
Leaf
(
values
[
0
])
if
option
==
2
:
# rule: LPAREN exp RPAREN
if
option
==
2
:
# rule: function
return
values
[
0
]
if
option
==
3
:
# rule: LPAREN exp RPAREN
return
values
[
1
]
if
option
in
[
3
,
4
,
5
]:
# rule: unary | binary | nary
if
option
in
[
4
,
5
,
6
]:
# rule: unary | binary | nary
return
values
[
0
]
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
...
...
@@ -390,6 +394,45 @@ class Parser(BisonParser):
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
# pragma: nocover
def
on_function
(
self
,
target
,
option
,
names
,
values
):
"""
function : function_name LPAREN arglist RPAREN
"""
if
option
==
0
:
# rule: function_name LPAREN arglist RPAREN
print
'FUNCTION:'
,
values
[
0
],
values
[
2
]
return
Node
(
values
[
0
],
*
values
[
2
])
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
# pragma: nocover
def
on_function_name
(
self
,
target
,
option
,
names
,
values
):
"""
function_name : SQRT | SIN | COS | TAN | INT | SOLVE
"""
if
0
<=
option
<=
5
:
# rule: SQRT | SIN | COS | TAN | INT | SOLVE
return
values
[
0
]
#return TOKEN_OP_MAP[values[0]]
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
# pragma: nocover
def
on_arglist
(
self
,
target
,
option
,
names
,
values
):
"""
arglist : arglist COMMA exp
| exp
"""
if
option
==
0
:
# rule: arglist COMMA exp
return
values
[
0
]
+
[
values
[
2
]]
if
option
==
1
:
# rule: exp
return
[
values
[
0
]]
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
# pragma: nocover
# -----------------------------------------
# operator tokens
# -----------------------------------------
...
...
@@ -436,7 +479,6 @@ class Parser(BisonParser):
[a-zA-Z] { returntoken(IDENTIFIER); }
"(" { returntoken(LPAREN); }
")" { returntoken(RPAREN); }
"," { returntoken(COMMA); }
"""
+
operators
+
r"""
"raise" { returntoken(RAISE); }
"graph" { returntoken(GRAPH); }
...
...
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