[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Peter Suk

4/24/2005 9:06:00 PM

Folks,

I need help using Racc. I've been trying to go through the basic
calculator example, but no go. The grammar is processed without any
shift-reduce conflicts. It appears I am feeding the wrong kind of
tokens to it. I keep getting:


Parsing file:
/usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:377:in `on_error':
(Racc::ParseError)
parse error on value 1 (NUMBER) from
/usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:104:in
`_racc_do_parse_c'
from /usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:104:in
`__send__'
from /usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:104:in
`do_parse'
from racc-calc-2.y:47:in `parse'
from ruby_calc_test.rb:20


I am feeding it tokens that are two-element arrays, as stated in the
documentation. <http://i.loveruby.net/en/man/racc/parse... But it
is not at all clear what should be in the second element.


tokens = [ [ :NUMBER, 1 ],
[ :PLUS, "+" ],
[ :NUMBER, 2 ],
[ false, false ] ]


--Peter


--
There's neither heaven nor hell, save what we grant ourselves.
There's neither fairness nor justice, save what we grant each other.


-------- ruby_calc_test.rb --------
#!/usr/bin/ruby
require "FakeLexer"
require "RubyCalcParser"

## reuse the same parser object


p = RubyCalcParser.new
#p.yydebug = true
#p.yyerror = $stdout

print "Parsing file:\n"

tokens = [ [ :NUMBER, 1 ],
[ :PLUS, "+" ],
[ :NUMBER, 2 ],
[ false, false ] ]

p.lexer = FakeLexer.new(tokens)
print(p.parse.inspect)

print "\n"
-------- racc-calc-2.y --------
class RubyCalcParser


prechigh
left TIMES DIVIDE
left PLUS MINUS
preclow


token NUMBER PLUS MINUS TIMES DIVIDE LPAREN RPAREN


rule


exp: NUMBER { TestNumNode.new($1, "+") }
| exp PLUS exp { TestBinaryOpNode.new($1, "+", $3) }
| exp MINUS exp { TestBinaryOpNode.new($1, "-", $3) }
| exp TIMES exp { TestBinaryOpNode.new($1, "*", $3) }
| exp DIVIDE exp { TestBinaryOpNode.new($1, "/", $3) }
| LPAREN exp RPAREN { TestExpNode.new($2) }
| LPAREN error RPAREN { 1 } ## example error recovery--a bad
expression is interpreted as a 1
;

end # RubyCalcParser


---- header ----
require 'RubyCalcAst'

---- inner ----

def initialize
@ast = nil
end

attr_accessor :lexer ;

def parse()
return do_parse()
end

protected

def next_token
return @lexer.yylex()
end
-------- RubyCalcAst.rb --------
class TestNumNode
def initialize(num, sign)
@num = num
@sign = sign
end
end
class TestBinaryOpNode
def initialize(term1, op, term2)
@term1 = term1
@op = op
@term2 = term2
end
end
class TestExpNode
def initialize(exp)
@exp = exp
end
end
-------- FakeLexer.rb --------
require 'RubyCalcParser'

class FakeLexer

def initialize(tokens)
@tokens = tokens
@index = 0
end

def reset()
@index = 0
end

def yylex()
rval = @tokens[@index]
@index += @index
return rval
end

end
-------- end --------



5 Answers

Steven Jenkins

4/24/2005 11:30:00 PM

0

Peter Suk wrote:
> I need help using Racc. I've been trying to go through the basic
> calculator example, but no go. The grammar is processed without any
> shift-reduce conflicts. It appears I am feeding the wrong kind of
> tokens to it. I keep getting:
>
>
> Parsing file:
> /usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:377:in `on_error':
> (Racc::ParseError)
> parse error on value 1 (NUMBER) from
> /usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:104:in `_racc_do_parse_c'
> from /usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:104:in
> `__send__'
> from /usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:104:in
> `do_parse'
> from racc-calc-2.y:47:in `parse'
> from ruby_calc_test.rb:20

That means there's no rule that matches the input.

> I am feeding it tokens that are two-element arrays, as stated in the
> documentation. <http://i.loveruby.net/en/man/racc/parse... But it
> is not at all clear what should be in the second element.

Racc doesn't care. As long as the lexer and your productions agree on
the type (or on the duck-typing), it's OK.

Your understanding appears to be fine. You just have a simple bug--see
below.

> [snip]
> -------- FakeLexer.rb --------
> require 'RubyCalcParser'
>
> class FakeLexer
>
> def initialize(tokens)
> @tokens = tokens
> @index = 0
> end
>
> def reset()
> @index = 0
> end
>
> def yylex()
> rval = @tokens[@index]
> @index += @index

@index += 1

> return rval
> end
>
> end
> -------- end --------

It's returning two NUMBERS in a row, which is a syntax error in your
grammar.

Don't you love bugs like this? If you didn't suspect your understanding
of Racc, you'd probably have found in in two minutes. HTH.

Steve


Peter Suk

4/24/2005 11:38:00 PM

0


On Apr 24, 2005, at 6:30 PM, Steven Jenkins wrote:

> Your understanding appears to be fine. You just have a simple bug--see
> below.
>> def yylex()
>> rval = @tokens[@index]
>> @index += @index
>
> @index += 1
>
>> return rval
>> end

Doh!

--
There's neither heaven nor hell, save what we grant ourselves.
There's neither fairness nor justice, save what we grant each other.



Anonymous Coward

5/18/2007 12:46:00 AM

0

Vitor wrote:
> Some dumb guy wrote:
>> wow...
>>
>> Too bad this kind of investigative reporting will never reach a wide
>> audience.
>>
>> People are just too busy with important things like American Idol,
>> Survivor and who is going to check Paris Hilton's private parts (excuse
>> me... did I say private parts? I meant public parts) when she reports
>> for her jail time.
>
>
> I am not sure if the poll was advertised as scientific. Still many
> people weather republicans or not like Ron Paul. A good question and
> many would assume that those that participated giving Paul such high
> numbers would not likely vote for republicans or in a republican
> primary. How many of the leftist posters would actually vote for Paul
> over some Democrat? He is free to run and the Republicans have a
> diversity of ideas.
>
> I watched a good part of the debate and I am not really impressed with
> any of the candidates. They all kinda look the same none of them having
> a message I really like. I agree with Republican ideas and I don;t see
> any of them really pushing those ideas. I think one of them said
> something about ending departments but I can't put the person with the
> position.
>
> Mostly I am looking for leadership. The left hates Republicans and the
> responses I will get here will prove that so there is no point trying to
> get along or compromise with them.

With an attitude like that, I guess not.

We need to be as aggressive with our
> agenda as they are with theirs.

What do you mean "we" Kimosabe?

As long as we accept their premises and
> try to get along we will lose. Government only gets bigger the party is
> about how fast or slow. They say that Republicans are just lairs and
> cheats.

They're not very good spellers either.

Great if those leaders are throw them out and good leaders that
> will have leadership on those issues.

Bad grammar and sentence structure, also.

>
> The main thrust should be shrinking government. 79% is non-defense and
> departments can be cut and combine. Take the security agencies and cale
> down the bureaucracies and focus on the small percentage of people
> actually doing intel work.
>
> Have a legal way for people seeking work and employers to satisfy supply
> and demand and take the pressure of the border where only criminals will
> not cross over legal crossings.

Huh?

>
> Fight against the scare tactics of the environmental zealots. Allow us
> to meet our own demand with the resources we have. Basically get
> government out between employer and employee.

Yes, let's return to the day when a worker who got an arm ripped off on
the job was thrown out on his ass and good luck.

>
> Overall I we need to take the cost of government out the goods and
> services we buy. The government makes a greater profit off gas sold
> than any oil company.

Last I heard it was the government who builds, maintains and repairs the
roads, not the oil companies.

>
> There are conservative principles. They need to be expressed and that
> choice made available to those who desire that outcome.

I guess that leaves Bush out.

Makes you wonder how he ever got elected as a Republican to any office.

Kevin Cunningham

5/18/2007 2:12:00 PM

0


"Vitor" <none@yahoo.net> wrote in message
news:464cd34f$0$8914$4c368faf@roadrunner.com...
> Some dumb guy wrote:
>> wow...
>>
>> Too bad this kind of investigative reporting will never reach a wide
>> audience.
>>
>> People are just too busy with important things like American Idol,
>> Survivor and who is going to check Paris Hilton's private parts (excuse
>> me... did I say private parts? I meant public parts) when she reports for
>> her jail time.
>
>
> I am not sure if the poll was advertised as scientific. Still many people
> weather republicans or not like Ron Paul. A good question and many would
> assume that those that participated giving Paul such high numbers would
> not likely vote for republicans or in a republican primary. How many of
> the leftist posters would actually vote for Paul over some Democrat? He
> is free to run and the Republicans have a diversity of ideas.
>
> I watched a good part of the debate and I am not really impressed with any
> of the candidates. They all kinda look the same none of them having a
> message I really like. I agree with Republican ideas and I don;t see any
> of them really pushing those ideas. I think one of them said something
> about ending departments but I can't put the person with the position.
>
> Mostly I am looking for leadership. The left hates Republicans and the
> responses I will get here will prove that so there is no point trying to
> get along or compromise with them. We need to be as aggressive with our
> agenda as they are with theirs. As long as we accept their premises and
> try to get along we will lose. Government only gets bigger the party is
> about how fast or slow. They say that Republicans are just lairs and
> cheats. Great if those leaders are throw them out and good leaders that
> will have leadership on those issues.
>
> The main thrust should be shrinking government. 79% is non-defense and
> departments can be cut and combine. Take the security agencies and cale
> down the bureaucracies and focus on the small percentage of people
> actually doing intel work.
>
> Have a legal way for people seeking work and employers to satisfy supply
> and demand and take the pressure of the border where only criminals will
> not cross over legal crossings.
>
> Fight against the scare tactics of the environmental zealots. Allow us to
> meet our own demand with the resources we have. Basically get government
> out between employer and employee.
>
> Overall I we need to take the cost of government out the goods and
> services we buy. The government makes a greater profit off gas sold than
> any oil company.
>
> There are conservative principles. They need to be expressed and that
> choice made available to those who desire that outcome.

This assinine screed has one thing in its favor, at the end he claims that
his principles are conservative principles just like Guliani says that his
principles are conservative principles and McCain claims and Tancredo
claims.... on and on till infinity. What repgus won't say is my principles
resemble yours, lets talk. The repugs want a pure party, their purity,
their party. They don't want a big tent party full of all kind of thinkers,
they want ideological purity.

Sorta like their Nazi buddies.


Vitor

5/18/2007 8:20:00 PM

0

Kevin Cunningham wrote:
> "Vitor" <none@yahoo.net> wrote in message
> news:464cd34f$0$8914$4c368faf@roadrunner.com...
>> Some dumb guy wrote:
>>> wow...
>>>
>>> Too bad this kind of investigative reporting will never reach a wide
>>> audience.
>>>
>>> People are just too busy with important things like American Idol,
>>> Survivor and who is going to check Paris Hilton's private parts (excuse
>>> me... did I say private parts? I meant public parts) when she reports for
>>> her jail time.
>>
>> I am not sure if the poll was advertised as scientific. Still many people
>> weather republicans or not like Ron Paul. A good question and many would
>> assume that those that participated giving Paul such high numbers would
>> not likely vote for republicans or in a republican primary. How many of
>> the leftist posters would actually vote for Paul over some Democrat? He
>> is free to run and the Republicans have a diversity of ideas.
>>
>> I watched a good part of the debate and I am not really impressed with any
>> of the candidates. They all kinda look the same none of them having a
>> message I really like. I agree with Republican ideas and I don;t see any
>> of them really pushing those ideas. I think one of them said something
>> about ending departments but I can't put the person with the position.
>>
>> Mostly I am looking for leadership. The left hates Republicans and the
>> responses I will get here will prove that so there is no point trying to
>> get along or compromise with them. We need to be as aggressive with our
>> agenda as they are with theirs. As long as we accept their premises and
>> try to get along we will lose. Government only gets bigger the party is
>> about how fast or slow. They say that Republicans are just lairs and
>> cheats. Great if those leaders are throw them out and good leaders that
>> will have leadership on those issues.
>>
>> The main thrust should be shrinking government. 79% is non-defense and
>> departments can be cut and combine. Take the security agencies and cale
>> down the bureaucracies and focus on the small percentage of people
>> actually doing intel work.
>>
>> Have a legal way for people seeking work and employers to satisfy supply
>> and demand and take the pressure of the border where only criminals will
>> not cross over legal crossings.
>>
>> Fight against the scare tactics of the environmental zealots. Allow us to
>> meet our own demand with the resources we have. Basically get government
>> out between employer and employee.
>>
>> Overall I we need to take the cost of government out the goods and
>> services we buy. The government makes a greater profit off gas sold than
>> any oil company.
>>
>> There are conservative principles. They need to be expressed and that
>> choice made available to those who desire that outcome.
>
> This assinine screed has one thing in its favor, at the end he claims that
> his principles are conservative principles just like Guliani says that his
> principles are conservative principles and McCain claims and Tancredo
> claims.... on and on till infinity. What repgus won't say is my principles
> resemble yours, lets talk. The repugs want a pure party, their purity,
> their party. They don't want a big tent party full of all kind of thinkers,
> they want ideological purity.
>
> Sorta like their Nazi buddies.
>
>

You are just a hate filled bigot. Three are ideas out there and I am
looking for someone to provide leadership on those ideas. The ideas the
Paul advocates are primarily in the Democratic party.