aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWilliam Hergès <william@herges.fr>2025-11-09 13:23:05 +0100
committerWilliam Hergès <william@herges.fr>2025-11-09 13:23:05 +0100
commit3b0cc79dee76244da55d2326cc4244a384d85e44 (patch)
tree7a2819f658fe987f942633ad82997a75850e16ef /src
parent8f9730d89e66ab1cbf08cbc0dea2a429d135e0da (diff)
feat(calc)): supports factorial
Diffstat (limited to 'src')
-rw-r--r--src/elixir_math_parser.yrl4
-rw-r--r--src/elixir_math_parser_lexer.xrl1
2 files changed, 4 insertions, 1 deletions
diff --git a/src/elixir_math_parser.yrl b/src/elixir_math_parser.yrl
index 86b36c8..0808683 100644
--- a/src/elixir_math_parser.yrl
+++ b/src/elixir_math_parser.yrl
@@ -10,7 +10,7 @@ Terminals
int
var
break
- '+' '-' '*' '/'
+ '+' '-' '*' '/' '!'
'='
'(' ')'
.
@@ -24,6 +24,7 @@ Left 300 '+'.
Left 300 '-'.
Left 400 '*'.
Left 400 '/'.
+Right 500 '!'.
Left 600 '('.
root -> statements : '$1'.
@@ -46,6 +47,7 @@ expr -> exprs '-' exprs : {sub_op, '$1', '$3'}.
expr -> exprs '*' exprs : {mul_op, '$1', '$3'}.
expr -> exprs '/' exprs : {div_op, '$1', '$3'}.
expr -> '(' exprs ')' : '$2'.
+expr -> expr '!' : {factor_op, '$1'}.
Erlang code.
diff --git a/src/elixir_math_parser_lexer.xrl b/src/elixir_math_parser_lexer.xrl
index facf323..5bdcbef 100644
--- a/src/elixir_math_parser_lexer.xrl
+++ b/src/elixir_math_parser_lexer.xrl
@@ -13,6 +13,7 @@ Rules.
\= : {token, {'=', TokenLine}}.
\( : {token, {'(', TokenLine}}.
\) : {token, {')', TokenLine}}.
+! : {token, {'!', TokenLine}}.
{BREAK}+ : {token, {break, TokenLine}}.
{NAME} : {token, {var, TokenLine, TokenChars}}.
{INT} : {token, {int, TokenLine, TokenChars}}.