Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
1.9 kB
2
Indexable
Never
FOR { printf("FOR\n");} { forStart(); } { pushScope(); } '(' StmtForList { printf("cool\n"); } ')' { forBody(); } '{' StmtList '}' { forEnd(); } { dumpScope(); }



StmtForList
    : StmtFor
    | VARIABLE_T IDENT ':' IDENT {
        setVarT(findVarType($4));
        createVNoT($<s_var>2, VAR_FLAG_DEFAULT);
        } {idFunc($4);}
;

StmtFor
    : InitFor ';' { ifExp = true; } EqaFor { ifExp = false; } ';' { forUpBegin(); } OptFor { forUpEnd(); }
;

InitFor
    : InitFor ',' IDENT {right = true;} VAL_ASSIGN ARG {
        createVNoT($<s_var>3, VAR_FLAG_DEFAULT);
        Object *variable = findVariable($<s_var>3);
        if (variable != NULL) {
            objectValueAssign(variable, &$<object_val>5, NULL);
        }
        assStore();
    }{right = false;}
    | IDENT {right = true;} VAL_ASSIGN ARG {
        createVNoT($<s_var>1, VAR_FLAG_DEFAULT);
        Object *variable = findVariable($<s_var>1);
        if (variable != NULL) {
            objectValueAssign(variable, &$<object_val>3, NULL);
        }
        assStore();
    }{right = false;}
    | VARIABLE_T IDENT {right = true;} VAL_ASSIGN ARG {
        setVarT($1);
        createVNoT($<s_var>2, VAR_FLAG_DEFAULT);
        Object *variable = findVariable($<s_var>2);
        if (variable != NULL) {
            objectValueAssign(variable, &$<object_val>4, NULL);
        }
        assStore();
    }{right = false;}
    |
;

EqaFor
    : { forCondBegin(); } Expression { forCondEnd(); }
    |
;

OptFor
    : Expression INC_ASSIGN { printf("INC_ASSIGN\n"); ippFunc(); }
    | Expression DEC_ASSIGN { printf("DEC_ASSIGN\n"); }
    | Expression SUB_ASSIGN { right = true; } Expression { printf("SUB_ASSIGN\n"); operGen("sub"); assStore(); } { right = false; }
    | Expression ADD_ASSIGN { right = true; } Expression { printf("ADD_ASSIGN\n"); operGen("add"); assStore(); } { right = false; }
    |
;
Leave a Comment