GrammarRules [rules]
represents grammar rules to be deployed to a cloud object that implements the grammar in a form suitable for use with functions like GrammarApply and Interpreter .
GrammarRules [rules,defs]
uses grammar definitions defs.
GrammarRules
GrammarRules [rules]
represents grammar rules to be deployed to a cloud object that implements the grammar in a form suitable for use with functions like GrammarApply and Interpreter .
GrammarRules [rules,defs]
uses grammar definitions defs.
Details and Options
- Grammar rules are of the form pattern->expr or pattern:>expr.
- The pattern in a grammar rule must be a combination of the following elements:
-
"string" literal stringform1|form2|… alternative formsform.. form repeated any number of timesx:form form named to be used
- CloudDeploy [GrammarRules[…]] deploys a grammar and returns a cloud object, which can be used in GrammarApply and Interpreter .
- The rules associated with the grammar in effect specify how inputs should be transformed to expressions.
- In GrammarRules [rules,defs], the list defs can give subsidiary rules for grammar domains that can be used in the main grammar rules.
- GrammarRules supports the following options:
-
Examples
open all close allBasic Examples (2)
Deploy a simple grammar for adding numbers:
Apply the deployed grammar to a natural language string:
Define rules for custom GrammarToken objects:
Apply the grammar:
Properties & Relations (1)
Repeated and DelimitedSequence are equivalent to recursive grammar rules:
Possible Issues (1)
Expressions on the right-hand side of a grammar rule evaluate during GrammarApply :
To keep an expression unevaluated, use a wrapper like HoldComplete or Inactivate :
See Also
Related Guides
Text
Wolfram Research (2014), GrammarRules, Wolfram Language function, https://reference.wolfram.com/language/ref/GrammarRules.html (updated 2015).
CMS
Wolfram Language. 2014. "GrammarRules." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/GrammarRules.html.
APA
Wolfram Language. (2014). GrammarRules. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GrammarRules.html
BibTeX
@misc{reference.wolfram_2025_grammarrules, author="Wolfram Research", title="{GrammarRules}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/GrammarRules.html}", note=[Accessed: 16-November-2025]}
BibLaTeX
@online{reference.wolfram_2025_grammarrules, organization={Wolfram Research}, title={GrammarRules}, year={2015}, url={https://reference.wolfram.com/language/ref/GrammarRules.html}, note=[Accessed: 16-November-2025]}