parse.c
static void ParseDim(ParseContext *c)
{
    char name[MAXTOKEN];
    VMVALUE value = 0, size = 0;
    int isArray;
    int tkn;

    /* parse variable declarations */
    do {

        /* get variable name */
        isArray = ParseVariableDecl(c, name, &size);

        /* add to the global symbol table if outside a function definition */
        if (c->currentFunction == c->mainFunction) {
            Symbol *sym;

            /* get the address of the data */
            value = codeaddr(c->g);
            
            /* check for initializers */
            if ((tkn = GetToken(c)) == '=') {
                if (isArray)
                    ParseArrayInitializers(c, size);
                else
                    putdword(c->g, ParseScalarInitializer(c));
            }

            /* no initializers */
            else {
                ClearArrayInitializers(c, isArray ? size : 1);
                SaveToken(c, tkn);
            }

            /* add the symbol to the global symbol table */
            sym = AddGlobal(c, name, isArray ? SC_CONSTANT : SC_VARIABLE, &c->integerType, value);
            sym->placed = VMTRUE;
        }

        /* otherwise, add to the local symbol table */
        else {
            if (isArray)
                ParseError(c, "local arrays are not supported");
                
            /* add a local variable */
            AddLocal(c, name, SC_VARIABLE, &c->integerType, c->currentFunction->u.functionDefinition.localOffset);
            ++c->currentFunction->u.functionDefinition.localOffset;
            
            /* check for an initializer */
            if ((tkn = GetToken(c)) == '=') {
                ParseTreeNode *expr, *node;
            
                /* get the initializer */
                expr = ParseExpr(c);
                
                /* add code to set the initial value of the variable */
                node = NewParseTreeNode(c, NodeTypeLetStatement);
                node->u.letStatement.lvalue = GetSymbolRef(c, name);
                node->u.letStatement.rvalue = expr;
                AddNodeToList(c, &c->bptr->pNextStatement, node);
            }
        
            /* no initializer */
            else {
                SaveToken(c, tkn);
            }
                
        }

    } while ((tkn = GetToken(c)) == ',');

    Require(c, tkn, T_EOL);
}
/* ParseDim - parse the 'DIM' statement */
parse the 'DIM' statement
parse the ' DIM ' statement
static void ParseDim(ParseContext *c)
{
    char name[MAXTOKEN];
    VMVALUE value = 0, size = 0;
    int isArray;
    int tkn;
    do {
        isArray = ParseVariableDecl(c, name, &size);
        if (c->currentFunction == c->mainFunction) {
            Symbol *sym;
            value = codeaddr(c->g);
            if ((tkn = GetToken(c)) == '=') {
                if (isArray)
                    ParseArrayInitializers(c, size);
                else
                    putdword(c->g, ParseScalarInitializer(c));
            }
            else {
                ClearArrayInitializers(c, isArray ? size : 1);
                SaveToken(c, tkn);
            }
            sym = AddGlobal(c, name, isArray ? SC_CONSTANT : SC_VARIABLE, &c->integerType, value);
            sym->placed = VMTRUE;
        }
        else {
            if (isArray)
                ParseError(c, "local arrays are not supported");
            AddLocal(c, name, SC_VARIABLE, &c->integerType, c->currentFunction->u.functionDefinition.localOffset);
            ++c->currentFunction->u.functionDefinition.localOffset;
            if ((tkn = GetToken(c)) == '=') {
                ParseTreeNode *expr, *node;
                expr = ParseExpr(c);
                node = NewParseTreeNode(c, NodeTypeLetStatement);
                node->u.letStatement.lvalue = GetSymbolRef(c, name);
                node->u.letStatement.rvalue = expr;
                AddNodeToList(c, &c->bptr->pNextStatement, node);
            }
            else {
                SaveToken(c, tkn);
            }
        }
    } while ((tkn = GetToken(c)) == ',');
    Require(c, tkn, T_EOL);
}
static void ParseDim ( ParseContext * c ) { char name [ MAXTOKEN ] ; VMVALUE value = 0 , size = 0 ; int isArray ; int tkn ; do { isArray = ParseVariableDecl ( c , name , & size ) ; if ( c -> currentFunction == c -> mainFunction ) { Symbol * sym ; value = codeaddr ( c -> g ) ; if ( ( tkn = GetToken ( c ) ) == ' ' ) { if ( isArray ) ParseArrayInitializers ( c , size ) ; else putdword ( c -> g , ParseScalarInitializer ( c ) ) ; } else { ClearArrayInitializers ( c , isArray ? size : 1 ) ; SaveToken ( c , tkn ) ; } sym = AddGlobal ( c , name , isArray ? SC_CONSTANT : SC_VARIABLE , & c -> integerType , value ) ; sym -> placed = VMTRUE ; } else { if ( isArray ) ParseError ( c , " " ) ; AddLocal ( c , name , SC_VARIABLE , & c -> integerType , c -> currentFunction -> u . functionDefinition . localOffset ) ; ++ c -> currentFunction -> u . functionDefinition . localOffset ; if ( ( tkn = GetToken ( c ) ) == ' ' ) { ParseTreeNode * expr , * node ; expr = ParseExpr ( c ) ; node = NewParseTreeNode ( c , NodeTypeLetStatement ) ; node -> u . letStatement . lvalue = GetSymbolRef ( c , name ) ; node -> u . letStatement . rvalue = expr ; AddNodeToList ( c , & c -> bptr -> pNextStatement , node ) ; } else { SaveToken ( c , tkn ) ; } } } while ( ( tkn = GetToken ( c ) ) == ' ' ) ; Require ( c , tkn , T_EOL ) ; }
ParseDim - parse the 'DIM' statement
ParseDim - parse the ' DIM ' statement
/* parse variable declarations */ /* get variable name */ /* add to the global symbol table if outside a function definition */ /* get the address of the data */ /* check for initializers */ /* no initializers */ /* add the symbol to the global symbol table */ /* otherwise, add to the local symbol table */ /* add a local variable */ /* check for an initializer */ /* get the initializer */ /* add code to set the initial value of the variable */ /* no initializer */