[Rubygrammar-grammarians] Ruby Grammar Project
Ryan Davis
ryand-ruby at zenspider.com
Sat Nov 26 15:46:23 EST 2005
On Nov 26, 2005, at 11:49 AM, Terence Parr wrote:
>> First:
>>
>> foo bar baz
>
> Which object is foo a method of? Is that the "main" thing I keep
> reading about? foo returns an object that bar is a method of?
>
>> (where foo and bar are method names) parses the same as:
>>
>> foo( bar( baz ) )
>
> Ah. So it calls bar(baz) first and then uses result as an arg to
> foo? That is very different from how'd I read it w/o the parens.
> Holy smokes.
Hey Terr, long time no email... It has been many many years.
I think I can help here. 1) yes, ruby has ties smalltalk, but nowhere
near the grammar side of things. You'll just have to let go of that.
It is much more of a loose java grammar than it is a smalltalk grammar.
2) I have tools to help this exploration process along quite easily:
509 % echo "foo bar baz" | parse_tree_show -f
(eval):1: warning: parenthesize argument(s) for future version
[[:class,
:Example,
:Object,
[:defn,
:example,
[:scope,
[:block,
[:args],
[:fcall, :foo, [:array, [:fcall, :bar, [:array,
[:vcall, :baz]]]]]]]]]]
This is in my package ParseTree, which you can easily install via
'sudo gem install -y ParseTree' assuming you have rubygems installed.
parse_tree_show displays ruby's internal AST (at the class/method
level) in a more digestible form. It doesn't do any parsing on it's
own. The '-f' part of it stands for fast-mode or fragment-mode and
lets you pipe in snippets of ruby w/o having a whole file/class/
method to play with.
---
I tried doing an LR2LL flip on ruby about 2 years ago and got
stymied. It wasn't nearly as easy as doing smalltalk and I can't keep
the whole grammar in my head. I've started working on a tool for
grammar exploration/experimentation (tentatively called yaccpuke or
GIT - grammar inspection toolkit). It hopes to do only a few things,
but do them well:
1) provide a simple DSL for describing grammars by hand ( from
smalltalk: bod [ uod | be ] )
2) ability to read in y.output (stripped grammar from yacc when run
w/ -v)
3) provide an interactive session (via irb) with api to explore and
manipulate grammar rules ( grammar.cycles? and grammar[:bod].replace
(:be))
I've got 1 & 2 down and am extending 3 right now. I'm hoping that
when this tool is done enough it'll provide me the extra brainpower
to do the LR2LL flip on ruby's yacc based grammar.
I haven't been tracking what you've been up to Terr. I stopped using
Antlr in the early v2 days (mostly because I stopped coding in java
and C++ as much as possible) so I don't know if you've done more work
in this area.
---
I should also point out the work being done by Don Roberts and John
Brant (of refactoring browser fame). They are working on a suite of
tools that can be taught a new language and then spit out a new
refactoring browser for that language. They said that in about a
month (about now actually) they'd be done with C# and able to work on
back-porting the system into squeak. They have a lot of experience in
this area and might want to bite off a chunk as well. At the very
least, the sooner we can get the grammar into a more digestible form,
the sooner we can have a feature-complete refactoring browser!
More information about the Rubygrammar-grammarians
mailing list