RACC examples

C

Charles Mills

How about a RACC-based parser for C/C++ expressions? It's mostly
complete, it works (I use it to translate from the Teja language which
embeds C++ expressions), but it may be too large.
I have done something like this for C only - I am going to release it
with a companion article soon...
Is your parser available to look at? Do you build a syntax tree?
-Charlie
 
J

Joel VanderWerf

Charles said:
I have done something like this for C only - I am going to release it
with a companion article soon...
Is your parser available to look at? Do you build a syntax tree?
-Charlie

It's bundled up in

http://PATH.Berkeley.EDU/~vjoel/mobies/teja2hsif/teja2hsif-0.1/

Look in the lib/teja/cparser dir. The nodes.rb, scanner.rb, and
parser.y.rb are the useful parts. There is also a shell.rb in the same
dir that uses readline to interactively parse expressions and show the tree:

expr> 1+4
= <AddOp>
op: "+"
left_expr: <Constant 1>
right_expr: <Constant 4>

expr> sin(*a[5]->b)
= <FnCall>
fn_expr: <Identifier sin>
arg_expr:
<UnOp>
op: "*"
expr: <DerefAccess>
this_expr: <Aref>
ary_expr: <Identifier a>
idx_expr: <Constant 5>
member_name: "b"

There are some limitations, due to the contstraints of the application:

-- no special attention to strings (no string literals)

-- no attention to declarations, control structures, function defs, etc.

It would be great if someone put together a complete C parser in RACC...

Anyway, I hope this is of some use to somebody.
 
C

Charles Mills

Charles said:
I have done something like this for C only - I am going to release it
with a companion article soon...
Is your parser available to look at? Do you build a syntax tree?
-Charlie

It's bundled up in

http://PATH.Berkeley.EDU/~vjoel/mobies/teja2hsif/teja2hsif-0.1/

Look in the lib/teja/cparser dir. The nodes.rb, scanner.rb, and
parser.y.rb are the useful parts. There is also a shell.rb in the same
dir that uses readline to interactively parse expressions and show the
tree:

expr> 1+4
= <AddOp>
op: "+"
left_expr: <Constant 1>
right_expr: <Constant 4>

expr> sin(*a[5]->b)
= <FnCall>
fn_expr: <Identifier sin>
arg_expr:
<UnOp>
op: "*"
expr: <DerefAccess>
this_expr: <Aref>
ary_expr: <Identifier a>
idx_expr: <Constant 5>
member_name: "b"

There are some limitations, due to the contstraints of the application:

-- no special attention to strings (no string literals)

-- no attention to declarations, control structures, function defs,
etc.

It would be great if someone put together a complete C parser in
RACC...

Anyway, I hope this is of some use to somebody.

It is, thanks!
-Charlie
 
P

Phil Tomson

How about a RACC-based parser for C/C++ expressions? It's mostly
complete, it works (I use it to translate from the Teja language which
embeds C++ expressions), but it may be too large.

Actually, that would be great as it's similar to something we're trying to
do with the Cardinal project: We want to be able to parse Ruby's C files
(array.c, hash.c, etc) and translate to Parrot assembly.

The only reason I asked for a small one was that I was just trying to
figure out how to use RACC.

Phil
 
P

Phil Tomson

I have done something like this for C only - I am going to release it
with a companion article soon...

Cool. We need something like this for the Cardinal project.
Where/when will your article appear?

Phil
 
L

Lennon Day-Reynolds

Actually, that would be great as it's similar to something we're trying to
do with the Cardinal project: We want to be able to parse Ruby's C files
(array.c, hash.c, etc) and translate to Parrot assembly.

Problem: We want Ruby to run on the Parrot VM
Solution: Write a C compiler that emits parrot bytecodes, and just
recompile the standard Ruby sources

You guys are nuts. Perhaps in a brilliant way, but crazy nonetheless.

Best of luck.
 
P

Phil Tomson

Problem: We want Ruby to run on the Parrot VM
Solution: Write a C compiler that emits parrot bytecodes, and just
recompile the standard Ruby sources

Well, that's not exactly the plan.

The problem we have is that we need all of the builtin libraries (those
coded in C - classes like Array, Hash, String, ...) to work with
Ruby/Parrot. So instead of hand-coding them all over in Parrot IMC (a
huge effort in itself), we're thinking of somehow parsing the Ruby/C to
translate it into IMC. Now it'll probably turn out that it takes us as
long as it would have to hand-translate, but it'll be a lot more interesting
and the resulting code will probably be useful for other projects besides
Cardinal.

A project for doing this has been started at:
http://rubyforge.org/projects/rubyclconv/

You guys are nuts. Perhaps in a brilliant way, but crazy nonetheless.

All the best stuff results from some crazy idea ;-)

Phil
 
G

gabriele renzi @ google

It would be great if someone put together a complete C parser in RACC...

I'm not really sure, but IIRC the RNA project on rubyforge has parsers
for Java,C. c++ and sql. I'm not sure this are full parsers cause RNA
is a code generation framework, but it may be of interest to you.
 

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

Similar Threads

racc error on new 1.9 hash syntax 7
racc 1.4.6 fails to install on windows 1
Racc fails on install 7
Fun with RACC examples 3
Can't install racc 2
Examples for racc? 11
Rex & Racc : howto? 9
Racc error recovery 4

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top