Start New Discussion within our Software Development Community

I am using this lex program to analyze the usage of each register, whether they are used as a source, a destination, or used as an indirect addressing, these are my codes, i have to analyze all 12 there any other efficient way to do these as oppose to declaring 36 variables, and 36 rules? (I am a student).

#include <stdio.h>

int q,w,e,r,t,y,u,i,o,p,a,s = 0;


[push|dec]?+[ ]+(eax|EAX)+[,] q++ ;
[,| ]+(eax|EAX)+[ ]? w++ ;
['[']+(eax|EAX)+[ ]? e++ ;
[push|dec]?+[ ]+(ebx|EBX)+[,] r++ ;
[,| ]+(ebx|EBX)+[ ]? t++ ;
['[']+(ebx|EBX)+[ ]? y++ ;
[push|dec]?+[ ]+(ecx|ECX)+[,] u++ ;
[,| ]+(ecx|ECX)+[ ]? i++ ;
['[']+(ecx|ECX)+[ ]? o++ ;
[push|dec]?+[ ]+(edx|EDX)+[,] p++ ;
[,| ]+(edx|EDX)+[ ]? a++ ;
['[']+(edx|EDX)+[ ]? s++ ;

. ;




yylex() ;

printf("EAX as source: %d\n", q) ;
printf("EAX as destination: %d\n", w) ;
printf("EAX as indirect address: %d\n", e) ;
printf("EBX as source: %d\n", r) ;
printf("EBX as destination: %d\n", t) ;
printf("EBX as indirect address: %d\n", y) ;
printf("ECX as source: %d\n", u) ;
printf("ECX as destination: %d\n", i) ;
printf("ECX as indirect address: %d\n", o) ;
printf("EDX as source: %d\n", p) ;
printf("EDX as destination: %d\n", a) ;
printf("EDX as indirect address: %d\n", s) ;

this is my output:

EAX as source: 56
EAX as destination: 71
EAX as indirect address: 0
EBX as source: 25
EBX as destination: 38
EBX as indirect address: 0
ECX as source: 26
ECX as destination: 30
ECX as indirect address: 0
EDX as source: 30
EDX as destination: 38
EDX as indirect address: 0
ubuntu@ubuntu:~$ ^C

The asm file is located here Click Here

PLease, is there any other efficient way to do this, at this rate, i have to type all 36 rules, and make 36 variables, and printf line...

I'll bump this question, it's two weeks old and still nobody's replied. You might have more luck posting this question on a forum with more focus on lex :)

This article has been dead for over six months. Start a new discussion instead.