kosen13s / tiny

A tiny programming language to improve kosen13s' skills
MIT License
4 stars 0 forks source link

Parsing four-arithmetical-operation #5

Closed Iruyan-Zak closed 7 years ago

Iruyan-Zak commented 7 years ago

Let's parse four-arithmetical-operation!

I wonder if...

Roadagain commented 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.

Iruyan-Zak commented 7 years ago

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.

Roadagain commented 7 years ago

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?

Iruyan-Zak commented 7 years ago

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?

Roadagain commented 7 years ago

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.

Iruyan-Zak commented 7 years ago

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.)

Iruyan-Zak commented 7 years ago

does this enchantment look good?

Roadagain commented 7 years ago

i guessed what you did.

but i think isNonZeroDigit shorter than yours as isDigit c && c /= '0'. which is better?

Iruyan-Zak commented 7 years ago

It's true. Fixing now.

Iruyan-Zak commented 7 years ago

How do I treat negative numbers? Concretely, do we allow this expression? : "1+-2"

Roadagain commented 7 years ago

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.

Iruyan-Zak commented 7 years ago

OK. I feel that some troubles will occur around - operator later, but it is nothing to be good that fears it now.

Iruyan-Zak commented 7 years ago

I will implement parsers following in regex. So I makeing

  1. $a \cdot b$
  2. $a | b$
  3. $a*$
  4. $a?$ where a, b are regex.

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.)

Roadagain commented 7 years ago

i propose the names of (1) and (2).

  1. "composition" / "composite"
  2. "switch"

but (4) has no proposal... sry

Iruyan-Zak commented 7 years ago

I thank you for your response.

In result of my research,

So I use the name mentioned above.

Iruyan-Zak commented 7 years ago

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?

Roadagain commented 7 years ago

of course, but please log changes of the implementation courses here or commits.

Iruyan-Zak commented 7 years ago

@Roadagain Is it OK?

Roadagain commented 7 years ago

@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?

Roadagain commented 7 years ago

sry, i mistaked. closure is not wrong.

Iruyan-Zak commented 7 years ago

OK, I cannot find to do in this issue. So I'm going to create PR.

Iruyan-Zak commented 7 years ago

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.

Roadagain commented 7 years ago

ok, so i wish to rename this issue "Parsing four-arithmetical-operations" for looking back.

Iruyan-Zak commented 7 years ago

Done it. And I create PR #8.

Roadagain commented 7 years ago

thx and i will merge it after ci checks.

Roadagain commented 7 years ago

close via 8404e98