two more shift/reduces down, 8 to go
This commit is contained in:
parent
5ef10fce4c
commit
2753648d65
3
code.cs
3
code.cs
|
@ -110,3 +110,6 @@ case "Wednesday"
|
|||
go_to_work()
|
||||
eat_dinner()
|
||||
default go_to_work().
|
||||
|
||||
# Semicolons can optionally be used instead of newlines.
|
||||
wednesday: => eat_breakfast(); go_to_work(); eat_dinner(); .
|
|
@ -13,7 +13,7 @@ token SWITCH CASE DEFAULT
|
|||
token NEWLINE
|
||||
token JS
|
||||
|
||||
# Declare order of operations (mostly taken from Ruby).
|
||||
# Declare order of operations.
|
||||
prechigh
|
||||
nonassoc UMINUS NOT '!'
|
||||
left '*' '/' '%'
|
||||
|
@ -26,11 +26,12 @@ prechigh
|
|||
nonassoc IF
|
||||
left UNLESS
|
||||
right RETURN THROW FOR WHILE
|
||||
nonassoc "."
|
||||
preclow
|
||||
|
||||
# We expect 10 shift/reduce errors for optional syntax.
|
||||
# We expect 8 shift/reduce errors for optional syntax.
|
||||
# There used to be 252 -- greatly improved.
|
||||
expect 10
|
||||
expect 8
|
||||
|
||||
rule
|
||||
|
||||
|
|
5
nodes.rb
5
nodes.rb
|
@ -228,14 +228,13 @@ class OpNode < Node
|
|||
def compile(indent, scope, opts={})
|
||||
return compile_conditional(indent, scope) if CONDITIONALS.include?(@operator)
|
||||
return compile_unary(indent, scope) if unary?
|
||||
op = "#{@first.compile(indent, scope)} #{@operator} #{@second.compile(indent, scope)}"
|
||||
opts[:no_paren] ? op : "(#{op})"
|
||||
"#{@first.compile(indent, scope)} #{@operator} #{@second.compile(indent, scope)}"
|
||||
end
|
||||
|
||||
def compile_conditional(indent, scope)
|
||||
first, second = @first.compile(indent, scope), @second.compile(indent, scope)
|
||||
sym = @operator[0..1]
|
||||
"(#{first} = #{first} #{sym} #{second})"
|
||||
"#{first} = #{first} #{sym} #{second}"
|
||||
end
|
||||
|
||||
def compile_unary(indent, scope)
|
||||
|
|
Loading…
Reference in New Issue