Ejemplo n.º 1
0
void FUNCTIONDEFINITION(void){
	/*functiondefinition = type ID ( idlist ) defstartsymbol statementlist defendsymbol*/
	switch (l){
	case KW_BOOLEAN: case KW_FLOAT: case KW_INT: case KW_VOID:						TYPE(); eat(ID); eat('('); IDLIST(); eat(')'); DEFSTARTSYMBOL(); STATEMENTLIST(); DEFENDSYMBOL(); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 2
0
void IDLIST(void){
	/*idlist = ID IDLIST_TAIL | epsilon*/
	switch(l){
	case ID:																		eat(ID);IDLIST_TAIL();return;
	case ')':																		return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 3
0
void RETURNSTATEMENT(void){
	/*returnstatement 	::= 	<KW_RETURN> returnstatements_assignment*/
	switch(l){

	case KW_RETURN:																	eat(KW_RETURN); RETURNSTATEMENTS_ASSIGNMENT(); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 4
0
void IFSTATEMENT(void){
	/*ifstatement 	::= 	<KW_IF> "(" assignment ")" block*/
	switch(l){

	case KW_IF:																		eat(KW_IF); eat('('); ASSIGNMENT(); eat(')'); BLOCK(); return;	/*expand parse tree with these 5 nodes, then expand the leftmost, then the next, ...*/
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 5
0
void POSITIVESIMPEXPR(void){
	/*positivesimpexpr = term positivesimpexpr_tail*/
	switch(l){

	case CONST_INT: case CONST_FLOAT: case CONST_BOOLEAN: case ID: case '(':		TERM(); POSITIVESIMPEXPR_TAIL();  return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 6
0
void TERM(void){
	/*term 	::= 	factor term_tail*/
	switch(l){

	case CONST_INT: case CONST_FLOAT: case CONST_BOOLEAN: case '(': case ID:		FACTOR(); TERM_TAIL(); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 7
0
void IDLIST_TAIL(void){
	/*idlist_tail = , ID IDLIST_TAIL | epsilon*/
	switch(l){
	case ',':																		eat(',');eat(ID);IDLIST_TAIL();return;
	case ')':																		return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 8
0
void PRINTF(void){
	/*printf 	::= 	<KW_PRINTF> "(" assignment ")"*/
	switch(l){

	case KW_PRINTF:																	eat(KW_PRINTF); eat('('); ASSIGNMENT(); eat(')'); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 9
0
void BLOCK(void){
	/*block = defstartsymbol statementlist defendsymbol | statement*/
	switch(l){

	case '{': case KW_BEGIN:														DEFSTARTSYMBOL(); STATEMENTLIST(); DEFENDSYMBOL(); return;
	case KW_IF: case KW_RETURN: case KW_PRINTF: case ID:							STATEMENT(); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 10
0
void STATEMENTLIST(void){
	/*STATEMENTLIST 	::= 	block statementlist | epsilon*/
	switch(l){

	case '{': case KW_BEGIN: case KW_IF: case KW_RETURN: case KW_PRINTF: case ID:	BLOCK(); STATEMENTLIST(); return;
	case '}': case KW_END:															return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 11
0
void ASSIGNMENTLIST_TAIL(void){
	/*assignmentlist = , assignment assignmentlist_tail | epsilon*/
	switch(l){

	case ',':																		eat(','); ASSIGNMENT(); ASSIGNMENTLIST_TAIL(); return;
	case ')':																		return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 12
0
void DEFENDSYMBOL(void){
	/*defendsymbol = } | KW_END*/
	switch(l){

	case '}':																		eat('}'); return;
	case KW_END:																	eat(KW_END);return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 13
0
void DEFSTARTSYMBOL(void){
	/*defstartsymbol = { | KW_BEGIN*/
	switch(l){

	case '{':																		eat('{'); return;
	case KW_BEGIN:																	eat(KW_BEGIN);return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 14
0
void RESTOF_STATICASSIGNMENT_OR_FUNCTIONCALL(void){
	/*restof_statassignment_or_functioncall 	::= 	"=" assignment | ( assignmentlist )*/
	switch(l){

	case '=':																		eat('='); ASSIGNMENT(); return;
	case KW_FLOAT:																	eat('('); ASSIGNMENTLIST(); eat(')'); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 15
0
void		TcpCSocket::waitForConnection(int timeout)
{
  struct pollfd	pollfd;
  int		ret;

  pollfd.fd = this->fd();
  pollfd.events = (POLLOUT);
  pollfd.revents = 0;
  if ((ret = poll(&pollfd, 1, timeout)) == -1)
    throw (StdError("TcpCSocket::connect(poll)"));
  if (ret == 0)
    {
      errno = ETIMEDOUT;
      throw (StdError());
    }
  if ((errno = this->getError()))
    throw (StdError("TcpCSocket::connect"));
}
Ejemplo n.º 16
0
void EXPR_TAIL(void){
	/*expr_tail = comparator simpexpr | epsilon*/
	switch(l){

	case EQ: case NEQ: case LEQ: case GEQ: case LSS: case GRT:						COMPARATOR(); SIMPEXPR(); return;
	case ')': case ';': case ',' /*follow(EXPR_TAIL)*/:								return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 17
0
void SIMPEXPR(void){
	/*simpexpr ::=  - positivesimpexpr | positivesimpexpr*/
	switch(l){

	case '-':																		eat('-'); POSITIVESIMPEXPR(); return;
	case CONST_INT: case CONST_FLOAT: case CONST_BOOLEAN: case ID: case '(':		POSITIVESIMPEXPR(); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 18
0
void EXPR(void){
	/*expr 	::= 	simpexpr expr_tail*/
	switch(l){

	case '-': case CONST_INT: case CONST_FLOAT: case CONST_BOOLEAN:
	case ID: case '(':																SIMPEXPR(); EXPR_TAIL(); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 19
0
void RESTOF_FUNCTIONCALL_OR_EPSILON(void){
	/*restof_functioncall_or_epsilon = ( assignmentlist ) | epsilon*/
	switch(l){

	case '(':																		eat('('); ASSIGNMENTLIST(); eat(')');  return;
	case '*': case '/': case AND: case '+': case '-': case OR: case LSS: case GRT:
	case LEQ: case GEQ: case EQ: case NEQ: case ')': case ';': case ',':			return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 20
0
void TERM_TAIL(void){
	/*term_tail = dotoperator term | epsilon*/
	switch(l){

	case '*': case '/': case AND:													DOTOPERATOR(); TERM(); return;
	case '+': case '-': case OR: case LSS: case GRT: case LEQ:
	case GEQ: case EQ: case NEQ: case ')': case ';': case ',':						return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 21
0
void ASSIGNMENTLIST(void){
	/*assignmentlist = assignment assignmentlist_tail | epsilon*/
	switch(l){

	case ID: case '-': case CONST_INT: case CONST_FLOAT:
	case CONST_BOOLEAN: case '(':													ASSIGNMENT(); ASSIGNMENTLIST_TAIL(); return;
	case ')':																		return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 22
0
void DOTOPERATOR(void){
	/*dotoperator ::= dotoperator = "*" | "/" | "&&"*/
	switch(l){

	case '*':																		eat('*');  return;
	case '/':																		eat('/'); return;
	case AND:																		eat(AND); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 23
0
void OPERATOR(void){
	/*operator ::= "+" | "-" | "||"*/
	switch(l){

	case '+':																		eat('+');  return;
	case '-':																		eat('-'); return;
	case OR:																		eat(OR); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 24
0
void POSITIVESIMPEXPR_TAIL(void){
	/*positivesimpexpr_tail = operator positivesimpexpr_tail | epsilon*/
	switch(l){

	case OR: case '+': case '-':													OPERATOR(); TERM(); POSITIVESIMPEXPR_TAIL(); return;
	case LSS: case GRT: case LEQ: case GEQ: case EQ: case NEQ:
	case ')': case ';': case ',':													return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 25
0
void RETURNSTATEMENTS_ASSIGNMENT(void){
	/*returnstatements_assignment :== assignment | epsilon*/
	switch(l){

	case ID: case '-':
	case CONST_INT: case CONST_FLOAT: case CONST_BOOLEAN: case '(':					ASSIGNMENT(); return;
	case ';':																		return;		/*apply rule 2. lookahead is in follow(returnstatements_assignment) = {;}*/
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 26
0
void COMPARATOR(void){
	/*comparator =      "==" | "!=" | "<=" | ">=" | "<" | ">"*/
	switch(l){

	case EQ:																		eat(EQ);  return;
	case NEQ:																		eat(NEQ); return;
	case LEQ:																		eat(LEQ); return;
	case GEQ:																		eat(GEQ); return;
	case LSS:																		eat(LSS); return;
	case GRT:																		eat(GRT); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 27
0
void ASSIGNMENT(void){
	/*assignment = id "=" assignment | expr*/
	/*Note that FIRST(id = assignment) and FIRST(EXPR) both contain ID*/
	switch(l){

	case '-': case CONST_INT: case CONST_FLOAT: case CONST_BOOLEAN: case '(':		EXPR(); return;
	case ID:																		if (l2 == '=')
																						{eat(ID); eat('='); ASSIGNMENT(); return;} /*expand according to rule 1*/
																					else /*note that EXPR can only derive into something that starts with an ID by deriving into id restof_functioncall_or_epsilon. Strings derived from the latter nonterminal either start with '(' or with something in FOLLOW(restof_functioncall_or_epsilon). The latter set does not contain =. It is '*'||'/'||AND||'+'||'-'||OR||LSS||GRT||LEQ||GEQ||EQ||NEQ||')'||';'||',').*/
																						{EXPR(); return;} /*rule 2*/
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 28
0
void PROGRAM(void){
	/*PROGRAM ::= FUNCTIONDEFINITION PROGRAM | eof*/
	switch (l){
	case KW_BOOLEAN: case KW_FLOAT: case KW_INT: case KW_VOID: {					/*expand the parse-tree node PROGRAM with the children (FUNCTIONDEFINITION, PROGRAM)*/
																					FUNCTIONDEFINITION(); PROGRAM(); return;
	}
	case EOF: {
																					eat(EOF);
																					/*Input is in the language. Terminating.*/
																					exit(0);
	}
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 29
0
void STATEMENT(void){
	/*statement 	::= 	ifstatement
		| 	returnstatement ";"
		| 	printf ";"
		| 	id restof_statassignment_or_functioncall ";"*/
	switch(l){

	case KW_IF:																		IFSTATEMENT(); return;
	case KW_RETURN:																	RETURNSTATEMENT(); eat(';'); return;
	case KW_PRINTF:																	PRINTF(); eat(';'); return;
	case ID:																		eat(ID); RESTOF_STATICASSIGNMENT_OR_FUNCTIONCALL(); eat(';'); return;
	default:																		StdError(__func__);
	}
}
Ejemplo n.º 30
0
void TYPE(void){
	/*type 	::= 	<KW_BOOLEAN>
	| 	<KW_FLOAT>
	| 	<KW_INT>
	| 	<KW_VOID>*/
	switch(l){

	case KW_BOOLEAN:																eat(KW_BOOLEAN); return;
	case KW_FLOAT:																	eat(KW_FLOAT); return;
	case KW_INT:																	eat(KW_INT); return;
	case KW_VOID:																	eat(KW_VOID); return;
	default:																		StdError(__func__);
	}
}