aboutsummaryrefslogtreecommitdiff
path: root/compilador/parser.py
diff options
context:
space:
mode:
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