Re: Adding block scopes to an assembly language

Derek Ross <d_ross@iders.mb.ca>
29 Apr 2000 23:53:06 -0400

          From comp.compilers

Related articles
Adding block scopes to an assembly language d_ross@iders.mb.ca (Derek Ross) (2000-04-27)
Re: Adding block scopes to an assembly language d_ross@iders.mb.ca (Derek Ross) (2000-04-29)
Re: Adding block scopes to an assembly language rhyde@shoe-size.com (Randall Hyde) (2000-04-29)
Re: Adding block scopes to an assembly language htak@eskimo.com (2000-05-01)
| List of all articles for this month |

From: Derek Ross <d_ross@iders.mb.ca>
Newsgroups: comp.compilers
Date: 29 Apr 2000 23:53:06 -0400
Organization: MBnet Networking Inc.
References: 00-04-206
Keywords: assembler, comment

Derek Ross wrote:


> I'm interested in giving block scopes to an assembly language, in
> particular for the ADSP2181 dsp.


John Wrote:
> [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:


MY_LABEL:
/* LABEL_COMMENT */
JUMP ANOTHER_LABEL;


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
another application.


Thank you,
--
Derek Ross
[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]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.