Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | %option stack |
| 2 | |
| 3 | %x comment |
| 4 | %x api_entry |
| 5 | %x api_entry2 |
| 6 | %x api_entry_param |
| 7 | %x var_type |
| 8 | |
| 9 | DIGIT [0-9] |
| 10 | ID [a-zA-Z_][a-zA-Z0-9_]* |
| 11 | |
Joe Onorato | daed524 | 2009-08-10 15:01:51 -0700 | [diff] [blame] | 12 | #include "spec.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 13 | |
| 14 | int num_lines = 0; |
| 15 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 16 | VarType *currType = 0; |
| 17 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 18 | ApiEntry apis[128]; |
| 19 | int apiCount = 0; |
| 20 | |
| 21 | int typeNextState; |
| 22 | |
Joe Onorato | daed524 | 2009-08-10 15:01:51 -0700 | [diff] [blame] | 23 | extern "C" int yylex(); |
| 24 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 25 | %% |
| 26 | |
| 27 | "/*" BEGIN(comment); |
| 28 | <comment>[^*\n]* /* eat anything that's not a '*' */ |
| 29 | <comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ |
| 30 | <comment>\n ++num_lines; |
| 31 | <comment>"*"+"/" BEGIN(INITIAL); |
| 32 | |
| 33 | <*>" " //printf("found ' '\n"); |
| 34 | <*>"\n" ++num_lines; //printf("found lf \n"); |
| 35 | |
| 36 | {ID} { |
| 37 | memset(&apis[apiCount], 0, sizeof(ApiEntry)); |
| 38 | memcpy(apis[apiCount].name, yytext, yyleng); |
| 39 | BEGIN(api_entry); |
| 40 | } |
| 41 | |
| 42 | <api_entry>"{" { |
| 43 | BEGIN(api_entry2); |
| 44 | } |
| 45 | |
| 46 | <api_entry2>"sync" { |
| 47 | apis[apiCount].sync = 1; |
| 48 | } |
| 49 | |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 50 | <api_entry2>"handcodeApi" { |
| 51 | apis[apiCount].handcodeApi = 1; |
| 52 | } |
| 53 | |
| 54 | <api_entry2>"handcodePlay" { |
| 55 | apis[apiCount].handcodePlay = 1; |
| 56 | } |
| 57 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 58 | <api_entry2>"ret" { |
| 59 | currType = &apis[apiCount].ret; |
| 60 | typeNextState = api_entry2; |
| 61 | BEGIN(var_type); |
| 62 | } |
| 63 | |
| 64 | <api_entry2>"param" { |
| 65 | currType = &apis[apiCount].params[apis[apiCount].paramCount]; |
| 66 | apis[apiCount].paramCount++; |
| 67 | typeNextState = api_entry_param; |
| 68 | BEGIN(var_type); |
| 69 | } |
| 70 | |
| 71 | <var_type>"const" { |
| 72 | currType->isConst = 1; |
| 73 | } |
| 74 | |
| 75 | <var_type>"i8" { |
| 76 | currType->type = 1; |
| 77 | currType->bits = 8; |
| 78 | BEGIN(typeNextState); |
| 79 | } |
| 80 | |
| 81 | <var_type>"i16" { |
| 82 | currType->type = 1; |
| 83 | currType->bits = 16; |
| 84 | BEGIN(typeNextState); |
| 85 | } |
| 86 | |
| 87 | <var_type>"i32" { |
| 88 | currType->type = 1; |
| 89 | currType->bits = 32; |
| 90 | BEGIN(typeNextState); |
| 91 | } |
| 92 | |
| 93 | <var_type>"i64" { |
| 94 | currType->type = 1; |
| 95 | currType->bits = 64; |
| 96 | BEGIN(typeNextState); |
| 97 | } |
| 98 | |
| 99 | <var_type>"u8" { |
| 100 | currType->type = 2; |
| 101 | currType->bits = 8; |
| 102 | BEGIN(typeNextState); |
| 103 | } |
| 104 | |
| 105 | <var_type>"u16" { |
| 106 | currType->type = 2; |
| 107 | currType->bits = 16; |
| 108 | BEGIN(typeNextState); |
| 109 | } |
| 110 | |
| 111 | <var_type>"u32" { |
| 112 | currType->type = 2; |
| 113 | currType->bits = 32; |
| 114 | BEGIN(typeNextState); |
| 115 | } |
| 116 | |
| 117 | <var_type>"u64" { |
| 118 | currType->type = 2; |
| 119 | currType->bits = 64; |
| 120 | BEGIN(typeNextState); |
| 121 | } |
| 122 | |
| 123 | <var_type>"f" { |
| 124 | currType->type = 3; |
| 125 | currType->bits = 32; |
| 126 | BEGIN(typeNextState); |
| 127 | } |
| 128 | |
| 129 | <var_type>"d" { |
| 130 | currType->type = 3; |
| 131 | currType->bits = 64; |
| 132 | BEGIN(typeNextState); |
| 133 | } |
| 134 | |
| 135 | <var_type>{ID} { |
| 136 | currType->type = 4; |
| 137 | currType->bits = 32; |
Joe Onorato | daed524 | 2009-08-10 15:01:51 -0700 | [diff] [blame] | 138 | memcpy(currType->typeName, yytext, yyleng); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 139 | BEGIN(typeNextState); |
| 140 | } |
| 141 | |
| 142 | <api_entry_param>"*" { |
| 143 | currType->ptrLevel ++; |
| 144 | } |
| 145 | |
| 146 | <api_entry_param>{ID} { |
| 147 | memcpy(currType->name, yytext, yyleng); |
| 148 | BEGIN(api_entry2); |
| 149 | } |
| 150 | |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 151 | <api_entry2>"*" { |
| 152 | currType->ptrLevel ++; |
| 153 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 154 | |
| 155 | <api_entry2>"}" { |
| 156 | apiCount++; |
| 157 | BEGIN(INITIAL); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | %% |
| 162 | |
| 163 | |
| 164 | int yywrap() |
| 165 | { |
| 166 | return 1; |
| 167 | } |
| 168 | |