From daed524c35f5fe4d35f403d2279947605d161b2e Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Mon, 10 Aug 2009 15:01:51 -0700 Subject: The build system knows how to deal with lex files, but it treats them as c++, so make spec.lex conform to that. --- libs/rs/spec.l | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 libs/rs/spec.l (limited to 'libs/rs/spec.l') diff --git a/libs/rs/spec.l b/libs/rs/spec.l new file mode 100644 index 0000000..62fcb63 --- /dev/null +++ b/libs/rs/spec.l @@ -0,0 +1,157 @@ +%option stack + +%x comment +%x api_entry +%x api_entry2 +%x api_entry_param +%x var_type + +DIGIT [0-9] +ID [a-zA-Z_][a-zA-Z0-9_]* + + #include "spec.h" + + int num_lines = 0; + + VarType *currType = 0; + + ApiEntry apis[128]; + int apiCount = 0; + + int typeNextState; + + extern "C" int yylex(); + +%% + +"/*" BEGIN(comment); +[^*\n]* /* eat anything that's not a '*' */ +"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ +\n ++num_lines; +"*"+"/" BEGIN(INITIAL); + +<*>" " //printf("found ' '\n"); +<*>"\n" ++num_lines; //printf("found lf \n"); + +{ID} { + memset(&apis[apiCount], 0, sizeof(ApiEntry)); + memcpy(apis[apiCount].name, yytext, yyleng); + BEGIN(api_entry); + } + +"{" { + BEGIN(api_entry2); + } + +"sync" { + apis[apiCount].sync = 1; + } + +"ret" { + currType = &apis[apiCount].ret; + typeNextState = api_entry2; + BEGIN(var_type); + } + +"param" { + currType = &apis[apiCount].params[apis[apiCount].paramCount]; + apis[apiCount].paramCount++; + typeNextState = api_entry_param; + BEGIN(var_type); + } + +"const" { + currType->isConst = 1; + } + +"i8" { + currType->type = 1; + currType->bits = 8; + BEGIN(typeNextState); + } + +"i16" { + currType->type = 1; + currType->bits = 16; + BEGIN(typeNextState); + } + +"i32" { + currType->type = 1; + currType->bits = 32; + BEGIN(typeNextState); + } + +"i64" { + currType->type = 1; + currType->bits = 64; + BEGIN(typeNextState); + } + +"u8" { + currType->type = 2; + currType->bits = 8; + BEGIN(typeNextState); + } + +"u16" { + currType->type = 2; + currType->bits = 16; + BEGIN(typeNextState); + } + +"u32" { + currType->type = 2; + currType->bits = 32; + BEGIN(typeNextState); + } + +"u64" { + currType->type = 2; + currType->bits = 64; + BEGIN(typeNextState); + } + +"f" { + currType->type = 3; + currType->bits = 32; + BEGIN(typeNextState); + } + +"d" { + currType->type = 3; + currType->bits = 64; + BEGIN(typeNextState); + } + +{ID} { + currType->type = 4; + currType->bits = 32; + memcpy(currType->typeName, yytext, yyleng); + BEGIN(typeNextState); + } + +"*" { + currType->ptrLevel ++; + } + +{ID} { + memcpy(currType->name, yytext, yyleng); + BEGIN(api_entry2); + } + + +"}" { + apiCount++; + BEGIN(INITIAL); + } + + +%% + + +int yywrap() +{ + return 1; +} + -- cgit v1.1