Use canonical GF in LPGF compiler

Still contains some hardcoded values, missing cases.

I notice now that LPGF and Canonical GF are almost identical, so maybe we don't need a new LPGF format,
just a linearization-only runtime which works on canonical grammars.
The argument for keeping LGPF is that it would be optimized for size and speed.
This commit is contained in:
John J. Camilleri
2021-02-01 12:28:06 +01:00
parent cead0cc4c1
commit fe15aa0c00
5 changed files with 137 additions and 111 deletions

View File

@@ -44,7 +44,8 @@ data LinType =
-- | Linearisation function
data LinFun =
LFEmpty
LFError String
| LFEmpty
| LFToken String
| LFConcat LinFun LinFun
| LFInt Int
@@ -125,6 +126,7 @@ type Context = [LinFun]
-- | Operational semantics, Table 2
eval :: Context -> LinFun -> LinFun
eval cxt t = case t of
LFError err -> error err
LFEmpty -> LFEmpty
LFToken tok -> LFToken tok
LFConcat s t -> LFConcat v w
@@ -136,8 +138,14 @@ eval cxt t = case t of
where vs = map (eval cxt) ts
LFProjection t u -> vs !! (i-1)
where
LFTuple vs = eval cxt t
LFInt i = eval cxt u
-- LFTuple vs = eval cxt t
-- LFInt i = eval cxt u
vs = case eval cxt t of
LFTuple vs -> vs
x -> error $ "ERROR expected LFTuple, got: " ++ show x
i = case eval cxt u of
LFInt j -> j
x -> error $ "ERROR expected LFInt, got: " ++ show x
LFArgument i -> cxt !! (i-1)
-- | Turn concrete syntax terms into an actual string