void TypeParser::parseIdentifier(Scanner &scanner, QStack<Info *> &stack, QString &array, bool in_array, bool &colon_prefix) {
    if (in_array) {
        array = scanner.identifier();
    } else if (colon_prefix || stack.top()->qualified_name.isEmpty()) {
        stack.top()->qualified_name << scanner.identifier();
        colon_prefix = false;
    } else {
        //stack.top()->qualified_name.last().append(" " + scanner.identifier());
        QString identifier = scanner.identifier();
        QString &name = stack.top()->qualified_name.last();

        bool set = false;
        if (identifier != "int") set = true;

        // TODO: this handles only one case
        if (name != "short" && !name.endsWith(" short")
                && name != "long" && !name.endsWith(" long")) {
            set = true;
        }

        if (set) name.append(" " + identifier);
    }
}
Example #2
0
int main(int argc, char *argv[])
{
	ifstream inFile;
	ofstream outFile;

	bool error;
	string input;
	
	vector<Token>TokenList;

	Scanner analyze;

	inFile.open(argv[1]);
	outFile.open(argv[2]);

	while(getline(inFile,input))
	{
		error=analyze.identifier(input);

		if(error==true)
		{
			analyze.initiateError(outFile);
			return 0;
		}
	}
	TokenList=analyze.tokenify();

	Parser parse(TokenList);

	try
	{
		parse.parse();
	}

	catch(string a)
	{
		Token temp=outputError(parse);
		outFile<<"Failure!"<<endl;
		outFile<<"  "<<"("<<temp.getChar()<<","<<"\""<<temp.getInfo()<<"\""<<","<<temp.fetchLineNum()<<")"<<endl;
		return 0;
	}
	
	parse.outToFile(outFile);
	return 0;
}