Hey Guys

I'm working on a preprocessor for MASM and I've hit a small snag.
I want the parser to detect literal text contained in <> but they have multiple uses in MASM.



blah equ <literal>

.if ( eax < 1 ) || ( eax > 2 )

blah <this is a literal macro arg>


I could scan the rest of the line if I detect < but the above .if statement would be parsed wrong.
I could determine the keyword and then let the keyword handler parse the rest of the line but that wouldn't work for macros.

Any suggestions and/or obvious solutions are welcome.

Maelstrom
Posted on 2003-08-27 19:34:57 by Maelstrom
there may be a simple and elegant solution around, but rite now the things that comes to mind are "regular expressions"...because im reading the book "mastering regular expressions" :grin:

i can think of one simple solution: parse the '<' and '>' differently when they're inside the .const section, and differently when they're outside of it, like in that .if statement u have in your example

so basically u parse the .const section first, grab the literal text, create a hash of sorts using "blah" as the key and "literal" as the value (for fast lookups) then go on to the rest of the code after u're dun

that way whenever u encounter a '<' or a '>' outside of the .const sections, u will know that its not meant to be used as a constant...

of course u will have to make it so that the user isnt allowed to just randomly insert blah equ <literal> anywhere at all, but only inside of sections marked as '.const' or sumthing like that

and similarly for macro expansions
Posted on 2003-08-28 01:20:03 by AnotherWay83
perhaps you could just detect where the ">" or "<" is occuring,
if it is on the same line as an "if", then treat it as an expression,
otherwise it is a literal... etc.
Posted on 2003-08-28 03:31:10 by enjoy!
.if ( eax < FreakMacro(<_Linda_>)  ) || ( eax > 2 )
MASM can parse this too - scary. I think you'll have rebuild MASM.
Posted on 2003-08-28 08:35:13 by bitRAKE

.if ( eax < FreakMacro(<_Linda_>)  ) || ( eax > 2 )
MASM can parse this too - scary. I think you'll have rebuild MASM.

That's what happens when you give some of the best coders working for the world's largest and richest software company years and years to build on a parser, it grows to the point of being scary. I am not really surprised by the MASM parser anymore, I just type the line the way I want and assume that the parser will figure out what I meant :tongue:
Posted on 2003-08-28 08:47:38 by donkey
AnotherWay83
I'd prefer to be able to parse existing code without requiring the user to modify it, nice idea tho :alright:

enjoy!
I think your right, it's the only way I can currently think to do it.

bitRAKE
Nice curveball :grin: I didn't know MASM could parse that.

Maelstrom
Posted on 2003-08-28 17:09:22 by Maelstrom

.if ( eax < FreakMacro(<_Linda_>)  ) || ( eax > 2 )
MASM can parse this too - scary. I think you'll have rebuild MASM.
Doesn't look too hard. If there is no interpretation for a "unary <", the "unary <" is treated as a left bracket. It may require something more sophisticated than a string pattern match.
Posted on 2003-08-28 20:57:07 by tenkey