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
62e32ad5
Commit
62e32ad5
authored
Feb 24, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for function calls in parser.
parent
935b8061
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
src/parser.py
src/parser.py
+16
-2
No files found.
src/parser.py
View file @
62e32ad5
...
@@ -61,7 +61,9 @@ class Parser(BisonParser):
...
@@ -61,7 +61,9 @@ class Parser(BisonParser):
(
'left'
,
(
'COMMA'
,
)),
(
'left'
,
(
'COMMA'
,
)),
(
'left'
,
(
'MINUS'
,
'PLUS'
)),
(
'left'
,
(
'MINUS'
,
'PLUS'
)),
(
'left'
,
(
'TIMES'
,
'DIVIDE'
)),
(
'left'
,
(
'TIMES'
,
'DIVIDE'
)),
(
'left'
,
(
'EQ'
,
)),
(
'left'
,
(
'NEG'
,
)),
(
'left'
,
(
'NEG'
,
)),
(
'right'
,
(
'SIN'
,
'COS'
,
'TAN'
,
'SOLVE'
,
'INT'
,
'SQRT'
)),
(
'right'
,
(
'POW'
,
)),
(
'right'
,
(
'POW'
,
)),
)
)
...
@@ -334,6 +336,12 @@ class Parser(BisonParser):
...
@@ -334,6 +336,12 @@ class Parser(BisonParser):
def
on_unary
(
self
,
target
,
option
,
names
,
values
):
def
on_unary
(
self
,
target
,
option
,
names
,
values
):
"""
"""
unary : MINUS exp %prec NEG
unary : MINUS exp %prec NEG
| SIN exp
| COS exp
| TAN exp
| INT exp
| SOLVE exp
| SQRT exp
"""
"""
if
option
==
0
:
# rule: NEG exp
if
option
==
0
:
# rule: NEG exp
...
@@ -346,6 +354,11 @@ class Parser(BisonParser):
...
@@ -346,6 +354,11 @@ class Parser(BisonParser):
return
values
[
1
]
return
values
[
1
]
if
option
<
7
:
# rule: SIN exp | COS exp | TAN exp | INT exp
if
values
[
1
].
type
==
TYPE_OPERATOR
and
values
[
1
].
op
==
OP_COMMA
:
return
Node
(
values
[
0
],
*
values
[
1
])
return
Node
(
*
values
)
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
# pragma: nocover
%
(
option
,
target
))
# pragma: nocover
...
@@ -355,13 +368,14 @@ class Parser(BisonParser):
...
@@ -355,13 +368,14 @@ class Parser(BisonParser):
| exp TIMES exp
| exp TIMES exp
| exp DIVIDE exp
| exp DIVIDE exp
| exp POW exp
| exp POW exp
| exp EQ exp
| exp MINUS exp
| exp MINUS exp
"""
"""
if
0
<=
option
<
4
:
# rule: exp {PLUS,TIMES,DIVIDES,POW
} exp
if
0
<=
option
<
5
:
# rule: exp {PLUS,TIMES,DIVIDES,POW,EQ
} exp
return
Node
(
values
[
1
],
values
[
0
],
values
[
2
])
return
Node
(
values
[
1
],
values
[
0
],
values
[
2
])
if
option
==
4
:
# rule: exp MINUS exp
if
option
==
5
:
# rule: exp MINUS exp
node
=
values
[
2
]
node
=
values
[
2
]
# Add negation to the left-most child
# Add negation to the left-most child
...
...
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