lex

Download Lex

If you can't read please download the document

Upload: abhishekmahato

Post on 07-Feb-2016

212 views

Category:

Documents


0 download

DESCRIPTION

Lexical Analysis

TRANSCRIPT

%{static int c[32];extern FILE *yyin;extern FILE *yyout;#define IF 0#define ELSE 1#define AUTO 2#define DOUBLE 3#define INT 4#define STRUCT 5#define BREAK 6#define LONG 7#define SWITCH 8#define CASE 9#define ENUM 10 #define REGISTER 11#define TYPEDEF 12#define CHAR 13#define EXTERN 14#define RETURN 15#define UNION 16#define CONST 17#define FLOAT 18#define SHORT 19 #define UNSIGNED 20#define CONTINUE 21#define FOR 22#define STATIC 23#define VOID 24#define DEFAULT 25 #define GOTO 26#define SIZEOF 27#define VOLATILE 28#define DO 29#define SIGNED 30#define WHILE 31%}delim [ \t\n]ws {delim}+letter [A-Za-z]digit [0-9]id {letter}({letter}|{digit})*number {digit}+(\.{digit}+)?(E[+\-]?{digit}+)?%%{ws} {}if {count(IF);}else {count(ELSE);}auto {count(AUTO);}double {count(DOUBLE);}int {count(INT);}struct {count(STRUCT);}break {count(BREAK);}long {count(LONG);}switch {count(SWITCH);}case {count(CASE);}enum {count(ENUM);}register {count(REGISTER);}typedef {count(TYPEDEF);}char {count(CHAR);}extern {count(EXTERN);}return {count(RETURN);}union {count(UNION);}const {count(CONST);}float {count(FLOAT);}short {count(SHORT);}unsigned {count(UNSIGNED);}continue {count(CONTINUE);}for {count(FOR);}static {count(STATIC);}void {count(VOID);}default {count(DEFAULT);}goto {count(GOTO);}sizeof {count(SIZEOF);}volatile {count(VOLATILE);}do {count(DO);}signed {count(SIGNED);}while {count(WHILE);}{id} {}{number} {}"=" {}"(" {}")" {}";" {}%%count(int n){c[n]+=1;}main(int argc,char **argv){yyin = fopen("bitmap.c","r");yyout = fopen("output.txt","w");yylex();int i;for(i = 0;i