[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[ANN] CAST -- Ruby's C parsing dog. Woof.

George Ogata

2/20/2005 6:28:00 PM


What Is
=======

CAST parses C code into an abstract syntax tree (AST), lets you break
it, then vomit it out as code. The parser does C99.

Library Overview
================

Everything is in the module C.

* There's the parser (Parser).
* There's the tree (Node and its subclasses).
* That's it.

Usage
-----

You call Parser#parse, and it gives you a tree of Node objects. Watch:

require 'cast/cast'

## create a parser
parser = C::Parser.new

## (optional) set some settings...
parser.pos.filename = "toy.c" # used for error messages
parser.type_names << 'LinkedList' # treat these words as types

## gimme a tree
ugly_c_code = open("toy.c"){|f| f.read}
tree = parser.parse(ugly_c_code)

## what's the tree look like?
puts tree.to_debug

If there's a parse error, #parse raises a ParseError (which has a nice
error message in #message).

.......................................................................

Keep reading: http://cast.rub...

Woof!
8 Answers

Tom Reilly

2/20/2005 11:28:00 PM

0

The folowing is a program from The Ruby Way page 441
#--------------------------------------
require 'net/http'

begin
h = Net::HTTP.new("www.ruby-lang.org",80)
resp, data = h.get("en/index.html",nil)
rescue => err
puts "error: #{err}"
exit
end

puts 'Received #{data.split.size} lines, #{data.size} bytes
#-------------------------------------

The program works fine on a Dell laptop running Windows 2000 professional

It will not work on a laptop using an AMD athlon processor running
Windows 2000 professional

Does anyone have a suggestion as to a fix?

Thanks





Jamis Buck

2/20/2005 11:40:00 PM

0

On 08:28 Mon 21 Feb , Tom Reilly wrote:
> The folowing is a program from The Ruby Way page 441
> #--------------------------------------
> require 'net/http'
>
> begin
> h = Net::HTTP.new("www.ruby-lang.org",80)
> resp, data = h.get("en/index.html",nil)
> rescue => err
> puts "error: #{err}"
> exit
> end
>
> puts 'Received #{data.split.size} lines, #{data.size} bytes
> #-------------------------------------
>
> The program works fine on a Dell laptop running Windows 2000 professional
>
> It will not work on a laptop using an AMD athlon processor running
> Windows 2000 professional

Can you be more specific? Do you get a raised exception? If so, what
is the exception? Also, what version of Ruby do you have running on
the AMD machine?

- Jamis

--
Jamis Buck
jamis_buck@byu.edu
http://jamis.jam...
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."



Tom Reilly

2/22/2005 1:53:00 AM

0

The version of Ruby running on both machines is Ruby 1.8.2 <2004-12-25>
[i386mswin32]

The program does not throw an exception. It just hangs. Also I've
tried going through network cards
of different manufacture and it makes no difference.
Also turning off the antivirus program and firewall programs make no
difference either.
Any recommendations as how go go about figuring out where it is hanging?

Jamis Buck wrote:

>On 08:28 Mon 21 Feb , Tom Reilly wrote:
>
>
>>The folowing is a program from The Ruby Way page 441
>>#--------------------------------------
>>require 'net/http'
>>
>>begin
>> h = Net::HTTP.new("www.ruby-lang.org",80)
>> resp, data = h.get("en/index.html",nil)
>>rescue => err
>> puts "error: #{err}"
>> exit
>>end
>>
>>puts 'Received #{data.split.size} lines, #{data.size} bytes
>>#-------------------------------------
>>
>>The program works fine on a Dell laptop running Windows 2000 professional
>>
>>It will not work on a laptop using an AMD athlon processor running
>>Windows 2000 professional
>>
>>
>
>Can you be more specific? Do you get a raised exception? If so, what
>is the exception? Also, what version of Ruby do you have running on
>the AMD machine?
>
>- Jamis
>
>
>



Lyndon Samson

2/22/2005 1:57:00 AM

0

Try and do something similar with a socket, see if that behaves the same way.


William Morgan

2/22/2005 1:13:00 PM

0

Excerpts from Tom Reilly's mail of 21 Feb 2005 (EST):
> Any recommendations as how go go about figuring out where it is hanging?

Put a "puts 'hello'" statement between each line, and count how many
before it hangs. :)

--
William <wmorgan-ruby-talk@masanjin.net>


Tom Reilly

2/25/2005 1:41:00 AM

0

Try and do something similar with a socket, see if that behaves the same
way.

I tried as suggested using the following program from the ruby book
#____________________________________________________________
require 'socket'

$port = 4321

sThread = Thread.start do # run server in a thread
server = UDPSocket.open
server.bind(nil, $port)
2.times { p server.recvfrom(64) }
end


# Connection based client
sock = UDPSocket.open
sock.connect('localhost', $port)
sock.send("connection-based", 0)
sThread.join

# Ad-hoc client
UDPSocket.open.send("ad hoc", 0, 'localhost', $port)
#____________________________________________________________

The program responds with:
["connection-based", ["AF_INET", 1133, "systemax", "127.0.0.1"]]
then hangs forever.

No exceptions.

Again the program responds as expected on the Dell

It would seem there is a problem in socket.so?
Ideas? THanks.




Ville Mattila

2/25/2005 5:55:00 AM

0

Tom Reilly <w3gat@nwlagardener.org> writes:

>
> No exceptions.
>
> Again the program responds as expected on the Dell
>
> It would seem there is a problem in socket.so?
> Ideas? THanks.

try to run your ruby script with -d option in other words, ruby -d script.rb
It will show if your threads are failing. -d option enables
Thread.abort_on_exception.

- Ville

djberg96

2/25/2005 3:59:00 PM

0

Tom Reilly wrote:
> The version of Ruby running on both machines is Ruby 1.8.2
<2004-12-25>
> [i386mswin32]
>
> The program does not throw an exception. It just hangs. Also I've
> tried going through network cards
> of different manufacture and it makes no difference.
> Also turning off the antivirus program and firewall programs make no
> difference either.
> Any recommendations as how go go about figuring out where it is
hanging?

I'm not positive, but I think Jean-Francois Nadeau's patch might fix
this. See ruby-core:3154.

I'd be interested to know myself.

Regards,

Dan