Untitled
Never
import pandas as pd class NodeStack: def __init__(self, symbol, lexeme): global count self.symbol = symbol self.lexeme = lexeme self.id = count + 1 count += 1 class NodeTree: def __init__(self, id, symbol, lexeme): self.id = id self.symbol = symbol self.lexeme = lexeme self.children = [] self.father = None tabla = pd.read_csv("tabla.csv", index_col=0) count = 0 stack = [] # init stack symbol_E = NodeStack('E', None) symbol_dollar = NodeStack('$', None) stack.append(symbol_dollar) stack.append(symbol_E) # init tree root = NodeTree(symbol_E.id, symbol_E.symbol, symbol_E.lexeme) input = [ {"symbol": "int", "lexeme": "4", "nroline": 2, "col": 2}, {"symbol": "+", "lexeme": "+", "nroline": 2, "col": 4}, {"symbol": "int", "lexeme": "5", "nroline": 2, "col": 6}, {"symbol": "$", "lexeme": "$", "nroline": 0, "col": 0}, ] while len(stack) > 0: current_input = input[0] top_symbol = stack[-1] if top_symbol.symbol == current_input["symbol"]: # Matched terminal, pop stack and consume input stack.pop(0) input.pop(0) elif top_symbol.symbol in tabla.columns and current_input["symbol"] in tabla.index: # Non-terminal, consult parsing table production = tabla.loc[top_symbol.symbol, current_input["symbol"]] if production == "e": # Empty production, pop stack stack.pop() else: # Replace top non-terminal with production in stack stack.pop() for symbol in reversed(production.split()): stack.append(NodeStack(symbol, None)) else: # Error, input not accepted by the language print("Error at line", current_input["nroline"], "column", current_input["col"]) break if len(stack) == 0 and len(input) == 0: print("Input accepted by the language") else: print("Input not accepted by the language")
Raw Text
-
fsdfvsdjuygasidtufascfdasdfca
50 sec ago
-
Breaking news - Update 1 - 12/11/2023 05:54:39
7 min ago
-
https://groups.google.com/g/sayuj79pdf/c/
14 min ago
-
Nirogihealthcare Is Here To Provide Expert slimer ras At Affordable Prices
22 min ago
-
Breaking news - Update 1 - 12/11/2023 05:28:04
34 min ago
-
4K HD - Full Gratis
36 min ago
-
Breaking news - Update 1 - 12/11/2023 05:21:38
40 min ago
-
sdafsf
43 min ago
-
Skuyliv
45 min ago
-
Breaking news - Update 1 - 12/11/2023 05:14:18
47 min ago