From 1c4377b4cb73d50cdaa3c2533f9493079f2a9331 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 17 Dec 2023 16:51:20 +0100 Subject: [PATCH] natural works --- src/find-natural.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/find-natural.py diff --git a/src/find-natural.py b/src/find-natural.py new file mode 100644 index 0000000..89bee31 --- /dev/null +++ b/src/find-natural.py @@ -0,0 +1,43 @@ +#!/usr/bin/python3 +import ply.lex +tokens = [ + 'NUMBER', + 'ANY' +] + +def t_NUMBER(t): + r'[^-\.,(0\d*)]([1-9][0-9]*)' + t.value = int(t.value) + print(t.value) + return t + +def t_error(t): + pass + +def t_ANY(t): + r'.' + pass + +def t_newline(t): + r'\n' + pass + +lexer = ply.lex.lex() + +data = """ +This is a text containing five 55 lines, two 2 of which are empty. +This is the second 2 non-empty line, +and this is the third 3 non-empty line 5758. +you are 0 + +bad stuff +0111001 +vsadads -500 +.5 +0.2324 +0,2324 +""" + +lexer.input(data) +for t in lexer: + pass