How to write regex for c type inetger in lex? -


i trying write c parser code in lex

   %{      /* program job identifying c type integer , floats*/    %}    %%     [\t ]+      /* ignore whitespace */ ;     [0-9][5]+       { printf ("\"%s\" out of range \n", yytext); }    [-+][0-9][5]        { printf ("\"%s\" c integers\n", yytext); }    [-+]?[0-9]*\.?[0-9]+        { printf ("\"%s\" float\n", yytext); }     \n      echo; /* default anyway */    %% 

i facing problem in identifying c type integer because have limit i.e. 32767. have used regex i.e. digit length greater 5 in should yell "out of range" error it's hack , not perfect solution.

this might provably impossible right. regular expressions make simplistic kind of recognition (a state machine no memory), , tokenization/lexical analysis. you're trying use type-checking, requires lot more horsepower.

i'd save parser itself. far easier, symbol table filled in (to know kind of variable want assign to) , can check actual value of integer , compare upper , lower bounds.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -