Jump to content

Parse EBNF: Difference between revisions

m
Line 1,057:
-- The rules that applies() has to deal with are:
-- {factors} - if rule[1] is not string, just apply one after the other,
-- (asrecursively. As per term() above, originally I had a "factors" there,
-- but getting rid of it made the syntax tree much clearer)
-- {"terminal", "a1"} -- literal constants
-- {"or", <e1>, <e2>, ...} -- (any) one of n
-- {"repeat", <e1>} -- as per "{}" in ebnf
-- {"optional", <e1>} -- as per "()[]" in ebnf
-- {"ident", <name>, idx} -- apply the sub-rule
 
Line 1,165:
end if
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 syntax tree dump (the bit just after "===>" below) practically for free.
{{out}}
<pre>
7,820

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.