riffraff / shakespeare-parrot
A Parrot based interpreter for the Shakespeare programming language
Clone this repository (size: 640.1 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/riffraff/shakespeare-parrot/
| commit 92: | e4f0025e7622 |
| parent 91: | dfcc448b7385 |
| branch: | default |
| tags: | tip |
properly release as Beer Ware code
| r92:e4f0025e7622 | 184 loc | 3.6 KB | embed / history / annotate / raw / |
|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | grammar shakespeare::Grammar is PCT::Grammar;
rule TOP {
<shebang>?
<title>
<chardef>*
<act>*
{*}
}
rule shebang {
'#!' \N*
}
rule title {
<description> <end>
}
rule scene {
'scene' <roman> ':' <description> <end>
<events>*
{*}
}
rule act {
'act' <roman> ':' <description> <end>
{*} #= open
<scene>*
{*} #= close
}
rule events {
| <line> {*} #= line
| <move> {*} #= move
}
rule chardef {
<character> ',' <description> <end> {*}
}
rule line {
<character> ':' [<sentence> <end>]+ {*}
}
rule charlist {
<character>? ['and' <character>]*
}
rule sentence {
| <tap> {*} #= tap
| <plan> {*} #= plan
| <memorize> {*} #= memorize
| <branch> {*} #= branch
| <question> {*} #= question
| <test> {*} #= test
| <io> {*} #= io
| <assignment> {*} #= assignment
| <value> {*} #= value
| <recall> {*} #= recall
}
token end { <[.!?]> }
rule tap {
'proove' <value> {*}
}
rule memorize {
'remember' <value> {*}
}
rule recall {
'recall' <-end>* {*}
}
rule plan {
'plan' <value> {*}
}
rule io {
|'open' <second_person_possessive> 'heart' {*} #= open_heart
|'speak' <second_person_possessive> 'mind' {*} #= speak_mind
|'listen' 'to' <second_person_possessive> 'heart' {*} #= listen_heart
|'open' <second_person_possessive> 'mind' {*} #= open_mind
}
rule assignment {
|<second_person> <be> 'as' <adjective> 'as' <value> {*}
|<second_person> <be>? <value> {*}
}
rule branch {
[ 'let' 'us' | 'we' [ 'shall' | 'must' ] ] [ 'return' | 'proceed' ] 'to' 'scene' <roman> {*}
}
rule question {
<be> <value> <comparison> <value>{*}
}
rule comparison {
| ['more' <negative_adjective>
|'less' <positive_adjective>
|<negative_comparative>] 'than' {*} #= worse
| ['more' <positive_adjective>
|'less' <negative_adjective>
|<positive_comparative>] 'than' {*} #= better
| 'as' <adjective> 'as' {*} #= equal
}
rule test {
| 'if so,' <sentence> {*} #= if
| 'if not,' <sentence> {*} #= unless
}
rule computation {
<article>?
[
|<binary> {*} #= binary
|<unary> {*} #= unary
]
}
rule binary {
|'remainder' 'of' 'the' 'quotient' 'between' <value> 'and' <value> {*} #= mod
|'difference' 'between' <value> 'and' <value> {*} #= sub
|'sum' 'of' <value> 'and' <value> {*} #= add
|'product' 'of' <value> 'and' <value> {*} #= mul
|'quotient' 'between' <value> 'and' <value> {*} #= div
}
rule unary {
|'factorial' 'of' <value> {*} #= fact
|'square' 'of' <value> {*} #= square
|'square root' 'of' <value> {*} #= sqrt
|'cube' 'of' <value> {*} #= cube
|'twice' <value> {*} #= dup
}
rule value {
|<reference> {*} #= reference
|<immediate> {*} #= immediate
|<computation> {*} #= computation
}
rule immediate {
<article>? [<adjective> ]* <noun> {*}
}
token noun {
|<positive_noun>
|<negative_noun>
|<neutral_noun>
|<nothing>
}
token reference {
|<second_person_reflexive> {*} #= you_ref
|<second_person> {*} #= you_ref
|<first_person> {*} #= self_ref
|<first_person_reflexive> {*} #= self_ref
|<character> {*} #= named_ref
}
token adjective {
|<positive_adjective>
|<neutral_adjective>
|<negative_adjective>
|<first_person_possessive>
|<second_person_possessive>
|<third_person_possessive>
}
token roman {
['iii' | 'ii' | 'iv' | 'i' | 'vii' | 'vi' | 'v' ]
}
rule move {
'['
[
|'enter' <character> ['and' <character>]* {*} #= enter
# nqp does not have a flatten function, this enforces
# the iterability of a single match
|'exit' <character>**{1} {*} #= exit
|'exeunt' <character> ['and' <character>]+ {*} #= exit
|'exeunt' {*} #= exeunt
]
']'
}
token description {
<-end>*
}
|
