aboutsummaryrefslogtreecommitdiff
path: root/compilador/parser.py
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-11-25 12:11:08 -0600
committerIván Ávalos <avalos@disroot.org>2022-11-25 12:11:08 -0600
commiteb4a3019bc0251e5b2b8229679e3c65d61d55336 (patch)
treef6b2a89dd35374272bd671933bfe87da4a587215 /compilador/parser.py
parent6b4e9a4e95eb511c194200e38ee323091dc5d7d2 (diff)
downloadjavanol-eb4a3019bc0251e5b2b8229679e3c65d61d55336.tar.gz
javanol-eb4a3019bc0251e5b2b8229679e3c65d61d55336.tar.bz2
javanol-eb4a3019bc0251e5b2b8229679e3c65d61d55336.zip
Buen progreso, pero se cicla
Diffstat (limited to 'compilador/parser.py')
-rw-r--r--compilador/parser.py54
1 files changed, 10 insertions, 44 deletions
diff --git a/compilador/parser.py b/compilador/parser.py
index b1fd411..82ee3c8 100644
--- a/compilador/parser.py
+++ b/compilador/parser.py
@@ -1,13 +1,10 @@
-from enum import Enum
-from tabla import LexToken, TablaLex, tokens
-from arbol import Arbol, Nodo
-from shared import Control
+import sys
from pprint import pprint
-from errors import Error
-from typing import NoReturn
-from tabla import TablaLex, Token
+from tabla import TablaLex
from errors import Error
+from parse.base import BaseParser
+from parse.unit import ParseUnit
class Parser:
def __init__(self, input_file: str):
@@ -16,42 +13,11 @@ class Parser:
self.iterador = self.tabla.iterar()
def inicio(self):
- tok = self.want(Token.STRING_LIT, Token.BOOLEAN_LIT)
- if type(tok) == Error:
- print(tok.message)
+ parser = BaseParser(self.iterador)
+ unit = ParseUnit(parser).unit()
+ if type(unit) is Error:
+ print (unit.message, file=sys.stderr)
return 1
- return 0
-
- ''' Requires the next token to have a matching ltok. Returns that
- token, or an error. '''
- def want(self, *want: Token) -> (Token | Error):
- tok: LexToken = next(self.iterador)
- if len(want) == 0:
- return tok
- for w in want:
- if tok.tipo == w:
- return tok
- return Error(got = tok.tipo, expects = want, numlinea = tok.numlinea)
- ''' Looks for a matching ltok from the lexer, and if not present,
- unlexes the token and returns void. If found, the token is
- consumed from the lexer and is returned. '''
- def _try(self, *want: Token) -> (Token | NoReturn):
- tok: LexToken = next(self.iterador)
- if len(want) == 0:
- return tok
- for w in want:
- if tok.tipo == w:
- return tok
- self.iterador.seek(-1)
-
- ''' Looks for a matching ltok from the lexer, unlexes the token,
- and returns it; or void if it was not an ltok. '''
- def peek(self, *want: Token) -> (Token | NoReturn):
- tok: LexToken = next(self.iterador)
- self.iterador.seek(-1)
- if len(want) == 0:
- return tok
- for w in want:
- if tok.tipo == w:
- return tok
+ pprint(self.unit)
+ return 0