Skip to content

Instantly share code, notes, and snippets.

@syntagmatic
Last active December 16, 2015 02:19
Show Gist options
  • Select an option

  • Save syntagmatic/5361872 to your computer and use it in GitHub Desktop.

Select an option

Save syntagmatic/5361872 to your computer and use it in GitHub Desktop.
Geometric Algebra Grammar
op
= outerprod
/ innerprod
/ geomprod
/ primary
outerprod
= left:primary "^" right:op { return left + ".op(" + right + ")"; }
innerprod
= left:primary "*" right:op { return left + ".ip(" + right + ")"; }
geomprod
= left:primary " " right:op { return left + ".gp(" + right + ")"; }
primary
= blade
/ "(" op:op ")" { return op; }
blade "blade"
= chars:[a-zA-Z0-9]+ { return chars.join(""); }
@weshoke
Copy link

weshoke commented Apr 15, 2013

Here's a version with operator precedence and some tweaks to the operator symbols:

op
= geomprod

geomprod
= left:innerprod "*" right:geomprod { return left + ".gp(" + right + ")"; }
/ innerprod

innerprod
= left:outerprod "<<" right:innerprod { return left + ".ip(" + right + ")"; }
/ outerprod

outerprod
= left:primary "^" right:outerprod { return left + ".op(" + right + ")"; }
/ primary

primary
= blade
/ "(" op:op ")" { return op; }

blade "blade"
= chars:[a-zA-Z0-9]+ { return chars.join(""); }

@syntagmatic
Copy link
Author

I got the operator names from the GAViewer documentation which has symbols, functions and precedence levels for each operator (page 28).

Perhaps though we could should use Versor's conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment