RACC examples

Anybody got a complete, working and not too large RACC example?

Phil

Hi,

ptkwt@aracnet.com (Phil Tomson) wrote:

Anybody got a complete, working and not too large RACC example?

Phil

Wiki clone "KakiWiki" uses Racc for parsing Wiki text.

http://raa.ruby-lang.org/project/kakiwiki/

Look at *.y files in src directory.

Takashi Sano

Phil Tomson wrote:

Anybody got a complete, working and not too large RACC example?

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.

It's based on the yacc grammar at

   ANSI C grammar (Yacc)

Phil Tomson wrote:

Anybody got a complete, working and not too large RACC example?

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

···

On Aug 25, 2004, at 12:01 PM, Joel VanderWerf wrote:

It's based on the yacc grammar at

  ANSI C grammar (Yacc)

In article <412CE1DF.6090203@path.berkeley.edu>,

···

Joel VanderWerf <vjoel@PATH.Berkeley.EDU> wrote:

Phil Tomson wrote:

Anybody got a complete, working and not too large RACC example?

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

Charles Mills wrote:

Phil Tomson wrote:

Anybody got a complete, working and not too large RACC example?

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

It's based on the yacc grammar at

  ANSI C grammar (Yacc)

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:

1+4

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

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.

···

On Aug 25, 2004, at 12:01 PM, Joel VanderWerf wrote:

In article <951CA418-F6CA-11D8-93A8-000A95A27A10@freeshell.org>,

···

Charles Mills <cmills@freeshell.org> wrote:

On Aug 25, 2004, at 12:01 PM, Joel VanderWerf wrote:

Phil Tomson wrote:

Anybody got a complete, working and not too large RACC example?

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

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

Phil

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.

···

On Thu, 26 Aug 2004 05:50:38 +0900, Phil Tomson <ptkwt@aracnet.com> wrote:

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.

--
Lennon
rcoder.net

It is, thanks!
-Charlie

···

On Aug 25, 2004, at 12:34 PM, Joel VanderWerf wrote:

Charles Mills wrote:

On Aug 25, 2004, at 12:01 PM, Joel VanderWerf wrote:

Phil Tomson wrote:

Anybody got a complete, working and not too large RACC example?

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

It's based on the yacc grammar at

  ANSI C grammar (Yacc)

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:

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

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

I don't want to get to far ahead of myself, but if all goes as planned it will appear here: http://www.codegeneration.net/
I will let you know the when part when I figure out when :slight_smile:
-Charlie

···

On Aug 25, 2004, at 1:50 PM, Phil Tomson wrote:

In article <951CA418-F6CA-11D8-93A8-000A95A27A10@freeshell.org>,
Charles Mills <cmills@freeshell.org> wrote:

On Aug 25, 2004, at 12:01 PM, Joel VanderWerf wrote:

Phil Tomson wrote:

Anybody got a complete, working and not too large RACC example?

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

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

In article <5d4c6124040825143014d13498@mail.gmail.com>,

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

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 :wink:

Phil

···

Lennon Day-Reynolds <rcoder@gmail.com> wrote:

On Thu, 26 Aug 2004 05:50:38 +0900, Phil Tomson <ptkwt@aracnet.com> wrote:

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.

Also, you could look at treecc:

http://www.southern-storm.com.au/treecc.html

It is an interesting 'aspect-oriented' approach to ast generation (its
written in C...under GPL), and it has a ruby generator!

-rich

···

On 8/26/04 6:30 AM, "gabriele renzi @ google" <surrender_it@yahoo.it> wrote:

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.