From 93179b90d8b1006001ce53310a6b01ba9f673fb7 Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Fri, 29 Sep 2023 16:40:36 +0200 Subject: New precedence test --- lib/expression_parser.messages | 360 ++++++++++++++++++++--------------------- lib/parser.mly | 2 +- lib/qsp_expression.mly | 3 +- lib/tokens.mly | 12 +- test/qsp_parser_test.ml | 58 ++++++- 5 files changed, 239 insertions(+), 196 deletions(-) diff --git a/lib/expression_parser.messages b/lib/expression_parser.messages index 5bcbd91..eaeec6c 100644 --- a/lib/expression_parser.messages +++ b/lib/expression_parser.messages @@ -25,11 +25,11 @@ main: LOCATION_START EOL L_PAREN INTEGER SET ## expression -> expression . MOD expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . GT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . LT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] +## expression -> expression . AND expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . GT EQUAL expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . LT EQUAL expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . EQUAL GT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . EQUAL LT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] -## expression -> expression . AND expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . OR expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## ## The known suffix of the stack is as follows: @@ -52,11 +52,11 @@ main: LOCATION_START EOL IF INTEGER SET ## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] +## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] -## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## line_statement -> IF expression . COLUMN nonempty_list(EOL) list(line_statement) elif_else_body END option(IF) nonempty_list(EOL) [ STAR SET PLUS OBJ NO MINUS L_PAREN LOCATION_END LITERAL LET KEYWORD INTEGER IF IDENT FUNCTION END ELSE ELIF COMMENT COLUMN ACT ] ## line_statement -> IF expression . COLUMN nonempty_list(EOL) list(line_statement) elif_else_body END option(IF) nonempty_list(AMPERSAND) list(EOL) [ STAR SET PLUS OBJ NO MINUS L_PAREN LOCATION_END LITERAL LET KEYWORD INTEGER IF IDENT FUNCTION END ELSE ELIF COMMENT COLUMN ACT ] @@ -94,11 +94,11 @@ main: LOCATION_START EOL ACT INTEGER SET ## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] +## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] -## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## line_statement -> ACT expression . COLUMN nonempty_list(EOL) list(line_statement) empty_body END option(ACT) nonempty_list(EOL) [ STAR SET PLUS OBJ NO MINUS L_PAREN LOCATION_END LITERAL LET KEYWORD INTEGER IF IDENT FUNCTION END ELSE ELIF COMMENT COLUMN ACT ] ## line_statement -> ACT expression . COLUMN nonempty_list(EOL) list(line_statement) empty_body END option(ACT) nonempty_list(AMPERSAND) list(EOL) [ STAR SET PLUS OBJ NO MINUS L_PAREN LOCATION_END LITERAL LET KEYWORD INTEGER IF IDENT FUNCTION END ELSE ELIF COMMENT COLUMN ACT ] @@ -189,10 +189,10 @@ main: LOCATION_START EOL IDENT AMPERSAND END ## ## Ends in an error in state: 175. ## -## main -> list(after_location) LOCATION_START nonempty_list(EOL) list(line_statement) . LOCATION_END [ # ] +## main -> list(before_location) LOCATION_START nonempty_list(EOL) list(line_statement) . LOCATION_END [ # ] ## ## The known suffix of the stack is as follows: -## list(after_location) LOCATION_START nonempty_list(EOL) list(line_statement) +## list(before_location) LOCATION_START nonempty_list(EOL) list(line_statement) ## ## WARNING: This example involves spurious reductions. ## This implies that, although the LR(1) items shown above provide an @@ -234,11 +234,11 @@ main: LOCATION_START EOL INTEGER SET ## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] +## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] -## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## single_instruction -> expression . [ EOL ELSE AMPERSAND ] ## @@ -263,11 +263,11 @@ main: LOCATION_START EOL IF IDENT COLUMN EOL ELIF INTEGER SET ## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] +## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] -## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## ## The known suffix of the stack is as follows: @@ -299,6 +299,18 @@ main: LOCATION_START EOL IF IDENT COLUMN EOL ELIF IDENT COLUMN EOL IDENT AMPERSA Unclosed `ELIF` block. +main: EOL STAR +## +## Ends in an error in state: 177. +## +## list(before_location) -> before_location . list(before_location) [ LOCATION_START ] +## +## The known suffix of the stack is as follows: +## before_location +## + +The context does not allow an instruction here. + main: LOCATION_START EOL R_PAREN ## ## Ends in an error in state: 7. @@ -398,45 +410,9 @@ main: LOCATION_START EOL IDENT STAR STAR -main: LOCATION_START EOL IDENT PLUS STAR -## -## Ends in an error in state: 29. -## -## expression -> expression PLUS . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression PLUS -## - - - -main: LOCATION_START EOL IDENT MOD STAR -## -## Ends in an error in state: 31. -## -## expression -> expression MOD . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression MOD -## - - - -main: LOCATION_START EOL IDENT MINUS STAR -## -## Ends in an error in state: 33. -## -## expression -> expression MINUS . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression MINUS -## - - - main: LOCATION_START EOL IDENT LT STAR ## -## Ends in an error in state: 35. +## Ends in an error in state: 39. ## ## expression -> expression LT . GT expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] ## expression -> expression LT . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] @@ -448,21 +424,9 @@ main: LOCATION_START EOL IDENT LT STAR -main: LOCATION_START EOL IDENT LT GT STAR -## -## Ends in an error in state: 36. -## -## expression -> expression LT GT . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression LT GT -## - - - main: LOCATION_START EOL IDENT GT STAR ## -## Ends in an error in state: 38. +## Ends in an error in state: 46. ## ## expression -> expression GT . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] ## expression -> expression GT . EQUAL expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] @@ -473,21 +437,9 @@ main: LOCATION_START EOL IDENT GT STAR -main: LOCATION_START EOL IDENT GT EQUAL STAR -## -## Ends in an error in state: 39. -## -## expression -> expression GT EQUAL . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression GT EQUAL -## - - - main: LOCATION_START EOL INTEGER EQUAL STAR ## -## Ends in an error in state: 43. +## Ends in an error in state: 51. ## ## expression -> expression EQUAL . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] ## expression -> expression EQUAL . GT expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] @@ -499,78 +451,6 @@ main: LOCATION_START EOL INTEGER EQUAL STAR -main: LOCATION_START EOL INTEGER EQUAL LT STAR -## -## Ends in an error in state: 44. -## -## expression -> expression EQUAL LT . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression EQUAL LT -## - - - -main: LOCATION_START EOL IDENT DIV STAR -## -## Ends in an error in state: 46. -## -## expression -> expression DIV . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression DIV -## - - - -main: LOCATION_START EOL INTEGER EQUAL GT STAR -## -## Ends in an error in state: 48. -## -## expression -> expression EQUAL GT . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression EQUAL GT -## - - - -main: LOCATION_START EOL IDENT LT EQUAL STAR -## -## Ends in an error in state: 52. -## -## expression -> expression LT EQUAL . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression LT EQUAL -## - - - -main: LOCATION_START EOL IDENT OR STAR -## -## Ends in an error in state: 55. -## -## expression -> expression OR . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression OR -## - - - -main: LOCATION_START EOL IDENT AND STAR -## -## Ends in an error in state: 57. -## -## expression -> expression AND . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression AND -## - - - main: LOCATION_START EOL KEYWORD L_PAREN INTEGER SET ## ## Ends in an error in state: 59. @@ -587,11 +467,11 @@ main: LOCATION_START EOL KEYWORD L_PAREN INTEGER SET ## expression -> expression . MOD expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COMA AND ] ## expression -> expression . GT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COMA AND ] ## expression -> expression . LT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COMA AND ] +## expression -> expression . AND expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COMA AND ] ## expression -> expression . GT EQUAL expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COMA AND ] ## expression -> expression . LT EQUAL expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COMA AND ] ## expression -> expression . EQUAL GT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COMA AND ] ## expression -> expression . EQUAL LT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COMA AND ] -## expression -> expression . AND expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COMA AND ] ## expression -> expression . OR expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COMA AND ] ## ## The known suffix of the stack is as follows: @@ -600,18 +480,6 @@ main: LOCATION_START EOL KEYWORD L_PAREN INTEGER SET -main: LOCATION_START EOL IDENT EXCLAMATION STAR -## -## Ends in an error in state: 41. -## -## expression -> expression EXCLAMATION . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] -## -## The known suffix of the stack is as follows: -## expression EXCLAMATION -## - - - main: LOCATION_START EOL KEYWORD IDENT COMA INTEGER SET ## ## Ends in an error in state: 63. @@ -626,11 +494,11 @@ main: LOCATION_START EOL KEYWORD IDENT COMA INTEGER SET ## expression -> expression . MOD expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . GT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . LT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] +## expression -> expression . AND expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . GT EQUAL expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . LT EQUAL expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . EQUAL GT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . EQUAL LT expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] -## expression -> expression . AND expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . OR expression [ STAR R_PAREN PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## separated_nonempty_list(COMA,expression) -> expression . [ R_PAREN EOL ELSE AMPERSAND ] ## separated_nonempty_list(COMA,expression) -> expression . COMA separated_nonempty_list(COMA,expression) [ R_PAREN EOL ELSE AMPERSAND ] @@ -689,11 +557,11 @@ main: LOCATION_START EOL IDENT L_BRACKET INTEGER SET ## expression -> expression . MOD expression [ STAR R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . GT expression [ STAR R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . LT expression [ STAR R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] +## expression -> expression . AND expression [ STAR R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . GT EQUAL expression [ STAR R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . LT EQUAL expression [ STAR R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . EQUAL GT expression [ STAR R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . EQUAL LT expression [ STAR R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] -## expression -> expression . AND expression [ STAR R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## expression -> expression . OR expression [ STAR R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV AND ] ## option(expression) -> expression . [ R_BRACKET ] ## @@ -748,11 +616,11 @@ main: LOCATION_START EOL SET IDENT DECR INTEGER SET ## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] +## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] -## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## let_assignation -> SET variable assignation_operator expression . [ EOL ELSE AMPERSAND ] ## @@ -819,11 +687,11 @@ main: LOCATION_START EOL LET IDENT DECR INTEGER SET ## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] +## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] -## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## let_assignation -> LET variable assignation_operator expression . [ EOL ELSE AMPERSAND ] ## @@ -958,11 +826,11 @@ main: LOCATION_START EOL IDENT DECR INTEGER SET ## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] +## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] -## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV AND AMPERSAND ] ## let_assignation -> variable assignation_operator expression . [ EOL ELSE AMPERSAND ] ## @@ -1047,11 +915,11 @@ main: LOCATION_START EOL KEYWORD INTEGER SET ## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] +## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] -## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA AND AMPERSAND ] ## qsp_instruction_argument(expression) -> expression . [ EOL ELSE AMPERSAND ] ## @@ -1221,11 +1089,11 @@ main: LOCATION_START EOL ACT IDENT COLUMN IF INTEGER SET ## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] +## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] -## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## onliner(IF) -> IF expression . COLUMN final_inline_instruction [ EOL ELSE AMPERSAND ] ## @@ -1261,11 +1129,11 @@ main: LOCATION_START EOL ACT IDENT COLUMN ACT INTEGER SET ## expression -> expression . MOD expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] +## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . GT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . LT EQUAL expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . EQUAL GT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . EQUAL LT expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] -## expression -> expression . AND expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## expression -> expression . OR expression [ STAR PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL DIV COLUMN AND ] ## onliner(ACT) -> ACT expression . COLUMN final_inline_instruction [ EOL ELSE AMPERSAND ] ## @@ -1380,26 +1248,14 @@ main: LOCATION_START EOL IF IDENT COLUMN EOL END IF STAR -main: EOL STAR -## -## Ends in an error in state: 177. -## -## list(after_location) -> after_location . list(after_location) [ LOCATION_START ] -## -## The known suffix of the stack is as follows: -## after_location -## - -The context does not allow an instruction here. - main: LOCATION_START STAR ## ## Ends in an error in state: 6. ## -## main -> list(after_location) LOCATION_START . nonempty_list(EOL) list(line_statement) LOCATION_END [ # ] +## main -> list(before_location) LOCATION_START . nonempty_list(EOL) list(line_statement) LOCATION_END [ # ] ## ## The known suffix of the stack is as follows: -## list(after_location) LOCATION_START +## list(before_location) LOCATION_START ## @@ -1408,10 +1264,10 @@ main: LOCATION_START EOL END ## ## Ends in an error in state: 9. ## -## main -> list(after_location) LOCATION_START nonempty_list(EOL) . list(line_statement) LOCATION_END [ # ] +## main -> list(before_location) LOCATION_START nonempty_list(EOL) . list(line_statement) LOCATION_END [ # ] ## ## The known suffix of the stack is as follows: -## list(after_location) LOCATION_START nonempty_list(EOL) +## list(before_location) LOCATION_START nonempty_list(EOL) ## ## WARNING: This example involves spurious reductions. ## This implies that, although the LR(1) items shown above provide an @@ -1450,10 +1306,154 @@ main: COMMENT STAR ## ## Ends in an error in state: 2. ## -## after_location -> COMMENT . EOL [ LOCATION_START EOL COMMENT ] +## before_location -> COMMENT . EOL [ LOCATION_START EOL COMMENT ] ## ## The known suffix of the stack is as follows: ## COMMENT ## + +main: LOCATION_START EOL IDENT MOD STAR +## +## Ends in an error in state: 29. +## +## expression -> expression MOD . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression MOD +## + + + +main: LOCATION_START EOL IDENT PLUS STAR +## +## Ends in an error in state: 31. +## +## expression -> expression PLUS . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression PLUS +## + + + +main: LOCATION_START EOL IDENT DIV STAR +## +## Ends in an error in state: 33. +## +## expression -> expression DIV . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression DIV +## + + + +main: LOCATION_START EOL IDENT OR STAR +## +## Ends in an error in state: 35. +## +## expression -> expression OR . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression OR +## + + + +main: LOCATION_START EOL IDENT MINUS STAR +## +## Ends in an error in state: 37. +## +## expression -> expression MINUS . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression MINUS +## + + + +main: LOCATION_START EOL IDENT LT GT STAR +## +## Ends in an error in state: 40. +## +## expression -> expression LT GT . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression LT GT +## + + + +main: LOCATION_START EOL IDENT EXCLAMATION STAR +## +## Ends in an error in state: 42. +## +## expression -> expression EXCLAMATION . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression EXCLAMATION +## + + + +main: LOCATION_START EOL IDENT LT EQUAL STAR +## +## Ends in an error in state: 44. +## +## expression -> expression LT EQUAL . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression LT EQUAL +## + + + +main: LOCATION_START EOL IDENT GT EQUAL STAR +## +## Ends in an error in state: 47. +## +## expression -> expression GT EQUAL . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression GT EQUAL +## + + + +main: LOCATION_START EOL INTEGER EQUAL LT STAR +## +## Ends in an error in state: 52. +## +## expression -> expression EQUAL LT . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression EQUAL LT +## + + + +main: LOCATION_START EOL INTEGER EQUAL GT STAR +## +## Ends in an error in state: 54. +## +## expression -> expression EQUAL GT . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression EQUAL GT +## + + + +main: LOCATION_START EOL IDENT AND STAR +## +## Ends in an error in state: 57. +## +## expression -> expression AND . expression [ STAR R_PAREN R_BRACKET PLUS OR MOD MINUS LT GT EXCLAMATION EQUAL EOL ELSE DIV COMA COLUMN AND AMPERSAND ] +## +## The known suffix of the stack is as follows: +## expression AND +## + + diff --git a/lib/parser.mly b/lib/parser.mly index a0a45e6..9b5297c 100644 --- a/lib/parser.mly +++ b/lib/parser.mly @@ -5,7 +5,7 @@ %parameter %start main -%on_error_reduce expression instruction +%on_error_reduce expression instruction binary_operator unary_operator %% diff --git a/lib/qsp_expression.mly b/lib/qsp_expression.mly index 3d758c4..06cfadd 100644 --- a/lib/qsp_expression.mly +++ b/lib/qsp_expression.mly @@ -36,7 +36,6 @@ op = binary_operator expr2 = expression { Analyzer.Expression.boperator $loc op expr1 expr2 } - %prec EQUAL | v = LITERAL { Analyzer.Expression.literal $loc v } | i = INTEGER { Analyzer.Expression.integer $loc i } | v = variable { Analyzer.Expression.ident v } @@ -64,11 +63,11 @@ unary_operator: | MOD { T.Mod } | GT { T.Gt } | LT { T.Lt } + | AND { T.And } | GT EQUAL { T.Gte } | LT EQUAL { T.Lte } | EQUAL GT { T.Gte } | EQUAL LT { T.Lte } - | AND { T.And } | OR { T.Or } (** Declare a variable, either in the assignation (let var = …) or as a diff --git a/lib/tokens.mly b/lib/tokens.mly index 1c199fa..9ac4b10 100644 --- a/lib/tokens.mly +++ b/lib/tokens.mly @@ -55,15 +55,17 @@ in favor of shifting. %right NO (* The priority for the variable should be lower than the equality priority if I want to allow declare new variables *) -%nonassoc p_variable -%left AND OR -%right EQUAL GT LT GTE LTE -%right EXCLAMATION +%left p_variable +%left OR +%left AND +%left EQUAL +%left GT LT +%left EXCLAMATION %left PLUS MINUS %left STAR DIV %left MOD %left FUNCTION -%left L_PAREN +%left L_PAREN %right R_PAREN %left COMA %left KEYWORD diff --git a/test/qsp_parser_test.ml b/test/qsp_parser_test.ml index 6ea9eab..d827099 100644 --- a/test/qsp_parser_test.ml +++ b/test/qsp_parser_test.ml @@ -256,18 +256,24 @@ let test_concat () = let content = {| $firstName + ' ' + $lastName |} in - let index = None in - let firstname = { Ast.pos = _position; name = "$FIRSTNAME"; index } - and lastName = { Ast.pos = _position; name = "$LASTNAME"; index } - and space = Ast.Literal (_position, " ") in _test_instruction content [ - Expression - (BinaryOp + Tree.Ast.Expression + (Tree.Ast.BinaryOp ( _position, Plus, - Ident firstname, - BinaryOp (_position, Plus, space, Ident lastName) )); + Tree.Ast.BinaryOp + ( _position, + Plus, + Tree.Ast.Ident + { + Tree.Ast.pos = _position; + name = "$FIRSTNAME"; + index = None; + }, + Tree.Ast.Literal (_position, " ") ), + Tree.Ast.Ident + { Tree.Ast.pos = _position; name = "$LASTNAME"; index = None } )); ] let test_comment () = _test_instruction "! Comment" [ Comment _position ] @@ -721,6 +727,40 @@ let test_mutiple_inline_ifs () = }; ] +let test_precedence7 () = + _test_instruction "(1 + 1 = '')" + [ + Tree.Ast.Expression + (Tree.Ast.BinaryOp + ( _position, + Eq, + Tree.Ast.BinaryOp + ( _position, + Plus, + Tree.Ast.Integer (_position, "1"), + Tree.Ast.Integer (_position, "1") ), + Tree.Ast.Literal (_position, "") )); + ] + +let test_precedence8 () = + _test_instruction "(0 = 1 or 0 = 1)" + [ + Tree.Ast.Expression + (Tree.Ast.BinaryOp + ( _position, + Or, + Tree.Ast.BinaryOp + ( _position, + Eq, + Tree.Ast.Integer (_position, "0"), + Tree.Ast.Integer (_position, "1") ), + Tree.Ast.BinaryOp + ( _position, + Eq, + Tree.Ast.Integer (_position, "0"), + Tree.Ast.Integer (_position, "1") ) )); + ] + let syntax = ( "Syntax", [ @@ -783,6 +823,8 @@ let syntax = Alcotest.test_case "Dyneval" `Quick test_dyneval; Alcotest.test_case "Input" `Quick test_input; Alcotest.test_case "inline if else if" `Quick test_mutiple_inline_ifs; + Alcotest.test_case "Precedence7" `Quick test_precedence7; + Alcotest.test_case "Precedence8" `Quick test_precedence8; ] ) let () = Alcotest.run "qsp_parser" [ syntax ] -- cgit v1.2.3