aboutsummaryrefslogtreecommitdiff
path: root/examples/lisp.g
diff options
context:
space:
mode:
Diffstat (limited to 'examples/lisp.g')
-rw-r--r--examples/lisp.g13
1 files changed, 13 insertions, 0 deletions
diff --git a/examples/lisp.g b/examples/lisp.g
new file mode 100644
index 0000000..551e6f9
--- /dev/null
+++ b/examples/lisp.g
@@ -0,0 +1,13 @@
+parser Lisp:
+ ignore: r'\s+'
+ token NUM: r'[0-9]+'
+ token ID: r'[-+*/!@$%^&=.a-zA-Z0-9_]+'
+ token STR: r'"([^\\"]+|\\.)*"'
+
+ rule expr: ID {{ return ('id',ID) }}
+ | STR {{ return ('str',eval(STR)) }}
+ | NUM {{ return ('num',int(NUM)) }}
+ | r"\("
+ {{ e = [] }} # initialize the list
+ ( expr {{ e.append(expr) }} ) * # put each expr into the list
+ r"\)" {{ return e }} # return the list