Created
April 26, 2018 12:31
-
-
Save Fhernd/3cf26db3a66f6f0c975e455c2a121d33 to your computer and use it in GitHub Desktop.
Tokenización de texto. OrtizOL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
NOMBRE = r'(?P<NAME>[a-zA-Z_][a-zA-Z_0-9]*)' | |
NUMERO = r'(?P<NUM>\d+)' | |
SUMA = r'(?P<PLUS>\+)' | |
PRODUCTO = r'(?P<TIMES>\*)' | |
IGUAL = r'(?P<EQ>=)' | |
ESPACIO = r'(?P<WS>\s+)' | |
patrones = re.compile('|'.join([NOMBRE, NUMERO, SUMA, PRODUCTO, IGUAL, ESPACIO])) | |
scanner = patrones.scanner('variable = 19') | |
print(scanner.match()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment