コード例 #1
0
ファイル: lexer.c プロジェクト: ezhangle/recc
unsigned int t_filename(struct common_lexer_state * common_lexer_state, unsigned int tentative_position){
	unsigned int count = 0;
	while(accept_range('!', '+', common_lexer_state, tentative_position + count) || accept_range('-', ';', common_lexer_state, tentative_position + count) || accept_range('A', '_', common_lexer_state, tentative_position + count) || accept_range('a', '}', common_lexer_state, tentative_position + count)){
		count += 1;
	}
	return count;
}
コード例 #2
0
ファイル: lexer.c プロジェクト: chyyuu/recc
unsigned int t_l2_register(struct common_lexer_state * common_lexer_state, unsigned int tentative_position){
	unsigned int count = 0;
	if(accept('r', common_lexer_state, tentative_position + count)){
		count++;
		while(accept_range('0', '9', common_lexer_state, tentative_position + count)){
			count++;
		}
		if(count > 1){
			return count;
		}else{
			return 0;
		}
	}
	if(accept('F', common_lexer_state, tentative_position + count)){
		count++;
		if(accept('P', common_lexer_state, tentative_position + count) || accept('R', common_lexer_state, tentative_position + count)){
			count++;
			return count;
		}else{
			return 0;
		}
	}
	if(accept('P', common_lexer_state, tentative_position + count)){
		count++;
		if(accept('C', common_lexer_state, tentative_position + count)){
			count++;
			return count;
		}else{
			return 0;
		}
	}
	if(accept('S', common_lexer_state, tentative_position + count)){
		count++;
		if(accept('P', common_lexer_state, tentative_position + count)){
			count++;
			return count;
		}else{
			return 0;
		}
	}
	if(accept('Z', common_lexer_state, tentative_position + count)){
		count++;
		if(accept('R', common_lexer_state, tentative_position + count)){
			count++;
			return count;
		}else{
			return 0;
		}
	}
	if(accept('W', common_lexer_state, tentative_position + count)){
		count++;
		if(accept('R', common_lexer_state, tentative_position + count)){
			count++;
			return count;
		}else{
			return 0;
		}
	}
	return count;
}
コード例 #3
0
ファイル: lexer.c プロジェクト: chyyuu/recc
unsigned int t_comment(struct common_lexer_state * common_lexer_state, unsigned int tentative_position, unsigned int * current_line){
	unsigned int count = 0;
	if(accept('/', common_lexer_state, tentative_position + count) && accept('*', common_lexer_state, tentative_position + count + 1)){
		count += 2;
		while(1){
			if(accept('*', common_lexer_state, tentative_position + count)){
				count++;
				if(accept('/', common_lexer_state, tentative_position + count)){
					count++;
					return count;
				}
			}else{
				if(accept(0, common_lexer_state, tentative_position + count)){
					buffered_printf(common_lexer_state->buffered_output, "Unterminated comment.");
					return 0;
				}
				if(accept('\n', common_lexer_state, tentative_position + count)){
					*current_line = *current_line + 1;
				}else{
					accept_range(1,255, common_lexer_state, tentative_position + count);
				}
				count++;
			}
		}
	}
	return 0;
}
コード例 #4
0
ファイル: lexer.c プロジェクト: chyyuu/recc
unsigned int t_constant_string_part(struct common_lexer_state * common_lexer_state, unsigned int tentative_position){
	if(accept('"', common_lexer_state, tentative_position)){
		unsigned int count = 1;
		while(!accept('"', common_lexer_state, tentative_position + count)){
			if(accept('\\', common_lexer_state, tentative_position + count)){
				accept_range(1,255, common_lexer_state, tentative_position + count);
				count +=2;
			}else{
				if(accept_range(1,255, common_lexer_state, tentative_position + count)){
					count++;
				}else{
					buffered_printf(common_lexer_state->buffered_output, "Unexpected end of file in constant expression.");
					assert(0 && "Unexpected end of file in constant expression.");
				}
			}
		}
		count++;
		return count;
	}
	return 0;
}
コード例 #5
0
ファイル: lexer.c プロジェクト: chyyuu/recc
unsigned int t_constant_character(struct common_lexer_state * common_lexer_state, unsigned int tentative_position){
	if(accept('\'', common_lexer_state, tentative_position)){
		unsigned int count = 1;
		if(accept('\\', common_lexer_state, tentative_position + count)){
			accept_range(1,255, common_lexer_state, tentative_position + count);
			count +=2;
		}else{
			if(accept('\'', common_lexer_state, tentative_position + count)){
				buffered_printf(common_lexer_state->buffered_output, "Error in character constant.");
				return 0;
			}
			if(accept(0, common_lexer_state, tentative_position + count)){
				buffered_printf(common_lexer_state->buffered_output, "Unexpected end of file in constant expression.");
				return 0;
			}
			accept_range(1,255, common_lexer_state, tentative_position + count);
			count++;
		}
		while(!accept('\'', common_lexer_state, tentative_position + count)){
			if(accept('\\', common_lexer_state, tentative_position + count)){
				accept_range(1,255, common_lexer_state, tentative_position + count);
				count +=2;
			}else{
				if(accept(0, common_lexer_state, tentative_position + count)){
					buffered_printf(common_lexer_state->buffered_output, "Unexpected end of file in constant expression.");
					return 0;
				}
				accept_range(1,255, common_lexer_state, tentative_position + count);
				count++;
			}
		}
		count++;
		return count;
	}
	return 0;
}
コード例 #6
0
ファイル: lexer.c プロジェクト: chyyuu/recc
unsigned int t_l2_comment(struct common_lexer_state * common_lexer_state, unsigned int tentative_position){
	unsigned int count = 0;
	if(accept(';', common_lexer_state, tentative_position + count)){
		count++;
		while(1){
			unsigned int count_before = count;
			if(accept_range(32, 126, common_lexer_state, tentative_position + count)){
				count++;
			}
			if(accept('\t', common_lexer_state, tentative_position + count)){
				count++;
			}
			if(accept('\n', common_lexer_state, tentative_position + count)){
				break;
			}
			if(count_before == count){
				printf("Char is 0x%X\n", common_lexer_state->buf[tentative_position + count]);
				assert(0 && "Bad character in asm comment.");
			}
		}
	}
	return count;
}
コード例 #7
0
ファイル: lexer.c プロジェクト: chyyuu/recc
unsigned int t_H(struct common_lexer_state * common_lexer_state, unsigned int tentative_position){
	return accept_range('a','f', common_lexer_state, tentative_position) || accept_range('A','F', common_lexer_state, tentative_position) || accept_range('0','9', common_lexer_state, tentative_position);
}
コード例 #8
0
ファイル: lexer.c プロジェクト: chyyuu/recc
unsigned int t_L(struct common_lexer_state * common_lexer_state, unsigned int tentative_position){
	/*  Currently treating $ as a letter.  TODO: make this a compiler option. */
	return accept_range('a','z', common_lexer_state, tentative_position) || accept_range('A','Z', common_lexer_state, tentative_position) || accept('_', common_lexer_state, tentative_position) || accept('$', common_lexer_state, tentative_position);
}
コード例 #9
0
ファイル: lexer.c プロジェクト: ezhangle/recc
unsigned int t_L(struct common_lexer_state * common_lexer_state, unsigned int tentative_position){
	return accept_range('a','z', common_lexer_state, tentative_position) || accept_range('A','Z', common_lexer_state, tentative_position) || accept('_', common_lexer_state, tentative_position);
}
コード例 #10
0
ファイル: lexer.c プロジェクト: ezhangle/recc
unsigned int accept(unsigned char c, struct common_lexer_state * common_lexer_state, unsigned int tentative_position){
	return accept_range(c, c, common_lexer_state, tentative_position);
}