crowbar.l(Ver.0.3.02)

  1: %{
  2: #include <stdio.h>
  3: #include <string.h>
  4: #include "DBG.h"
  5: #include "crowbar.h"
  6: #include "y.tab.h"
  7: 
  8: int
  9: yywrap(void)
 10: {
 11:     return 1;
 12: }
 13: 
 14: static void
 15: increment_line_number(void)
 16: {
 17:     crb_get_current_interpreter()->current_line_number++;
 18: }
 19: %}
 20: %start COMMENT STRING_LITERAL_STATE
 21: %%
 22: <INITIAL>"function"     return FUNCTION;
 23: <INITIAL>"if"           return IF;
 24: <INITIAL>"else"         return ELSE;
 25: <INITIAL>"elsif"        return ELSIF;
 26: <INITIAL>"while"        return WHILE;
 27: <INITIAL>"for"          return FOR;
 28: <INITIAL>"return"       return RETURN_T;
 29: <INITIAL>"break"        return BREAK;
 30: <INITIAL>"continue"     return CONTINUE;
 31: <INITIAL>"null"         return NULL_T;
 32: <INITIAL>"true"         return TRUE_T;
 33: <INITIAL>"false"        return FALSE_T;
 34: <INITIAL>"closure"      return CLOSURE;
 35: <INITIAL>"global"       return GLOBAL_T;
 36: <INITIAL>"try"          return TRY;
 37: <INITIAL>"catch"        return CATCH;
 38: <INITIAL>"finally"      return FINALLY;
 39: <INITIAL>"("            return LP;
 40: <INITIAL>")"            return RP;
 41: <INITIAL>"{"            return LC;
 42: <INITIAL>"}"            return RC;
 43: <INITIAL>"["            return LB;
 44: <INITIAL>"]"            return RB;
 45: <INITIAL>";"            return SEMICOLON;
 46: <INITIAL>","            return COMMA;
 47: <INITIAL>"&&"           return LOGICAL_AND;
 48: <INITIAL>"||"           return LOGICAL_OR;
 49: <INITIAL>"="            return ASSIGN_T;
 50: <INITIAL>"=="           return EQ;
 51: <INITIAL>"!="           return NE;
 52: <INITIAL>">"            return GT;
 53: <INITIAL>">="           return GE;
 54: <INITIAL>"<"            return LT;
 55: <INITIAL>"<="           return LE;
 56: <INITIAL>"+"            return ADD;
 57: <INITIAL>"-"            return SUB;
 58: <INITIAL>"*"            return MUL;
 59: <INITIAL>"/"            return DIV;
 60: <INITIAL>"%"            return MOD;
 61: <INITIAL>"+="           return ADD_ASSIGN_T;
 62: <INITIAL>"-="           return SUB_ASSIGN_T;
 63: <INITIAL>"*="           return MUL_ASSIGN_T;
 64: <INITIAL>"/="           return DIV_ASSIGN_T;
 65: <INITIAL>"%="           return MOD_ASSIGN_T;
 66: <INITIAL>"++"           return INCREMENT;
 67: <INITIAL>"--"           return DECREMENT;
 68: <INITIAL>"!"            return EXCLAMATION;
 69: <INITIAL>"."            return DOT;
 70: <INITIAL>[A-Za-z_][A-Za-z_0-9]* {
 71:     yylval.identifier = crb_create_identifier(yytext);
 72:     return IDENTIFIER;
 73: }
 74: <INITIAL>[1-9][0-9]* {
 75:     Expression  *expression = crb_alloc_expression(INT_EXPRESSION);
 76:     sscanf(yytext, "%d", &expression->u.int_value);
 77:     yylval.expression = expression;
 78:     return INT_LITERAL;
 79: }
 80: <INITIAL>"0" {
 81:     Expression  *expression = crb_alloc_expression(INT_EXPRESSION);
 82:     expression->u.int_value = 0;
 83:     yylval.expression = expression;
 84:     return INT_LITERAL;
 85: }
 86: <INITIAL>[0-9]+\.[0-9]+ {
 87:     Expression  *expression = crb_alloc_expression(DOUBLE_EXPRESSION);
 88:     sscanf(yytext, "%lf", &expression->u.double_value);
 89:     yylval.expression = expression;
 90:     return DOUBLE_LITERAL;
 91: }
 92: <INITIAL>\" {
 93:     crb_open_string_literal();
 94:     BEGIN STRING_LITERAL_STATE;
 95: }
 96: <INITIAL>[ \t] ;
 97: <INITIAL>[ \t\n] {increment_line_number();}
 98: <INITIAL>#     BEGIN COMMENT;
 99: <INITIAL>.      {
100:     crb_compile_error(CHARACTER_INVALID_ERR,
101:                       CRB_CHARACTER_MESSAGE_ARGUMENT, "bad_char", yytext[0],
102:                       CRB_MESSAGE_ARGUMENT_END);
103: }
104: <COMMENT>\n     {
105:     increment_line_number();
106:     BEGIN INITIAL;
107: }
108: <COMMENT>.      ;
109: <STRING_LITERAL_STATE>\"        {
110:     Expression *expression = crb_alloc_expression(STRING_EXPRESSION);
111:     expression->u.string_value = crb_close_string_literal();
112:     yylval.expression = expression;
113:     BEGIN INITIAL;
114:     return STRING_LITERAL;
115: }
116: <STRING_LITERAL_STATE>\n        {
117:     crb_add_string_literal('\n');
118:     increment_line_number();
119: }
120: <STRING_LITERAL_STATE>\\\"      crb_add_string_literal('"');
121: <STRING_LITERAL_STATE>\\n       crb_add_string_literal('\n');
122: <STRING_LITERAL_STATE>\\t       crb_add_string_literal('\t');
123: <STRING_LITERAL_STATE>\\\\      crb_add_string_literal('\\');
124: <STRING_LITERAL_STATE>.         crb_add_string_literal(yytext[0]);
125: %%
戻る