Ejemplo n.º 1
0
void
parse_msg()
{
    Token token;
    my_get_token(&token);
    char cls_name[MAX_TOKEN_SIZE];
    if (token.kind == STRING_TOKEN) {
        strcpy(cls_name, token.str);
        my_get_token(&token);
        if (token.kind == LEFT_PAREN_TOKEN) {
            my_get_token(&token);
            char title[1024];
            sprintf(title, "LCPB_%s = class(\"LCPB_%s\", LCProtoBase)\nfunction LCPB_%s:ctor(msgInput)\n\tlocal msg = msgInput or {}\n\tLCPB_%s.super.ctor(self, protoPack, \"%s\", msg)\n\tself.print = function()\n", cls_name, cls_name, cls_name, cls_name, cls_name);
            fputs(title, s_out_file);
            if (token.kind == RIGHT_PAREN_TOKEN) {
                fputs("\tend\nend\n\n", s_out_file);
                return;
            } else {
                while (token.kind != RIGHT_PAREN_TOKEN) {
                    unget_token(&token);
                    parse_expression();
                    my_get_token(&token);
                }
                fputs("\tend\nend\n\n", s_out_file);
                return;
            }
        } else {
            printf("no { next to cls name.\n");
            return;
        }
    } else {
        printf("no cls name next to message.\n");
        return;
    }
}
Ejemplo n.º 2
0
static double parse_primary_expression() {
	Token token;
	double value = 0.0;
	int minus_flag = 0;
	my_get_token(&token);

	if(token.kind == SUB_OPERATOR_TOKEN) {
		minus_flag = 1;
	} else {
		unget_token(&token);
	}

	my_get_token(&token);

	if(token.kind == NUMBER_TOKEN) {
		return token.value;
	} else if(token.kind == LEFT_PAREN_TOKEN) {
		value = parse_expression();
		my_get_token(&token);
		if(token.kind != RIGHT_PAREN_TOKEN) {
			fprintf(stderr, "missing ')' error.\n");
			exit(1);
		}
	} else {
		unget_token(&token);
	}

    if(minus_flag) {
    	value = -value;
    }

	return value;
}
Ejemplo n.º 3
0
void
parse(FILE *f_out)
{
    s_out_file = f_out;
    Token token;
    my_get_token(&token);
    if (!(token.kind == STRING_TOKEN && 0 == strcmp(token.str, "message"))) {
        printf("pb file not begin with \"message\"");
    }
    while (token.kind == STRING_TOKEN && 0 == strcmp(token.str, "message")) {
        parse_msg();
        my_get_token(&token);
    }
}
Ejemplo n.º 4
0
double
parse_expression()
{
    double v1;
    double v2;
    Token token;

    v1 = parse_term();
    for (;;) {
        my_get_token(&token);
        if (token.kind != ADD_OPERATOR_TOKEN 
            && token.kind != SUB_OPERATOR_TOKEN) {
            unget_token(&token);
            break;
        }
        v2 = parse_term();
        if (token.kind == ADD_OPERATOR_TOKEN) {
            v1 += v2;
        } else if (token.kind == SUB_OPERATOR_TOKEN) {
            v1 -= v2;
        } else {
            unget_token(&token);
        }
    }
    return v1;
}
Ejemplo n.º 5
0
static double parse_primary_expression() {
	Token token;
	my_get_token(&token);
	if(token.kind == NUMBER_TOKEN) {
		return token.value;
	}
	fprintf(stderr, "syntax error.\n");
	exit(1);
	return 0.0;
}
Ejemplo n.º 6
0
static double parse_term(){
    double v1;
    double v2;

    v1 = parse_primary_expresssion();
    for(;;){
         my_get_token(&token);
         if (token.kind != MUL_OPERATOR_TOKEN && token.kind != DIV_OPERATOR_TOKEN){
            unget_token(&token);
            break;
         }
         v2 = parse_primary_expresssion();
         if(token.kind == MUL_OPERATOR_TOKEN) {
              v1 *= v2;
         } else if (token.kind == DIV_OPERATOR_TOKEN) {
            v1 /= v2;
         }
    }
    return v1;
}
Ejemplo n.º 7
0
MSG
parse_expression()
{
    MSG msg;
    Token token;
    my_get_token(&token);
    if (token.kind == STRING_TOKEN) {
        msg.exsit = readRRO(token.str);
        if (msg.exsit != ERROR) {
            my_get_token(&token);
            if (token.kind == STRING_TOKEN) {
                strcpy(msg.var_type, token.str);
                my_get_token(&token);
                if (token.kind == STRING_TOKEN) {
                    strcpy(msg.var_name, token.str);
                    my_get_token(&token);
                    if (token.kind == EQUAL_TOKEN) {
                        my_get_token(&token);
                        if (token.kind == NUMBER_TOKEN) {
                            msg.index = token.value;
                            my_get_token(&token);
                            if (token.kind == SEMICOLON_TOKEN) {
                                outRRO(msg);
                                return msg;
                            } else {
                                printf("; error.\n");
                            }
                        } else {
                            printf("index error.\n");
                        }
                    } else {
                        printf("= error.\n");
                    }
                } else {
                    printf("var name error.\n");
                }
            } else {
                printf("type error.\n");
            }
        } else {
            printf("r,r,o error\n");
        }
    } else {
        printf("expression error.\n");
    }
    return msg;
}