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
>>>
>>>   http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
>>>
>
> 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