initial commit
This commit is contained in:
commit
bc55606a79
4 changed files with 43 additions and 0 deletions
5
betarules.rules
Normal file
5
betarules.rules
Normal file
|
@ -0,0 +1,5 @@
|
|||
term := Var | "\\" Var "." term @ label="abstraction" | term " " term @ label="application" | "(" term ")" @ hidden=True
|
||||
simple_type := Var | simple_type "->" simple_type @ label="arrow"
|
||||
|
||||
assoc "application" left
|
||||
assoc "arrow" right
|
8
lambda.lark
Normal file
8
lambda.lark
Normal file
|
@ -0,0 +1,8 @@
|
|||
start: term
|
||||
abstraction: "\\" VARIABLE "." term
|
||||
application: term " " term
|
||||
term: abstraction | application | VARIABLE | "(" term ")"
|
||||
|
||||
VARIABLE: LETTER+
|
||||
|
||||
%import common.LETTER
|
11
parsetest.py
Normal file
11
parsetest.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from lark import Lark
|
||||
|
||||
|
||||
with open("termdef.lark") as parse_file:
|
||||
parser = Lark(parse_file)
|
||||
|
||||
with open("betarules.rules") as b:
|
||||
rules_text = "\n".join(b.readlines())
|
||||
|
||||
print(parser.parse(rules_text).pretty())
|
||||
|
19
termdef.lark
Normal file
19
termdef.lark
Normal file
|
@ -0,0 +1,19 @@
|
|||
start: rule+
|
||||
rule: ntermdef | assocdef
|
||||
ntermdef: IDENTIFIER ":=" rhs ("|" rhs)*
|
||||
rhs: token+ ("@" annotation+)?
|
||||
token: STRING | IDENTIFIER
|
||||
annotation: IDENTIFIER "=" value
|
||||
assocdef: "assoc" STRING lr
|
||||
lr: LEFT | RIGHT
|
||||
LEFT: "left"
|
||||
RIGHT: "right"
|
||||
WORD: ("a".."z" | "0".."9")+
|
||||
|
||||
value: STRING | SIGNED_NUMBER | "True" | "False"
|
||||
|
||||
%import common.WS
|
||||
%import common.SIGNED_NUMBER
|
||||
%ignore WS
|
||||
%import common.ESCAPED_STRING -> STRING
|
||||
%import common.CNAME -> IDENTIFIER
|
Loading…
Add table
Reference in a new issue