Commit 1dfb8587 authored by Jamie A. Jennings's avatar Jamie A. Jennings

Drafted a to_rpl_1_2() function but actually we do not need it.

parent 7cd8c594
......@@ -113,18 +113,17 @@ operator = slash / and
grammar
syntax_error = { rest_of_line }
-- expression forms
exp = infix
alias infix = {atmos
!binding_prefix
atmos
term quantifier?
{ atmos
operator?
infix}*
}
grammar_exp = "grammar" identifier atmos (bindings "in")? infix
let_exp = "let" atmos (bindings "in")? infix
-- infix (and other) expression forms
exp = {atmos
!binding_prefix
atmos
term quantifier?
{ atmos
operator?
exp}*
}
grammar_exp = "grammar" identifier atmos (bindings "in")? exp
let_exp = "let" atmos (bindings "in")? exp
application = { identifier ":" } atmos (arg / arglist / rawarglist )
arglist = { atmos open int_or_exp { atmos "," int_or_exp }* close }
rawarglist = { atmos openraw int_or_exp { atmos "," int_or_exp }* closeraw }
......@@ -141,10 +140,10 @@ grammar
hash_exp /
application /
identifier}
bracket = { openbracket complement? infix atmos closebracket }
cooked = { open infix atmos close }
raw = { openraw infix atmos closeraw }
predicate = { predicate_symbol ws? infix }
bracket = { openbracket complement? exp atmos closebracket }
cooked = { open exp atmos close }
raw = { openraw exp atmos closeraw }
predicate = { predicate_symbol ws? exp }
-- binding forms
binding = { atmos grammar_block / let_block / simple / empty }
......
......@@ -347,6 +347,39 @@ function infix.to_prefix(pt)
end
end
--------------------------------------------------------------------------------
-- RPL 1.2 and RPL 1.3 are intended to accept the same language, though they
-- parse differently. The to_prefix() function restructures a parse tree
-- produced by the rpl_1_3 grammar so that it has a traditional prefix form,
-- where each operator, even if infix, is the root of a tree whose children are
-- the operands.
--
-- While modifying rpl_1_2 to produce rpl_1_3, we made a couple of minor changes
-- to make the to_prefix() algorithm easier to write. Specifically, form.exp
-- replaces the use of the alias form.infix (previously called form.exp_) in the
-- following productions:
-- (1) form.simple
-- (2) form.int_or_exp
--
-- The to_rpl_1_2 function alters a parse tree (AFTER to_prefix has been used)
-- to remove the capture node of type form.exp from the productions listed
-- above, because the RPL compiler does not expect them. In other words, we do
-- not want to change the compiler as a result of the change in parsing strategy.
function infix.to_rpl_1_2(pt)
if pt.type=="form.simple" or pt.type=="form.int_or_exp" then
assert(pt.subs and pt.subs[1] and pt.subs[1].type and
pt.subs[1].type=="form.exp" and not pt.subs[2])
return {type=pt.type,
s=pt.s,
e=pt.e,
data=pt.data,
subs=map(infix.to_rpl_1_2, pt.subs[1].subs)}
else
return pt
end
end
--------------------------------------------------------------------------------
function slurp(filename)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment