forked from glen/fostr
Glen Whitney
2e49065031
Also adds parenthesization of fostr expressions. Recasts code generation in terms of bottomup processing of a local strategy. Resolves #1. Co-authored-by: Glen Whitney <glen@studioinfinity.org> Reviewed-on: glen/fostr#8 Co-Authored-By: Glen Whitney <glen@nobody@nowhere.net> Co-Committed-By: Glen Whitney <glen@nobody@nowhere.net>
36 lines
550 B
Plaintext
36 lines
550 B
Plaintext
module fostr
|
|
|
|
imports
|
|
|
|
Common
|
|
|
|
context-free start-symbols
|
|
|
|
Ex
|
|
|
|
context-free sorts
|
|
|
|
Ex
|
|
|
|
context-free syntax
|
|
|
|
Ex.Int = INT
|
|
Ex.Stdio = <stdio>
|
|
Ex.Sum = {Ex "+"}+
|
|
Ex.Receives = [[Ex] << [Ex]] {left}
|
|
Ex.Enters = [[Ex] >> [Ex]] {left}
|
|
Ex = <(<Ex>)> {bracket}
|
|
|
|
context-free priorities
|
|
|
|
Ex.Enters
|
|
> Ex.Sum
|
|
> Ex.Receives,
|
|
|
|
// prevent cycle: no singletons
|
|
Ex.Sum <0> .> {Ex "+"}+ = Ex,
|
|
|
|
// flat: no Sum immediately in Sum:
|
|
{Ex "+"}+ = Ex <0> .> Ex.Sum,
|
|
{Ex "+"}+ = {Ex "+"}+ "+" Ex <2> .> Ex.Sum
|