t_wの輪郭

Feedlyでフォローするボタン
作業記録生活記録

2020年8月22日

2020/8/23 12:12:00

1:00 就寝
7:00 起床
7:30 朝食 カステラ 500kcal
8:00 散歩 15分
8:30 作業 pegged調査
12:00 昼食 カレー 400kcal
18:00 夕食 スパゲッティ 550kcal 唐揚げの甘酢あんかけ 350kcal
21:00 室内運動 15分
 
間食
 ヨーグルト 80kcal
 アイス 132 kcal
 枝豆 60kcal
 コーンポタージュ 100kcal
 
総カロリー: 2172kcal


数式をpeggedで構文木生成pegged調査ScrapboxのデータをObsidianに移植

文法:

Arithmetic:
    Term     < Factor (Add / Sub)*
    Add      < "+" Factor
    Sub      < "-" Factor
    Factor   < Primary (Mul / Div)*
    Mul      < "*" Primary
    Div      < "/" Primary
    Primary  < Parens / Neg / Pos / Number / Variable
    Parens   < "(" Term ")"
    Neg      < "-" Primary
    Pos      < "+" Primary
    Number   < ~([0-9]+)

    Variable <- identifier

数式
1 + 2 - (3*x-5)*6

生成結果:

Arithmetic("1 + 2 - (3*x-5)*6").writeln;
=>
    Arithmetic [0, 17]["1", "+", "2", "-", "(", "3", "*", "x", "-", "5", ")", "*", "6"]
    +-Arithmetic.Term [0, 17]["1", "+", "2", "-", "(", "3", "*", "x", "-", "5", ")", "*", "6"]
        +-Arithmetic.Factor [0, 2]["1"]
        |  +-Arithmetic.Primary [0, 2]["1"]
        |     +-Arithmetic.Number [0, 2]["1"]
        +-Arithmetic.Add [2, 6]["+", "2"]
        |  +-Arithmetic.Factor [4, 6]["2"]
        |     +-Arithmetic.Primary [4, 6]["2"]
        |        +-Arithmetic.Number [4, 6]["2"]
        +-Arithmetic.Sub [6, 17]["-", "(", "3", "*", "x", "-", "5", ")", "*", "6"]
        +-Arithmetic.Factor [8, 17]["(", "3", "*", "x", "-", "5", ")", "*", "6"]
            +-Arithmetic.Primary [8, 15]["(", "3", "*", "x", "-", "5", ")"]
            |  +-Arithmetic.Parens [8, 15]["(", "3", "*", "x", "-", "5", ")"]
            |     +-Arithmetic.Term [9, 14]["3", "*", "x", "-", "5"]
            |        +-Arithmetic.Factor [9, 12]["3", "*", "x"]
            |        |  +-Arithmetic.Primary [9, 10]["3"]
            |        |  |  +-Arithmetic.Number [9, 10]["3"]
            |        |  +-Arithmetic.Mul [10, 12]["*", "x"]
            |        |     +-Arithmetic.Primary [11, 12]["x"]
            |        |        +-Arithmetic.Variable [11, 12]["x"]
            |        +-Arithmetic.Sub [12, 14]["-", "5"]
            |           +-Arithmetic.Factor [13, 14]["5"]
            |              +-Arithmetic.Primary [13, 14]["5"]
            |                 +-Arithmetic.Number [13, 14]["5"]
            +-Arithmetic.Mul [15, 17]["*", "6"]
                +-Arithmetic.Primary [16, 17]["6"]
                    +-Arithmetic.Number [16, 17]["6"]

ScrapboxからexportしたJSONファイルをMarkdownに変換する
 
Scrapbox記法を行単位で見れば、構文木を作る必要がない気がしてきた
構文を配列にするだけで処理できそう
sbLine = [Indent, Text, Link, Text, Image]; みたいな感じ