Skip to content

Instantly share code, notes, and snippets.

@stephpy
Created September 12, 2012 13:58
Show Gist options
  • Save stephpy/3706786 to your computer and use it in GitHub Desktop.
Save stephpy/3706786 to your computer and use it in GitHub Desktop.
%skip space \s
%token bracket_ \(
%token _bracket \)
%token comma ,
%token number (0|[1-9]\d*)(\.\d+)?([eE][\+\-]?\d+)?
%token plus \+
%token minus \-|−
%token pow \*\*
%token times \*|×
%token percent %
%token div /|÷
%token ID [A-Z_0-9]+
%token id [a-z_0-9]+
expression:
primary()
( ( ::plus:: #addition | ::minus:: #substraction ) expression() )?
primary:
term()
( (
::times:: #multiplication |
::div:: #division |
::pow:: #pow |
::percent:: #modulo
)
expression() )?
term:
( ::bracket_:: expression() ::_bracket::)
| number()
| function()
| constant() #constant
| ( ::minus:: #negative | ::plus:: ) term()
number:
<number>
constant:
<ID>
#function:
<id> ::bracket_::
( expression() ( ::comma:: expression() )* )?
::_bracket::
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment