-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyparser.py
39 lines (30 loc) · 845 Bytes
/
myparser.py
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
import sp
import re
import os
from sp import *
from re import *
"""
Construction du parser pour les fichiers contenant les descriptions
textuelles des automates
"""
class MyParser :
@staticmethod
def Auto():
etat = R(r'\d+')
#etat = R(r'\w+')
with Separator(r'[\s\n\r]+'):
trans = '(' & etat & R(r'\w') & etat & ')'
listeEtats = etat[:]
listeInit = etat[:]
listeFin = etat[:]
listeTrans = trans[:]
auto = '#E:' & listeEtats & '#I:' & listeInit & '#F:'& listeFin & '#T:' & listeTrans
return auto
@staticmethod
def parseFromFile (nomFichier) :
fichier = open (nomFichier)
my_parser = MyParser.Auto()
s=fichier.read()
result = my_parser(s)
fichier.close()
return result