Пример #1
0
// Purpose: Tests the production rule for Declaration List
bool syntaxparser::DeclarationList(){
	bool bDeclarationList = false;
	if (displayFlag){
		cout <<endl<< "<DeclarationList> ::= <Declaration>;<DeclarationList>" << endl;
		printproduction("<DeclarationList> ::= <Declaration>;<DeclarationList>");
	}
	Declaration();

	//checks to see if next lexeme is a qualifier
	if(lexeme ==";"){
		Lexer();
		if(lexeme == "int" || lexeme == "boolean"){
			project3.addType(lexeme);
			Lexer();
			// if we have a semi colon then we recursively call for more additional declarations

			
			
			DeclarationList();
		}
		else if (lexeme == "real"){
			error("The 'real' type is not valid for Rat10F");
		}
	}
	else
		error("Missing ;");

	bDeclarationList = true;
	return bDeclarationList;
}
Пример #2
0
bool syntaxparser::OptDeclarationList(){
	bool OptDeclarationList=false;

	//checks to see if next lexeme is a qualifier
	if(lexeme == "int" || lexeme == "boolean"){
	
		if (displayFlag){
			cout<<endl<<"<OptDeclarationList> ::= <DeclarationList>"<<endl;
			printproduction("<OptDeclarationList> ::= <DeclarationList>");
		}
		OptDeclarationList = true;
		DeclarationList();
	}
	else if (lexeme == "real"){
		error("The 'real' type is not valid for Rat10F");
	}
	else{ // if no optional declaration list then its empty

		if (displayFlag){
			cout<<"<OptDeclarationList> ::= <Empty>"<<endl;
			printproduction("<OptDeclarationList> ::= <Empty>");
		}
		OptDeclarationList = true;
		Empty();
	}
	return OptDeclarationList;
}
Пример #3
0
Node* Parser::ExternalDecl() {
	Node* def = FunctionDefinitionStmt();
	
	if(def == NULL) {
		if(simple)
			return StatementList();

		return DeclarationList();
	}
	return def;
}
Пример #4
0
/* <Declaration List Prime> ::= <Declaration List> | epsilon */
void SyntaxAnalyzer::DeclarationListPrime()
{
	if(DeclarationList())
    {
		logger.Log("<Declaration List Prime> ::= <Declaration List>");
    }
	else // if(epsilon())
    {
		logger.Log("<Declaration List Prime> ::= epsilon");
    }
}
Пример #5
0
/* <Opt Declaration List> ::= <Declaration List> | epsilon */
void SyntaxAnalyzer::OptDeclarationList()
{
	if(DeclarationList())
    {
        logger.Log("<Opt Declaration List> ::= <Declaration List>");
    }
	else
    {
        // epsilon
        logger.Log("<Opt Declaration List> ::= epsilon");
    }
}
Пример #6
0
Node* Parser::DeclarationList() {
	Node *decl = Declaration();

	if(decl != NULL) {
		Node *link = DeclarationList();

		if(link == NULL) {
			return decl;
		}
		return new NodeStmt("<decl>", decl, link);
	}
	return NULL;
}
Пример #7
0
Node* Parser::CompoundStmt() {
	if(oper == FIGURE_LEFT_BRACKET) {
		Next();
		Node *decl = DeclarationList();
		Node *stmt = StatementList();

		if(oper != FIGURE_RIGHT_BRACKET)
			throw ParserException(currentToken, "Compound statement without '}'");
		else
			Next();
		
		return new NodeStmt("{stmt}", decl, stmt);
	}
	return NULL;
}
Пример #8
0
Node* Parser::Statement() {
	Node *link = NULL;
	
	if(simple)
		link = FunctionDefinitionStmt();

	if(link == NULL) link = CompoundStmt();
	if(link == NULL) link = ExpressionStmt();
	if(link == NULL) link = DeclarationList();
	if(link == NULL) link = SelectionStmt();
	if(link == NULL) link = IterationStmt();
	if(link == NULL) link = JumpStmt();
	if(link == NULL) link = PrintStmt();
	if(link == NULL) link = PauseStmt();
	if(link == NULL) link = LabelStmt();

	return link;
}