Closed Iruyan-Zak closed 7 years ago
i viewed your 1+1 parser on four-arithmetical-operation
.
i guess we should make the numerical parser first: sounds easy to extend to the operation parser.
i would like you to tell me your own opinion.
In my code...
(lhs, s1) <- char '1' str
(plus, s2) <- char '+' s1
(rhs, s3) <- char '1' s2
I prefer below one.
lhs <- char '1'
plus <- char '+'
rhs <- char '1'
This is just a motivation to use State monad. So next, I'd like to adopt State monad before my code becomes complicated.
i see. do what you'd love to do. And i prefer below one too cuz it's better as a Haskell's do-notation.
then you'd like to... reimplement 1+1 parser with State monad? or extend parser to n+m?
I'll do in order...
We should also consider integer-operation. e.g.) On integer-integer-division, do we use float-point-number or fractional-number, or integer?
thx for ur answer.
i think about when each of them is needed:
i feel integers the best and easiest for implement. i need fractions as a library, not as a norm.
I started with parsing natural number denoted by REGEX /0|[1-9][0-9]*/.
now I have digit
function that parsing a char matches REGEX /[0-9]/, and this function implemented with Prelude.isDigit
function.
How do I implement parsing one matches REGEX /[1-9]/?
(Use regex, make alteration of Prelude.isDigit
, or other way.)
does this enchantment look good?
i guessed what you did.
but i think isNonZeroDigit
shorter than yours as isDigit c && c /= '0'
.
which is better?
It's true. Fixing now.
How do I treat negative numbers? Concretely, do we allow this expression? : "1+-2"
it is allowed in python, ruby, and js so we can allow it like them. haskell doesnt allow it, but prefers to be mathematical.
tiny prefers to write easily, so i hope the expression will be allowed.
OK. I feel that some troubles will occur around -
operator later, but it is nothing to be good that fears it now.
I will implement parsers following in regex. So I makeing
How naming 1-4 operation? I am satisfied only that I named (3) "closure."
(In (1) and (2), I defined <.>
, <|>
as binary operators. But I wanna make function applying all of parsers in it's []
.
In (3) and (4), Haskell disallow defining unary operators in normal way, so I'd like to define as normal function.)
i propose the names of (1) and (2).
but (4) has no proposal... sry
I thank you for your response.
In result of my research,
So I use the name mentioned above.
My code remains unnecessary do
notations rather than (<.>)
operator.
The reason is just only the order of implementation.
I mention closure
and naturalNumber
now.
Should I rewrite these functions?
of course, but please log changes of the implementation courses here or commits.
@Roadagain Is it OK?
@Iruyan-Zak ok, great job.
btw, i can see closure as (p <.> closure p) <|> epsilon
.
i guess it should be p <.> (closure p <|> epsilon)
, should not?
sry, i mistaked. closure
is not wrong.
OK, I cannot find to do in this issue. So I'm going to create PR.
I'm aware that I parse four-arithmetical-operation but not calculate it. In my opinion, calculate is related in execution or code generating. So I want to focus on parsing in this issue.
ok, so i wish to rename this issue "Parsing four-arithmetical-operations" for looking back.
Done it. And I create PR #8.
thx and i will merge it after ci checks.
close via 8404e98
Let's parse four-arithmetical-operation!
I wonder if...
+
,-
,*
,/
, but other component in this issue? e.g.()
,mod
.)