调整语法;

This commit is contained in:
Saturneric 2021-05-01 00:05:03 +08:00
parent a5d808cabc
commit 1714e6f560
4 changed files with 66 additions and 68 deletions

View File

@ -18,7 +18,8 @@ using std::endl;
int main() {
clock_t start,end;//¶¨Òåclock_t±äÁ¿
try {
clock_t start, end;//¶¨Òåclock_t±äÁ¿
start = clock(); //开始时间
const GrammarResourcePool *pool;
@ -36,8 +37,8 @@ int main() {
//输出时间
end = clock(); //结束时间
double times = double(end-start)/CLOCKS_PER_SEC;
wcout<<"LR1Generator Run time = "<< times <<"s MicroSeconds" << " = " << times * 1000 <<"ms" << endl;
double times = double(end - start) / CLOCKS_PER_SEC;
wcout << "LR1Generator Run time = " << times << "s MicroSeconds" << " = " << times * 1000 << "ms" << endl;
start = clock(); //开始时间
@ -49,8 +50,11 @@ int main() {
//输出时间
end = clock(); //结束时间
times = double(end-start)/CLOCKS_PER_SEC;
wcout<<"SyntaxParser Run time = "<<times<<"s MicroSeconds " << " = " << times * 1000 <<"ms" << endl;
times = double(end - start) / CLOCKS_PER_SEC;
wcout << "SyntaxParser Run time = " << times << "s MicroSeconds " << " = " << times * 1000 << "ms" << endl;
} catch(std::runtime_error &e) {
std::wcout << "Runtime Error: " << e.what() << endl;
}
return 0;
}

View File

@ -1,89 +1,89 @@
@struct_type -> "struct" "ID" "{" member_list "}" more_struct_type
@struct_type -> "STRUCT" "ID" "OPENING_BRACE" member_list "CLOSING_BRACE" more_struct_type
more_struct_type -> "EOF"
more_struct_type -> ε
member_list -> type_spec declarators ";" member_list
member_list -> type_spec declarators "SEMICOLON" member_list
member_list -> ε
type_spec -> base_type_spec
type_spec -> @struct_type
base_type_spec -> floating_pt_type
base_type_spec -> integer_type
base_type_spec -> "char"
base_type_spec -> "boolean"
floating_pt_type -> "float"
floating_pt_type -> "double"
floating_pt_type -> "long" "double"
base_type_spec -> "CHAR"
base_type_spec -> "BOOLEAN"
floating_pt_type -> "FLOAT"
floating_pt_type -> "DOUBLE"
floating_pt_type -> "LONG" "DOUBLE"
integer_type -> signed_int
integer_type -> unsigned_int
signed_int -> "short"
signed_int -> "int16"
signed_int -> "long"
signed_int -> "int32"
signed_int -> "long" "long"
signed_int -> "int64"
signed_int -> "int8"
signed_int -> "SHORT"
signed_int -> "INT16"
signed_int -> "LONG"
signed_int -> "INT32"
signed_int -> "LONG" "LONG"
signed_int -> "INT64"
signed_int -> "INT8"
unsigned_int -> "unsigned" "short"
unsigned_int -> "unsigned" "long"
unsigned_int -> "unsigned" "long" "long"
unsigned_int -> "uint16"
unsigned_int -> "uint32"
unsigned_int -> "uint64"
unsigned_int -> "uint8"
unsigned_int -> "UNSIGNED" "SHORT"
unsigned_int -> "UNSIGNED" "LONG"
unsigned_int -> "UNSIGNED" "LONG" "LONG"
unsigned_int -> "UINT16"
unsigned_int -> "UINT32"
unsigned_int -> "UINT64"
unsigned_int -> "UINT8"
declarators -> declarator more_declarators
more_declarators -> "," declarator more_declarators
more_declarators -> "COMMA" declarator more_declarators
more_declarators -> ε
declarator -> "ID" more_declarator
more_declarator -> exp_list
more_declarator -> ε
exp_list -> "[" or_expr more_or_expr "]"
more_or_expr -> "," or_expr more_or_expr
exp_list -> "LEFT_BRACKET" or_expr more_or_expr "RIGHT_BRACKET"
more_or_expr -> "COMMA" or_expr more_or_expr
more_or_expr -> ε
or_expr -> xor_expr more_xor_expr
more_xor_expr -> "|" xor_expr more_xor_expr
more_xor_expr -> "DELIMITER" xor_expr more_xor_expr
more_xor_expr -> ε
xor_expr -> and_expr more_and_expr
more_and_expr -> "^" and_expr more_and_expr
more_and_expr -> "INSERT" and_expr more_and_expr
more_and_expr -> ε
and_expr -> shift_expr more_shift_expr
more_shift_expr -> "&" shift_expr more_shift_expr
more_shift_expr -> "AND" shift_expr more_shift_expr
more_shift_expr -> ε
shift_expr -> add_expr more_add_expr
more_add_expr -> shift_sign add_expr more_add_expr
shift_sign -> ">>"
shift_sign -> "<<"
shift_sign -> "RIGHT_SHIFT"
shift_sign -> "LEFT_SHIFT"
more_add_expr -> ε
add_expr -> multi_expr more_multi_expr
more_multi_expr -> multi_sign multi_expr more_multi_expr
multi_sign -> "+"
multi_sign -> "-"
multi_sign -> "PLUS"
multi_sign -> "SUB"
more_multi_expr -> ε
multi_expr -> unary_expr more_unary_expr
more_unary_expr -> unary_sign unary_expr more_unary_expr
unary_sign -> "*"
unary_sign -> "/"
unary_sign -> "%"
unary_sign -> "MULT"
unary_sign -> "SLASH"
unary_sign -> "PERCENT"
more_unary_expr -> ε
unary_expr -> unary_sign_2 unary_declare
unary_sign_2 -> "-"
unary_sign_2 -> "+"
unary_sign_2 -> "~"
unary_sign_2 -> "SUB"
unary_sign_2 -> "PLUS"
unary_sign_2 -> "TILDE"
unary_sign_2 -> ε
unary_declare -> "INTEGER"
unary_declare -> "STRING"
unary_declare -> BOOLEAN
unary_declare -> BOOLEAN_VALUE
BOOLEAN -> "TRUE"
BOOLEAN -> "FALSE"
BOOLEAN_VALUE -> "TRUE"
BOOLEAN_VALUE -> "FALSE"

View File

@ -86,7 +86,7 @@ const std::set<int> *GrammarResourcePool::FOLLOW(int symbol) {
if(it != follows.end()) {
return it->second;
} else {
throw std::runtime_error("symbol NOT Found");
throw std::runtime_error("Symbol_Index" + std::to_string(symbol) + "NOT Found");
}
}

View File

@ -112,13 +112,7 @@ void SyntaxParser::getToken() {
auto token_info = get_token_info(tokens[i]);
int symbol_index;
if(token_info.first == L"ID"
|| token_info.first == L"EOF"
|| token_info.first == L"INTEGER"
|| token_info.first == L"STRING")
symbol_index = pool->getSymbolIndex(token_info.first);
else
symbol_index = pool->getSymbolIndex(token_info.second);
tokens_queue.push(symbol_index);
_line_index++;