Parse EBNF: Difference between revisions

Content added Content deleted
Line 1,057: Line 1,057:
-- The rules that applies() has to deal with are:
-- The rules that applies() has to deal with are:
-- {factors} - if rule[1] is not string, just apply one after the other,
-- {factors} - if rule[1] is not string, just apply one after the other,
-- (as per term() above, originally I had a "factors" there,
-- recursively. As per term() above, originally had "factors",
-- but getting rid of it made the syntax tree much clearer)
-- but getting rid of it made the syntax tree much clearer)
-- {"terminal", "a1"} -- literal constants
-- {"terminal", "a1"} -- literal constants
-- {"or", <e1>, <e2>, ...} -- (any) one of n
-- {"or", <e1>, <e2>, ...} -- (any) one of n
-- {"repeat", <e1>} -- as per "{}" in ebnf
-- {"repeat", <e1>} -- as per "{}" in ebnf
-- {"optional", <e1>} -- as per "()" in ebnf
-- {"optional", <e1>} -- as per "[]" in ebnf
-- {"ident", <name>, idx} -- apply the sub-rule
-- {"ident", <name>, idx} -- apply the sub-rule


Line 1,165: Line 1,165:
end if
end if
end for</lang>
end for</lang>
In real use, I would be tempted to use numeric literals rather than string tags in such structures, but the latter certainly make things ten times easier to debug, plus I got an instantly legible dump practically for free.
In real use, I would be tempted to use numeric literals rather than string tags in such structures, but the latter certainly make things ten times easier to debug, plus I got an instantly legible syntax tree dump (the bit just after "===>" below) practically for free.
{{out}}
{{out}}
<pre>
<pre>