Skip to content

Instantly share code, notes, and snippets.

@javazquez
Created February 18, 2017 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javazquez/28b07357a601a7606b38726697077eab to your computer and use it in GitHub Desktop.
Save javazquez/28b07357a601a7606b38726697077eab to your computer and use it in GitHub Desktop.
clojure instaparse arnoldc grammer
Program = method-declaration* begin-main wspace method-declaration*;
begin-main = <'IT\'S SHOWTIME'> (statement wspace)* end-main ;<wspace> = <#'\s*'>;statement = wspace (assignment | printing | decvar | assign-var-from-method-call |
call-method | if | while | call-method | return);method-statement = (assignment | printing | decvar | assign-var-from-method-call |
call-method | if | while | call-method);call-method = <'DO IT NOW'> wspace method-name numvar* wspace;method-name = (number| #'[a-zA-Z][a-zA-Z0-9]*' |zero |false | true) assign-var-from-method-call = <'GET YOUR ASS TO MARS'> wspace variable wspace call-method;assignment = <'GET TO THE CHOPPER'> numvar wspace set-val wspace end-assignment wspace;
while= <'STICK AROUND'> numvar wspace statement* end-while ;
<end-while>= <'CHILL'>;
set-val= <'HERE IS MY INVITATION'> numvar (arithmetic-op|logical-op)*;
<end-assignment>= <'ENOUGH TALK'>;
printing = <'TALK TO THE HAND'> wspace (variable | quotedstring| number) wspace;
decvar = <'HEY CHRISTMAS TREE'> numvar wspace init-val;
if = <'BECAUSE I\'M GOING TO SAY PLEASE'> numvar statement* else-if* end-if;
else-if = <'BULLSHIT'>wspace statement*;
<end-if> = <'YOU HAVE NO RESPECT FOR LOGIC'> wspace;
<numvar> = wspace (number | variable | zero | false | true);
zero = <'@I LIED'>;
init-val = <'YOU SET US UP'> (numvar|bool) wspace;
bool = wspace (true|false);
true = '@NO PROBLEMO';
false ='@I LIED';
number = #'-?[0-9]+';
variable = #'[a-zA-Z][a-zA-Z0-9]*';
quotedstring = #'".*"';
logical-op = wspace (gt | or | and | equalto );
arithmetic-op = wspace ( plus | minus | mult | div | modulo) ;
modulo = <'I LET HIM GO'> numvar;
plus = <'GET UP'> numvar;
minus = <'GET DOWN'> numvar;
mult = <'YOU\'RE FIRED'> numvar;
div = <'HE HAD TO SPLIT'> numvar;
gt = <'LET OFF SOME STEAM BENNET'> numvar;
or = <'CONSIDER THAT A DIVORCE'> numvar;
and = <'KNOCK KNOCK'> numvar;
equalto = <'YOU ARE NOT YOU YOU ARE ME'> numvar;
<end-main> = <'YOU HAVE BEEN TERMINATED'> ;
method-declaration = <'LISTEN TO ME VERY CAREFULLY'> numvar wspace
method-arg*
( non-void-method* | statement* wspace end-method) wspace;
non-void-method = <'GIVE THESE PEOPLE AIR'> wspace (method-statement|method-return)* end-method wspace;
method-return = <'I\'LL BE BACK'> (numvar | quotedstring)+ wspace ;
return = <'I\'LL BE BACK'> (numvar | quotedstring)? wspace ;
method-arg = <'I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE'> wspace variable wspace;
<end-method> = <'HASTA LA VISTA, BABY'>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment