Esempio n. 1
0
SubprogramDeclarationsPtr Parser::parseSubprogramDeclarations()
{
    if (m_curToken.tokenType() != TokenType::Function && m_curToken.tokenType() != TokenType::Procedure) {
        return SubprogramDeclarationsPtr();
    }

    SubprogramDeclarationPtr declaration = parseSubprogramDeclaration();
    if (m_errorCode <= ErrorCodes::NoError) {
        if (!match(TokenType::Semicolon)) {
            reportError(ErrorCodes::ExpectedSemicolon);

            panic(subprogramDeclarationsFollow, subprogramDeclarationsFollowSize);
            return SubprogramDeclarationsPtr();
        }

        SubprogramDeclarationsPtr subprograms(new SubprogramDeclarations);
        subprograms->list.push_back(declaration);

        SubprogramDeclarationsPtr rest = parseSubprogramDeclarations();
        if (rest) {
            subprograms->list.insert(subprograms->list.end(), rest->list.begin(), rest->list.end());
        }

        return subprograms;
    }

    return SubprogramDeclarationsPtr();
}
Esempio n. 2
0
void block(char *name, int level) {
	LIST *S = (LIST*)malloc(sizeof(LIST));
    SYMBOL *tmp = NULL;
	/* initial block call */
	if(is_program_block == 1) {
		is_program_block = 0;

		if(token == TK_LBRAC) {
			debug(level,"BLOCK");
			push_scope(name);
			new_function(name, PROG);
			debug_lex(level+1);
			declerations(level+1);
			subprograms(level+1);
			
         	tmp = lookup(name);
         	tmp->func.genquad = qlabel;
			main_start_quad = qlabel;         
			
			genquad("begin_block", program_name, "_", "_");
			sequence(S, level+1);

			if(token == TK_RBRAC) {
				
				
				pop_scope();
				debug_lex();
			} else {
				/* syntax error lpar expected */
				syntax_error("a '}' expected");
			}
		} else {
			/* syntax error rpar expected */
			syntax_error("'{' expected");
		}
		backpatch(S->next, int2string(nextquad()));
		
		genquad("halt", "_", "_", "_");
		genquad("end_block", program_name, "_", "_");
		
		
	} else {

		if(token == TK_LBRAC) {
			debug(level,"BLOCK");
			
			debug_lex(level+1);

			declerations(level+1);
			subprograms(level+1);
            
            tmp = lookup(name);
            tmp->func.genquad = qlabel;

			genquad("begin_block", name, "_", "_");

            fprintf(stderr, "quad quad %s %d\n", tmp->name, tmp->func.genquad);
			
            sequence(S, level+1);
			
			if(token == TK_RBRAC) {
				
				if (!strcmp(assembly, "x86")) {
					generate_final_x86( program_name);
				} else {
					generate_final( program_name);
				}
				
				pop_scope();
				debug_lex();
			} else {
				/* syntax error lpar expected */
				syntax_error("a '}' expected");
			}
			
		} else {
			/* syntax error rpar expected */
			syntax_error("'{' expected");
		}
		backpatch(S->next, int2string(nextquad()));
		genquad("end_block", name,"_", "_");
	}
}