adding parser code
This commit is contained in:
parent
c7f5075842
commit
4ee05452c0
20
spf.py
20
spf.py
@ -7,17 +7,20 @@ import argparse
|
|||||||
import lark
|
import lark
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
class SPFTransformer(lark.Transformer):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
arg_parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("spf_file", help="Fichier source à interpréter")
|
arg_parser.add_argument("spf_file", help="Fichier source à interpréter")
|
||||||
parser.add_argument("-d", "--dump",
|
arg_parser.add_argument("-d", "--dump",
|
||||||
help="affichage de la mémoire du programme",
|
help="affichage de la mémoire du programme",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
parser.add_argument("-t", "--trace",
|
arg_parser.add_argument("-t", "--trace",
|
||||||
help="affichage de la mémoire au cours du programme",
|
help="affichage de la mémoire au cours du programme",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
args = parser.parse_args()
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
if args.dump:
|
if args.dump:
|
||||||
print("Dump activated (TODO)", file=sys.stderr)
|
print("Dump activated (TODO)", file=sys.stderr)
|
||||||
@ -25,6 +28,13 @@ def main():
|
|||||||
if args.trace:
|
if args.trace:
|
||||||
print("Trace activated (TODO)", file=sys.stderr)
|
print("Trace activated (TODO)", file=sys.stderr)
|
||||||
|
|
||||||
|
with open("spf.lark") as grammar:
|
||||||
|
spf_parser = lark.Lark(grammar, parser="lalr", transformer=SPFTransformer)
|
||||||
|
|
||||||
|
with open(args.spf_file) as spf_input:
|
||||||
|
program = spf_input.readall()
|
||||||
|
spf_parser.parse(program)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user