Parsing Complex Text Structures
By Ian E. Gorman, June 01, 2000
A pattern language that includes recursive patterns and conditional pattern matching can handle complex text structures without supplementary programming. Ian uses the OmniMark pattern language from OmniMark Technologies to do a job that might otherwise be done with tools like lex and yacc.
Jun00: Programmer's Toolchest
define switch function r-expression
as
do scan #current-input
match "+" term r-expression
;pop two integers, add them, push the result
match "-" term r-expression
;pop two integers, subtract them, push the result
done
;if not matched above, accept the empty string
return true
Example 8: Right-recursive arithmetic evaluation.