code_junkie

Macro Replacement during Code Generation

Nov 12th, 2011
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. for(each line in the program)
  2. {
  3. for(each macro definition)
  4. {
  5. test if the macro appears;
  6. perform replacement if needed;
  7. }
  8. }
  9.  
  10. for(each line in the program)
  11. {
  12. tokenize the line;
  13. for(each token in the line)
  14. {
  15. switch(based on the token type)
  16. {
  17. case(an identifier)
  18. lookup the identifier in the table of macro names;
  19. perform replacement as necessary;
  20. ....
  21. }
  22. }
  23. }
  24.  
  25. int c = a + b
Add Comment
Please, Sign In to add comment