|Adding block scopes to an assembly language email@example.com (Derek Ross) (2000-04-27)|
|Re: Adding block scopes to an assembly language firstname.lastname@example.org (Derek Ross) (2000-04-29)|
|Re: Adding block scopes to an assembly language email@example.com (Randall Hyde) (2000-04-29)|
|Re: Adding block scopes to an assembly language firstname.lastname@example.org (2000-05-01)|
|From:||Derek Ross <email@example.com>|
|Date:||29 Apr 2000 23:53:06 -0400|
|Organization:||MBnet Networking Inc.|
Derek Ross wrote:
> I'm interested in giving block scopes to an assembly language, in
> particular for the ADSP2181 dsp.
> [Forget lex and yacc, since you already have a lexer and a parser.
> Adding simple block structure is not very hard. One way to do it is
> to tag each symbol with the block where it's defined. Keep a block
> counter and a stack of active blocks. On each BEGIN, increment the
> counter and push the incremented value on the active stack. On each
> END, pop the top entry from the stack. Whenever you define a symbol,
> store the block number on the top of the stack as the block where the
> symbol is defined. When looking up a symbol, search for the symbol
> with the block on the top of the stack, if not found with the next one
> on the stack, etc. until you run out of stack or find it. -John]
Wouldn't lex be necessary to parse through the file and find where
symbols are defined as opposed to referenced?
For example, in the following code:
/* LABEL_COMMENT */
MY_LABEL is a definition, but ANOTHER_LABEL is a reference to a label
which should be defined somewhere. JUMP is a keyword. And LABEL_COMMENT
should be ignored altogether. Somehow, the software has to distinguish
between all these.
BTW, the assembler is a commercial product, so the source code is not
available for me to modify. The addition of block scopes will require
[Ah, you want to do a preprocessor. In that case you might want to use
lex and yacc, but I'd be more inclined to do it in perl, which has string
matching about as good as lex, as well as built in features to do symbol
tables and the like. Also see subsequent messages about other assemblers
you might want to use or adapt. -John]
Return to the
Search the comp.compilers archives again.