next up previous
Next: 8. Calculator Example Up: Yapps 1.0 Previous: 6. Future Extensions

7. Grammar for Parsers

This is the grammar for parsers, without the return values. Everything inside <...> is a placeholder for something that is harder to read.

parser ParserDesc:
    ignore:      "[ \t\n\r]+"
    token END:   "\'"
    token ATTR:  "<<\([^>]+\|>[^>]\)*>>"
    token ID:    '[a-zA-Z_][a-zA-Z_0-9]*'
    token STR:   <python single and double quoted strings>

    rule Parser: "parser" ID ":" Options Tokens Rules END
    rule Options: <nothing> | "option" ":" STR Options
    rule Tokens:  <nothing>   
               | "token" ID ":" STR Tokens
               | "ignore"   ":" STR Tokens
    rule Rules: <nothing>  |  "rule" ID OptParam ":" Clause Clauses Rules
    rule Clause: Subs "->" ATTR
    rule Clauses: <nothing> | "|" Clause Clauses
    rule OptParam: <nothing> | ATTR 
    rule Subs: <nothing>
             | STR Subs
             | ID OptParam Subs

The full grammar is here.



Amit J Patel, amitp@cs.stanford.edu