Skip to content

Commit 736c65e

Browse files
committed
Change operations priority, fix args analyzing
1 parent 1ab03a2 commit 736c65e

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/analyzer/analyzer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ def _check_return_stat(self, statement):
6060
self._value_analyzer().validate(statement.value)
6161

6262
def _check_fun_call(self, statement):
63-
if statement.fun.undef:
64-
self._error().signature_not_found(statement.name, statement.args)
65-
6663
for arg in statement.args:
6764
self._value_analyzer().validate(arg)
6865

66+
if statement.fun.undef:
67+
self._error().signature_not_found(statement.name, statement.args)
68+
6969
def _check_if_stat(self, statement):
7070
self._value_analyzer().validate(statement.condition)
7171
self.validate(statement.then)

src/parser/grammar/SanyaScript.g4

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ value: cast value
5656
| '(' value ')' # parenthesizedValue
5757
| target=value '[' index=value ']' # indexValue
5858
| 'not' value # notValue
59+
| left=value operation=('/' | '*') right=value # divMultValue
60+
| left=value operation=('+' | '-') right=value # sumSubtrValue
5961
| left=value operation='and' right=value # andValue
6062
| left=value operation='or' right=value # orValue
6163
| left=value operation=('==' | '!=' | '>=' | '<=' | '>' | '<') right=value # comparisonValue
62-
| left=value operation=('/' | '*') right=value # divMultValue
63-
| left=value operation=('+' | '-') right=value # sumSubtrValue
6464
| '^' value # nodeValue
6565
| source=value arc target=value # arcValue
6666
| '[' graphPart? ']' # graphValue

test.sanya

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
graph g = [
2-
^1 -> ^2,
3-
^2 -> ^3,
4-
^1 -> ^5,
5-
^3 -> ^6,
6-
^0 -> ^-3
7-
]
8-
9-
node biggest_node(graph g) go
10-
node maxx = ^-9999
11-
12-
for node n in nodes(g) go
13-
if n > maxx go
14-
maxx = n
1+
arc max_arc(graph g) go
2+
num max_weight = -999999
3+
arc max_arc
4+
for arc a in arcs(g) go
5+
if (num) source(a) + (num) target(a) > max_weight go
6+
max_arc = a
7+
max_weight = (num) source(a) + (num) target(a)
158
end
169
end
1710

18-
return maxx
11+
return max_arc
1912
end
2013

21-
puts(biggest_node(a))
14+
graph g = [
15+
^1 -> ^2,
16+
^2 -> ^4,
17+
^3 -> ^6,
18+
^3 -> ^4,
19+
^1 -> ^3,
20+
^7 -> ^1
21+
]
22+
23+
puts(max_arc(g))

0 commit comments

Comments
 (0)