Am learning lex in this process, I'm generating tokens for the C language, and am trying to recognize single line comments "//", but am having a conflict with the division operator
[1-9][0-9]*|0x[0-9a-fA-F][0-9a-fA-F]* return NUMBER;
[a-zA-Z][a-zA-Z0-9]* return IDENT;
/ {return DIVIDE;}
[ \t\r\n]
[//]
But when am running the example and entering // it's recognizing them as 2 division operators. Where should I be modifying the code. Any suggestions.
Edit:
Lex Code:
%{
#include "y.tab.h"
%}
%array
%%
if {return IF;}
while {return WHILE;}
else {return ELSE;}
int {return INT;}
return {return RETURN;}
\/\/[^\r\n]*
[1-9][0-9]*|0x[0-9a-fA-F][0-9a-fA-F]* return NUMBER;
[a-zA-Z][a-zA-Z0-9]* return IDENT;
[+] {return ADD;}
[-] {return SUB;}
[<] {return LESS;}
[>] {return GREAT;}
[*] {return MULT;}
[/] {return DIVIDE;}
[;] {return SEMICOLON;}
\{ return LBRACE;
\} return RBRACE;
[ \t\r\n]
\( return LPAREN;
\) return RPAREN;
. return BADCHAR;
%%
The following is the header file I use
typedef enum {END=0, WHILE, IF, ELSE,RETURN, IDENT, LPAREN, RPAREN,INT,LBRACE,RBRACE, SEMICOLON, EQUALITY, DIVIDE, MULT, LESS, GREAT,
ADD, SUB, NUMBER,BADCHAR} Token;
The following is the input am running,
//
/
p
Token 16, text /
Token 16, text /
Token 16, text /
Token 5, text p
When am running it, comments are consumed and even the divide operator is ignored. But check when am entering p, it classifies the operators listed above, which it shouldn't be doing.
Note: Am trying to ignore tabs, newline characters and single line comments.
Note 2: \/\/[^\r\n]* I have understood where I committed the mistake and wanted to share this.