So, I'm trying to make a simple C parser in flex/bison, I only need to parse function and variable declarations, and its uses.
Example, using yyin = fopen() I want to parse this .c file:
#include <stdio.h>
int main()
{
int firstNumber, secondNumber, sumOfTwoNumbers;
printf("Enter two integers: ");
// Two integers entered by user is stored using scanf() function
scanf("%d %d", &firstNumber, &secondNumber);
// sum of two numbers in stored in variable sumOfTwoNumbers
sumOfTwoNumbers = firstNumber + secondNumber;
// Displays sum
printf("%d + %d = %d", firstNumber, secondNumber, sumOfTwoNumbers);
return 0;
}
The parser should detect
int firstNumber, secondNumber, sumOfTwoNumbers;
as variable declaration, and count every use of the variables.
I can already do that, the thing is, I just need to parse those specific cases, and not everything like the "=, +" tokens or //comments, but they can be in the file.
I want a way to be able to maybe, ignore every token but those that match a rule, so that yyparse doesn't call yyerror when it can't recognize a token, so the when the file is parsed I only do an action for function/var declaration and everything else just runs smoothly til the EOF.