diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-11-04 12:52:19 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-11-04 12:52:19 +0100 |
| commit | 0c49df8a68d47b5c42e1d28b43111c341b540145 (patch) | |
| tree | 7dd919ee2ec2269b5e8f40225a6ae3870aa4c89a | |
| parent | b3ca325dd0c75ec8e779f1cdd31fa54df4aab090 (diff) | |
feat(tree): support parenthesis
| -rw-r--r-- | example/input.txt | 2 | ||||
| -rw-r--r-- | src/elixir_math_parser.yrl | 4 | ||||
| -rw-r--r-- | src/elixir_math_parser_lexer.xrl | 2 |
3 files changed, 7 insertions, 1 deletions
diff --git a/example/input.txt b/example/input.txt index cb3073b..ec70a41 100644 --- a/example/input.txt +++ b/example/input.txt @@ -1,6 +1,6 @@ :a = 7 :b = 4 -:result = :a + :b * 10 / 2 +:result = (:a + :b) * 10 / 2 :x = 20 :y = 3 diff --git a/src/elixir_math_parser.yrl b/src/elixir_math_parser.yrl index 4900996..762cf4b 100644 --- a/src/elixir_math_parser.yrl +++ b/src/elixir_math_parser.yrl @@ -13,6 +13,8 @@ Terminals '*' '/' '=' + '(' + ')' . Rootsymbol @@ -24,6 +26,7 @@ Left 300 '+'. Left 300 '-'. Left 400 '*'. Left 400 '/'. +Left 600 '('. root -> assignments : '$1'. @@ -38,6 +41,7 @@ expr -> expr '+' expr : {add_op, '$1', '$3'}. expr -> expr '-' expr : {sub_op, '$1', '$3'}. expr -> expr '*' expr : {mul_op, '$1', '$3'}. expr -> expr '/' expr : {div_op, '$1', '$3'}. +expr -> '(' expr ')' : '$2'. Erlang code. diff --git a/src/elixir_math_parser_lexer.xrl b/src/elixir_math_parser_lexer.xrl index a2980c8..8d7920a 100644 --- a/src/elixir_math_parser_lexer.xrl +++ b/src/elixir_math_parser_lexer.xrl @@ -9,6 +9,8 @@ Rules. \* : {token, {'*', TokenLine}}. \/ : {token, {'/', TokenLine}}. \= : {token, {'=', TokenLine}}. +\( : {token, {'(', TokenLine}}. +\) : {token, {')', TokenLine}}. {NAME} : {token, {atom, TokenLine, to_atom(TokenChars)}}. {INT} : {token, {int, TokenLine, TokenChars}}. {WHITESPACE}+ : skip_token. |
