Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


C++ should use more @`,!>

  • You cannot reply to this topic
No replies to this topic

#1 Cornstalks   Crossbones+   -  Reputation: 6991

Like
3Likes
Like

Posted 27 February 2013 - 10:18 AM

Here's a little sample from my Racket-based parser for parsing tokenized Python (uses Matt Might's derivative parser):
 

; <program> ::= (program <stmt>*)
(file_input      (@--> (seq! `(rep (or NEWLINE stmt)) ENDMARKER)
                       (λ (seq) `(program ,@seq))))
 
; <funcdef> ::= (def (<NAME> <NAME>*) <suite>)
(funcdef         ($--> (seq! "def" `NAME `parameters ":" `suite)
                       `(def (,($ 0) ,@($ 1)) ,($ 2))))
 
; ... more stuff

; <simple_stmt> ::= <small_stmt> | (begin <small_stmt>+)
(simple_stmt     (>--> (seq! `(seq* small_stmt
                                    (rep (seq! ";" `small_stmt)))
                             (opt ";")
                             NEWLINE)
                       [`((,small_stmt ())) small_stmt]
                       [`((,small_stmt ,rep)) `(begin ,small_stmt ,@rep)]))
 
; ... and a ton more cryptic cases

 
Because you can never have enough randomly* placed symbols sprinkled throughout your code...
*and by randomly, I mean very carefully

A whole file of this is actually kinda mesmerizing when you look back on what you've written.


[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

Sponsor:




PARTNERS