two more shift/reduces down, 8 to go

This commit is contained in:
Jeremy Ashkenas 2009-12-16 20:19:52 -05:00
parent 5ef10fce4c
commit 2753648d65
4 changed files with 480 additions and 449 deletions

View File

@ -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(); .

View File

@ -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

View File

@ -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)

914
parser.rb

File diff suppressed because it is too large Load Diff