0

There's a simple arithmetic grammar found in PEGjs, that I want to expand its output to 2 or 3 lines each containing expression results in Decimal, Hex and Binary format.

Example:

input: (3*(5+8))
output should be: 39\n27\n00100111

I searched for detail on PEG.js, but couldn't find any info on that.

Any help appreciated.

*Also it would be nice to have multiple lines in input too, with different outputs in multiple lines too.

HabibS
  • 382
  • 6
  • 14

1 Answers1

0

You can control the output of your matches, so you can just output 3 different versions of a single match.

For example if you have this rule:

Integer
  = _ [0-9]+ { return `${parseInt(text(), 10)} / 0x${Number(text()).toString(16)} / 0x${Number(text()).toString(2)}`}

passing 16 to it would return

"16 / 0x10 / 0x10000"