Question

I'm writing an assembler for a microprocessor I'm creating using lex/yacc.

I'd like to implement labels in my assembler code, and I thought a good way to do this would be to have a dictionary of labels in the form {name:line#}. I could then check when inserting a label, if it's already defined, its an error.

So how can I use a dictionary structure in lex/yacc?

Was it helpful?

Solution

Look at the various hash table implementations to find one you like.

OTHER TIPS

For labels? Create a structure with a file pointer, and initialise that to the position of the found label. And when you come across the label declaration, access that pointer and fill that blank with locctr.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top