Compare commits

...

2 commits

Author SHA1 Message Date
abdff4f65c put more things in grammar 2019-03-09 18:58:28 -03:00
09f230985e remove unused grammar file
since we're moving to lark
2019-03-09 16:58:46 -03:00
3 changed files with 40 additions and 12 deletions

View file

@ -1,10 +0,0 @@
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
integer = ['-' | '+'] "0" digit {digit} ;
hex_letters = "a" | "b" | "c" | "d" | "e" | "f"
hex_integer = "0x", {hex_letters | digit} ;
oct_digits = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
octal_integer = "0o", {oct_digits} ;
program =

View file

@ -2,8 +2,12 @@
import sys
import pprint
import logging
from jortsc.parser.lexer import lex_jorts
from jortsc.parser.parser import parse
logging.basicConfig(level=logging.DEBUG)
def main():
"""main entry point"""
@ -16,5 +20,8 @@ def main():
pprint.pprint(tokens)
print([t[0] for t in tokens])
tree = parse(in_data)
print(tree)
if __name__ == '__main__':
main()

View file

@ -1,9 +1,40 @@
from lark import Lark
# TODO: write a grammar
GRAMMAR = """
yeet
FN: "fn"
IMPORT: "import"
COMMA: ","
DOT: "."
SINGLE_COMMENT: "//"
NEWLINE: /[ \\n\\t]+/
ANY: /.+/
WHITESPACE: " "
INTEGER: /[0-9]+/
ARROW: "->"
COM_START: "/*"
COM_END: "*/"
QUOTE: "\\""
identifier: WHITESPACE* ANY WHITESPACE*
single_comment: "//" ANY* NEWLINE
multi_comment: COM_START ANY* COM_END
import_stmt: IMPORT identifier NEWLINE
fn_arg: identifier identifier
fn_stmt: FN identifier? "(" [fn_arg COMMA] ")" [ARROW identifier] "{" [stmt NEWLINE]* "}"
sign_int: "+" | "-"
string: QUOTE ANY* QUOTE
value: (sign_int* INTEGER) | string
call_stmt: [identifier DOT] identifier "(" [value COMMA]* ")"
stmt: (NEWLINE*) | import_stmt | fn_stmt | call_stmt
start: (stmt NEWLINE)*
"""
def parse(string: str):