mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-23 04:15:31 +00:00
Updated grammar.
This commit is contained in:
parent
8b08ca3cca
commit
1ff6dc058b
@ -9,22 +9,22 @@ static auto g_grammar = R"(
|
|||||||
|
|
||||||
STATEMENTS <- (EXPRESSION (';' _)?)*
|
STATEMENTS <- (EXPRESSION (';' _)?)*
|
||||||
|
|
||||||
EXPRESSION <- ASSIGNMENT / PRIMARY
|
EXPRESSION <- ASSIGNMENT / LOGICAL_OR
|
||||||
ASSIGNMENT <- MUTABLE IDENTIFIER '=' _ EXPRESSION
|
ASSIGNMENT <- MUTABLE IDENTIFIER '=' _ EXPRESSION
|
||||||
WHILE <- 'while' _ EXPRESSION BLOCK
|
WHILE <- 'while' _ EXPRESSION BLOCK
|
||||||
IF <- 'if' _ EXPRESSION BLOCK ('else' _ 'if' _ EXPRESSION BLOCK)* ('else' _ BLOCK)?
|
IF <- 'if' _ EXPRESSION BLOCK ('else' _ 'if' _ EXPRESSION BLOCK)* ('else' _ BLOCK)?
|
||||||
FUNCTION_CALL <- IDENTIFIER ARGUMENTS
|
FUNCTION_CALL <- IDENTIFIER ARGUMENTS
|
||||||
ARGUMENTS <- '(' _ (EXPRESSION (', ' _ EXPRESSION)*)? ')' _
|
ARGUMENTS <- '(' _ (EXPRESSION (', ' _ EXPRESSION)*)? ')' _
|
||||||
|
|
||||||
PRIMARY <- LOGICAL_OR ('||' _ LOGICAL_OR)*
|
LOGICAL_OR <- LOGICAL_AND ('||' _ LOGICAL_AND)*
|
||||||
LOGICAL_OR <- LOGICAL_AND ('&&' _ LOGICAL_AND)*
|
LOGICAL_AND <- CONDITION ('&&' _ CONDITION)*
|
||||||
LOGICAL_AND <- CONDITION (CONDITION_OPERATOR CONDITION)*
|
CONDITION <- ADDITIVE (CONDITION_OPERATOR ADDITIVE)*
|
||||||
CONDITION <- TERM (TERM_OPERATOR TERM)*
|
ADDITIVE <- UNARY_PLUS (ADDITIVE_OPERATOR UNARY_PLUS)*
|
||||||
TERM <- UNARY_PLUS_OPERATOR? UNARY_PLUS
|
UNARY_PLUS <- UNARY_PLUS_OPERATOR? UNARY_MINUS
|
||||||
UNARY_PLUS <- UNARY_MINUS_OPERATOR? UNARY_MINUS
|
UNARY_MINUS <- UNARY_MINUS_OPERATOR? UNARY_NOT
|
||||||
UNARY_MINUS <- UNARY_NOT_OPERATOR? UNARY_NOT
|
UNARY_NOT <- UNARY_NOT_OPERATOR? MULTIPLICATIVE
|
||||||
UNARY_NOT <- FACTOR (FACTOR_OPERATOR FACTOR)*
|
MULTIPLICATIVE <- PRIMARY (MULTIPLICATIVE_OPERATOR PRIMARY)*
|
||||||
FACTOR <- WHILE / IF / FUNCTION / FUNCTION_CALL / ARRAY / ARRAY_REFERENCE / NUMBER / BOOLEAN / STRING / INTERPOLATED_STRING / IDENTIFIER / '(' _ EXPRESSION ')' _
|
PRIMARY <- WHILE / IF / FUNCTION / FUNCTION_CALL / ARRAY / ARRAY_REFERENCE / NUMBER / BOOLEAN / STRING / INTERPOLATED_STRING / IDENTIFIER / '(' _ EXPRESSION ')' _
|
||||||
|
|
||||||
FUNCTION <- 'fn' _ PARAMETERS BLOCK
|
FUNCTION <- 'fn' _ PARAMETERS BLOCK
|
||||||
PARAMETERS <- '(' _ (PARAMETER (',' _ PARAMETER)*)? ')' _
|
PARAMETERS <- '(' _ (PARAMETER (',' _ PARAMETER)*)? ')' _
|
||||||
@ -36,11 +36,11 @@ static auto g_grammar = R"(
|
|||||||
BLOCK <- '{' _ STATEMENTS '}' _
|
BLOCK <- '{' _ STATEMENTS '}' _
|
||||||
|
|
||||||
CONDITION_OPERATOR <- < ('==' / '!=' / '<=' / '<' / '>=' / '>') > _
|
CONDITION_OPERATOR <- < ('==' / '!=' / '<=' / '<' / '>=' / '>') > _
|
||||||
TERM_OPERATOR <- < [-+] > _
|
ADDITIVE_OPERATOR <- < [-+] > _
|
||||||
UNARY_PLUS_OPERATOR <- < '+' > _
|
UNARY_PLUS_OPERATOR <- < '+' > _
|
||||||
UNARY_MINUS_OPERATOR <- < '-' > _
|
UNARY_MINUS_OPERATOR <- < '-' > _
|
||||||
UNARY_NOT_OPERATOR <- < '!' > _
|
UNARY_NOT_OPERATOR <- < '!' > _
|
||||||
FACTOR_OPERATOR <- < [*/%] > _
|
MULTIPLICATIVE_OPERATOR <- < [*/%] > _
|
||||||
|
|
||||||
IDENTIFIER <- < [a-zA-Z_][a-zA-Z0-9_]* > _
|
IDENTIFIER <- < [a-zA-Z_][a-zA-Z0-9_]* > _
|
||||||
|
|
||||||
@ -91,14 +91,14 @@ peg& get_parser()
|
|||||||
{ "ARRAY", Array, false },
|
{ "ARRAY", Array, false },
|
||||||
{ "ARRAY_REFERENCE", ArrayReference, false },
|
{ "ARRAY_REFERENCE", ArrayReference, false },
|
||||||
{ "ARGUMENTS", Default, false },
|
{ "ARGUMENTS", Default, false },
|
||||||
{ "PRIMARY", LogicalOr, true },
|
{ "LOGICAL_OR", LogicalOr, true },
|
||||||
{ "LOGICAL_OR", LogicalAnd, true },
|
{ "LOGICAL_AND", LogicalAnd, true },
|
||||||
{ "LOGICAL_AND", Condition, true },
|
{ "CONDITION", Condition, true },
|
||||||
{ "CONDITION", BinExpresion, true },
|
{ "ADDITIVE", BinExpresion, true },
|
||||||
{ "TERM", UnaryPlus, true },
|
{ "UNARY_PLUS", UnaryPlus, true },
|
||||||
{ "UNARY_PLUS", UnaryMinus, true },
|
{ "UNARY_MINUS", UnaryMinus, true },
|
||||||
{ "UNARY_MINUS", UnaryNot, true },
|
{ "UNARY_NOT", UnaryNot, true },
|
||||||
{ "UNARY_NOT", BinExpresion, true },
|
{ "MULTIPLICATIVE", BinExpresion, true },
|
||||||
{ "NUMBER", Number, false },
|
{ "NUMBER", Number, false },
|
||||||
{ "BOOLEAN", Boolean, false },
|
{ "BOOLEAN", Boolean, false },
|
||||||
{ "IDENTIFIER", Identifier, false },
|
{ "IDENTIFIER", Identifier, false },
|
||||||
|
Loading…
Reference in New Issue
Block a user