From: Jeff Massung Date: 2004-04-15T02:14:13+09:00 Subject: Re: New Ruby questions... Simon Strandgaard wrote in news:pan.2004.04.13.22.41.09.300793@adslhome.dk: > On Tue, 13 Apr 2004 23:10:11 +0000, Jeff Massung wrote: > [snip] >> Quickly, the "teach myself" project is a simple ARM assembler. I've >> done it numerous times, and it is something I'm familiar and >> comfortable with (let alone something I need ATM). >> > > sounds interesting... BTW: are you to follow test-first paradigm? Hehe, of course. >> In the regular expression, how can I get it to find r10 or r11 >> instead of stopping at r1? I get the same problem with opcode >> mnemonics (like B instead of BX or BL). >> > > There is many ways to do this.. > > I can recommend you to read up on 'lexing'.. a phase where you > transform the sourcecode into tokens, where all whitespace is stripped > off. Then you have your registernames as you want them. That was my approach in C. Works fine, but using the regexp (so far), I've been able to slowly tackle away at a source line easily. Assembly is simple, but ARM assembly can be a little headache-ish to parse. For example, I've been able to: @source = "test: add r0,r1,r2" if (@source =~ /(\w+):\s+(.*)/) == 0 @label = $1 @source = $2 end And then continue on, with using regexp on the rest of @source (stripping the opcode from the operands), etc. It actually seems to be rather efficient (programmatically). Whether it is effecient processor-wise, at this point, I don't really care. I'm more learning that optimizing. :) > However you asked for regexp.. then you can place word-boundary > anchors around the registers. Also place the longest names first in > the alternation. But I rather recommend the lexing path. > registers = / \b (?: r10 | r11 | r12 | ... r0 | r1 | r2 ) \b /x I'll give that a try. > BTW: welcome to Ruby ;-) Thanks! And a hearty thanks to everyone else who replied. I was rather surprised at the time taken by everyone to explain the OOP concepts behind @ and @@ (I do know C++ very well, but the generosity of the community here was rather -- delightfully overwhelming) :) It appears all I really was "missing" was the concept that all code is always in a class, whether some overall Ruby class or one that I make myself. And that @@ is static. Lastly, though. @ is instance, @@ is static, and $ is global. What is nothing? x = 10 Where does x reside in namespace, etc? How do I access it? Is it considered just local to the current definition? Really, thanks all! -- Best regards, Jeff jma[at]mfire.com http://www.jm-basic.com