I am working with LEX and YACC. I have a question regarding how to define tokens, I mean I have two regular expressions which share some characters, see the example below:
SHARED "+"|"-"|"/"|"="|"%"|"?"|"!"|"."|"$"|"_"|"~"|"&"|"^"|"<"|">"|"("|")"|","
REXP_1 {SHARED}|[a-zA-Z]|[ \t]+|[\\][\\\"]
REXP_2 {SHARED}|[a-zA-Z]|[ \t]+|"*"
Now my point is how to identify when a character from the shared regular expression correspond to REXP_1 or REXP_2 when I define the tokens in the third section of the .lex file.
I think I am misunderstanding something, I guess that the way I write the regular expression is wrong but I do not find a way to put it in a better way. Could you please give me some hints?
More over I would appreciate if someone could advice me some criteria to determine when to define a token (file.lex) or when to define a symbol in the grammar(file.y). For some symbols it is easy to figure out if it is a token or a grammar symbol but for some others I find it difficult to define where to put them.
By the way I am working with this grammar
#define SHAREDto what you want it to be, then use it with the string pasting facilities. - tripleeeSHAREDcould be replaced with[/=%?!.$_~&^<>(),+-], then its not so huge so you could just include it in each regex. - OGHaza