lexer.l (1043B)
1 %option noyywrap 2 3 %{ 4 #include <stdio.h> 5 #include "script.h" 6 #include "op.h" 7 8 int fileno(FILE *stream); 9 #define YY_DECL int yylex() 10 11 #include "parser.tab.h" 12 13 %} 14 15 %% 16 17 [ \t] ; // ignore all whitespace 18 \n {return T_NEWLINE;} 19 20 \<[^\>]+\> { yylval.str = yytext; return T_EXAMPLE; } 21 22 \[[^\]]+\] { yylval.str = yytext; return T_EXAMPLE; } 23 24 #[^\n]* { return T_COMMENT; } 25 26 [oO][pP]_ {} 27 28 \"[^\"]*\" { 29 char *t = yytext + 1; 30 t[strlen(t) - 1] = '\0'; 31 yylval.str = t; 32 return T_STR; 33 } 34 35 0x[a-fA-F0-9]+ { 36 char * t = yytext + 2; 37 if (strlen(t) % 2 != 0) { 38 yylval.str = "Invalid raw string, it must have even length"; 39 return T_ERR; 40 } 41 yylval.str = t; 42 return T_RAW; 43 } 44 45 @[a-fA-F0-9]+ { 46 char *t = yytext + 1; 47 if (strlen(t) % 2 != 0) { 48 yylval.str = "Invalid data string, it must have even length"; 49 return T_ERR; 50 } 51 yylval.str = t; 52 return T_DATA; 53 } 54 55 -?[0-9]+ { 56 s64 i = strtoll(yytext, NULL, 10); 57 yylval.val = val_from_int(i); 58 return T_VAL; 59 } 60 61 [a-zA-Z0-9]+ { 62 yylval.opcode = op_tokenize(yytext); 63 return T_OP; 64 } 65 66 %%