OriRoth / fling

A fluent API generator
http://drops.dagstuhl.de/opus/volltexte/2019/10805/
24 stars 3 forks source link

Define this grammar #8

Closed yossigil closed 5 years ago

yossigil commented 5 years ago
E  -> T E'
E' -> + T E' | -TE' |epsilon
T  -> F T'
T' -> * F T' | /FT' |epsilon
F  -> (E) | int

e.g., by


start(Expression). 
derive(Expression).to(Summands).
derive(Summands).to(DegenerateSummands).
derive(Summands).to(Summand,SummandsList).
derive(Summand).to(sum(oneOrMore(Expression)).
derive(SummandsList).to(plus,Summand)
yossigil commented 5 years ago

for example,

v("X"). //define variable X
times().
v("X").plus().v("Y") // X * X + Y
.times().begin(). // X* X + Y(
.n(12.3)
.plus().
.v("X").
end(); //  X* X + Y(12.3+X)
;

try also

n(12).v("X") // 12 * X
.plus("Y") // 12*X+Y
.n(36) // 12*X + 36*Y
OriRoth commented 5 years ago

The second code example would probably over-complicate the grammar---I'll pass it for now.

OriRoth commented 5 years ago

Done. Language is called Arithmetic.