I'm using Lex to do lexical analysis, in the below code when it gets to returning 1 (on the EOF rule), it quits with a segmentation fault.
Any idea whats causing this?
I don't actually need the 1 value, i just need the program generated to exit the subroute, keeping the two arrays in memory so they can be accessed by my parsing program.
any ideas?
thanks.
Code:
%{
#include <math.h>
#include <stdio.h>
/* codes for the different tokens */
#define MYEOF 0
#define IDENTIFIER 1
#define NUMBER 2
#define INTEGER 3
#define CHAR 4
int input[64]; /* buffer for holding the input */
char *input_value[64];
int count = 0; /*int to point to the next array location to be writen to*/
void Set_Arrays(int token, char *Value);
%}
%%
"int" {Set_Arrays(INTEGER, yytext);}
"char" {Set_Arrays(CHAR, yytext);}
"EOF" {Set_Arrays(MYEOF, yytext); return 1;}
[0-9]+ {Set_Arrays(NUMBER, yytext);}
[a-zA-Z][0-9a-zA-Z]* {Set_Arrays(IDENTIFIER, yytext);}
"(" {Set_Arrays('(', yytext);}
")" {Set_Arrays(')', yytext);}
"+" {Set_Arrays('+', yytext);}
"-" {Set_Arrays('-', yytext);}
"*" {Set_Arrays('*', yytext);}
"/" {Set_Arrays('/', yytext);}
"=" {Set_Arrays('=', yytext);}
";" {Set_Arrays(';', yytext);}
"{" {Set_Arrays('{', yytext);}
"}" {Set_Arrays('}', yytext);}
[ \t\n]+ {/* eat up white space */}
. {printf("Unrecognized character: %s\n", yytext);}
%%
void Set_Arrays(int token, char *value){
input[count] = token;
input_value[count] = value;
printf("Tokeen = %d \n", input[count]);
printf("Value = %s \n", input_value[count]);
count++;
}
yywrap() {} /* For Linux compatibility */