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

G

George Ogata

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.rubyforge.org

Woof!
 
T

Tom Reilly

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
 
J

Jamis Buck

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
 
T

Tom Reilly

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?
 
L

Lyndon Samson

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

William Morgan

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. :)
 
T

Tom Reilly

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.
 
V

Ville Mattila

Tom Reilly said:
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
 
D

Daniel Berger

Tom said:
The version of Ruby running on both machines is Ruby 1.8.2
[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top