Skip to content

Commit

Permalink
Merge pull request #40 from frungl/const_under
Browse files Browse the repository at this point in the history
Add lower underscore support in constants
  • Loading branch information
GassaFM authored Apr 1, 2023
2 parents 6b9f084 + a7289ff commit d05db70
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ It calls the function `<name>` with respective arguments.

* Variables come as either `<name>` for 64-bit integers or `<name>[<expr>]` for array elements.

* Constants are numbers in decimal notation, composed entirely of decimal digits.
* Constants are numbers in decimal notation, composed entirely of decimal digits. You can use any number of `_` characters inside the number for easy reading.

### Comments

Expand Down
2 changes: 1 addition & 1 deletion README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function <name> (<arg1>, <arg2>, ...):
а элементы массивов 64-битных чисел &mdash; как `<name>[<expr>]`.

* Константы &mdash; числа в десятичной записи, состоящие целиком
из десятичных цифр.
из десятичных цифр. Можно использовать любое количество символов `_` внутри числа для удобства чтения.

### Комментарии

Expand Down
6 changes: 6 additions & 0 deletions examples/constant.pr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function constant(id, pr, n, a):
if id == 0:
a := 1000
b := 1_000____
c := 10000___0000
print(a, b, c)
7 changes: 5 additions & 2 deletions source/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ struct Line
{
do
{
temp ~= t.front;
if (t.front.isDigit)
{
temp ~= t.front;
}
t.popFront ();
}
while (!t.empty && t.front.isDigit);
while (!t.empty && (t.front.isDigit || t.front == '_'));
}
else if (t.front.isIdent)
{
Expand Down
2 changes: 1 addition & 1 deletion syntax.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function <name> ( <parameter-list> ) : \n <statement-list>
( <expression0> )

<constant> is
[0-9]+
[0-9][0-9|_]+

<call> is
<name> ( <argument-list> )
Expand Down

0 comments on commit d05db70

Please sign in to comment.