aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compilador/arbol.py (renamed from arbol.py)0
-rw-r--r--compilador/automatas/automata_cadenas.py (renamed from automata_cadenas.py)84
-rw-r--r--compilador/automatas/automata_caracteres.py (renamed from automata_caracteres.py)102
-rw-r--r--compilador/automatas/automata_enteros.py (renamed from automata_enteros.py)114
-rw-r--r--compilador/automatas/automata_flotantes.py (renamed from automata_flotantes.py)154
-rw-r--r--compilador/automatas/automata_identificadores.py (renamed from automata_identificadores.py)70
-rw-r--r--compilador/automatas/automata_operadores.py (renamed from automata_operadores.py)190
-rw-r--r--compilador/lexer.py (renamed from lexer.py)0
-rw-r--r--compilador/main.py38
-rw-r--r--compilador/parser.py (renamed from parser.py)0
-rw-r--r--compilador/shared.py (renamed from shared.py)0
-rw-r--r--compilador/tabla.py (renamed from tabla.py)0
-rw-r--r--main.py92
13 files changed, 395 insertions, 449 deletions
diff --git a/arbol.py b/compilador/arbol.py
index 7abcbe0..7abcbe0 100644
--- a/arbol.py
+++ b/compilador/arbol.py
diff --git a/automata_cadenas.py b/compilador/automatas/automata_cadenas.py
index 7170d4b..dc15a98 100644
--- a/automata_cadenas.py
+++ b/compilador/automatas/automata_cadenas.py
@@ -1,43 +1,43 @@
-class automata_cad:
- stateN = 0
-
- def isAccepted(self, _str):
- i = len(_str)
- _len = len(_str)
-
- for i in range(len):
- if self.stateN == 0:
- self.start(_str[i])
- if self.stateN == 1:
- self.state1(_str[i])
- if self.stateN == 2:
- self.state2(str[i])
- else:
- return 0
- if self.stateN == 2
- return 1
- else:
- return 0
-
- def start(self, c):
- if (c == '\"'):
- self.stateN = 1
- else:
- self.stateN = -1
-
- def state1(self,c):
- if (c != '\"'):
- self.stateN = 1
- else:
- self.stateN = 2
-
- def state2(self,c):
- self.stateN = -1
-
- def verified(self,token)
- {
- if isAccepted(token):
- return true
- else:
- return false
+class automata_cad:
+ stateN = 0
+
+ def isAccepted(self, _str):
+ i = len(_str)
+ _len = len(_str)
+
+ for i in range(len):
+ if self.stateN == 0:
+ self.start(_str[i])
+ if self.stateN == 1:
+ self.state1(_str[i])
+ if self.stateN == 2:
+ self.state2(str[i])
+ else:
+ return 0
+ if self.stateN == 2
+ return 1
+ else:
+ return 0
+
+ def start(self, c):
+ if (c == '\"'):
+ self.stateN = 1
+ else:
+ self.stateN = -1
+
+ def state1(self,c):
+ if (c != '\"'):
+ self.stateN = 1
+ else:
+ self.stateN = 2
+
+ def state2(self,c):
+ self.stateN = -1
+
+ def verified(self,token)
+ {
+ if isAccepted(token):
+ return true
+ else:
+ return false
} \ No newline at end of file
diff --git a/automata_caracteres.py b/compilador/automatas/automata_caracteres.py
index 341100a..139f86b 100644
--- a/automata_caracteres.py
+++ b/compilador/automatas/automata_caracteres.py
@@ -1,51 +1,51 @@
-class automata_car:
- stateN = 0
-
-
- def isAccepted(self, _str):
- i = len(_str)
- _len = len(_str)
-
- for i in range(len):
- if self.stateN == 0:
- self.start(_str[i])
- if self.stateN == 1:
- self.state1(_str[i])
- if self.stateN == 2:
- self.state2(_str[i])
- if self.stateN == 3:
- self.state3(_str[i])
- else:
- return 0
- if self.stateN == 3:
- return 1
- else:
- return 0
-
- def start(self,c):
- if (c == '\''):
- self.stateN = 1
- else:
- self.stateN = -1
-
- def state1(self,c):
- if (c != '\''):
- self.stateN = 2
- else:
- self.stateN = 3
-
- def state2(self,c):
- if (c == '\''):
- self.stateN = 3
- else:
- self.stateN = -1
-
- def state3(self,c):
- self.stateN = -1
-
- def verified(self,token){
- if isAccepted(token):
- return true
- else:
- return false
- }
+class automata_car:
+ stateN = 0
+
+
+ def isAccepted(self, _str):
+ i = len(_str)
+ _len = len(_str)
+
+ for i in range(len):
+ if self.stateN == 0:
+ self.start(_str[i])
+ if self.stateN == 1:
+ self.state1(_str[i])
+ if self.stateN == 2:
+ self.state2(_str[i])
+ if self.stateN == 3:
+ self.state3(_str[i])
+ else:
+ return 0
+ if self.stateN == 3:
+ return 1
+ else:
+ return 0
+
+ def start(self,c):
+ if (c == '\''):
+ self.stateN = 1
+ else:
+ self.stateN = -1
+
+ def state1(self,c):
+ if (c != '\''):
+ self.stateN = 2
+ else:
+ self.stateN = 3
+
+ def state2(self,c):
+ if (c == '\''):
+ self.stateN = 3
+ else:
+ self.stateN = -1
+
+ def state3(self,c):
+ self.stateN = -1
+
+ def verified(self,token){
+ if isAccepted(token):
+ return true
+ else:
+ return false
+ }
diff --git a/automata_enteros.py b/compilador/automatas/automata_enteros.py
index 1b5fcb8..c97659e 100644
--- a/automata_enteros.py
+++ b/compilador/automatas/automata_enteros.py
@@ -1,58 +1,58 @@
-class automata_ent:
- stateN = 0
-
- def isAccepted(self, _str):
- i = len(_str)
- _len = len(_str)
-
- for i in range(len):
- if self.stateN == 0:
- self.start(_str[i])
- if self.stateN == 1:
- self.state1(_str[i])
- if self.stateN == 2:
- self.state2(_str[i])
- if self.stateN == 3:
- self.state3(_str[i])
- else:
- return 0
- if self.stateN == 2 or self.stateN == 3:
- return 1
- else:
- return 0
-
-
- def start(self,c):
- if(c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or c == '6' or c == '7' or c == '8' or c == '9'):
- self.stateN = 3
- else if (c == '0'):
- self.stateN = 2
- else if (c == '-'):
- self.stateN = 1
- else
- self.stateN = -1
-
- def state1(self,c):
- if (c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or c == '6' or c == '7' or c == '8' or c == '9'):
- self.stateN = 3
- else:
- self.stateN = -1
-
- def state2(self,c):
- self.stateN = -1
-
- def state3(self,c)
- {
- if c.isdigit():
- self.stateN = 3
- else:
- self.stateN = -1
- }
-
- def verified(self,token)
- {
- if isAccepted(token):
- return true
- else:
- return false
+class automata_ent:
+ stateN = 0
+
+ def isAccepted(self, _str):
+ i = len(_str)
+ _len = len(_str)
+
+ for i in range(len):
+ if self.stateN == 0:
+ self.start(_str[i])
+ if self.stateN == 1:
+ self.state1(_str[i])
+ if self.stateN == 2:
+ self.state2(_str[i])
+ if self.stateN == 3:
+ self.state3(_str[i])
+ else:
+ return 0
+ if self.stateN == 2 or self.stateN == 3:
+ return 1
+ else:
+ return 0
+
+
+ def start(self,c):
+ if(c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or c == '6' or c == '7' or c == '8' or c == '9'):
+ self.stateN = 3
+ else if (c == '0'):
+ self.stateN = 2
+ else if (c == '-'):
+ self.stateN = 1
+ else
+ self.stateN = -1
+
+ def state1(self,c):
+ if (c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or c == '6' or c == '7' or c == '8' or c == '9'):
+ self.stateN = 3
+ else:
+ self.stateN = -1
+
+ def state2(self,c):
+ self.stateN = -1
+
+ def state3(self,c)
+ {
+ if c.isdigit():
+ self.stateN = 3
+ else:
+ self.stateN = -1
+ }
+
+ def verified(self,token)
+ {
+ if isAccepted(token):
+ return true
+ else:
+ return false
} \ No newline at end of file
diff --git a/automata_flotantes.py b/compilador/automatas/automata_flotantes.py
index 5ba2b7d..b7be7d8 100644
--- a/automata_flotantes.py
+++ b/compilador/automatas/automata_flotantes.py
@@ -1,78 +1,78 @@
-class automata_flot:
- stateN = 0
- def isAccepted(self, _str):
- i = len(_str)
- _len = len(_str)
-
- for i in range(len):
- if self.stateN == 0:
- self.start(_str[i])
- if self.stateN == 1:
- self.state1(_str[i])
- if self.stateN == 2:
- self.state2(_str[i])
- if self.stateN == 3:
- self.state3(_str[i])
- if self.stateN == 4:
- self.state4(_str[i])
- if self.stateN == 5:
- self.state5(_str[i])
- else:
- return 0
-
- if self.stateN == 5:
- return 1
- else:
- return 0
-
- def start(self, c):
- if (c == '0'):
- self.stateN = 1
- else if(c == '-'):
- self.stateN = 2
- else if(c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or
- c == '6' or c == '7' or c == '8' or c == '9'):
- self.stateN = 3
- else:
- self.stateN = -1
-
- def state1(self,c):
- if (c == '.'):
- self.stateN = 4
- else:
- self.stateN = -1
-
- def state2(self,c):
- if(c == '0'):
- self.stateN = 1
- else if(c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or
- c == '6' or c == '7' or c == '8' or c == '9'):
- self.stateN = 3
- else:
- self.stateN = -1
-
- def state3(self,c):
- if(c == '.'):
- self.stateN = 4
- else if c.isdigit():
- stateN = 3
- else:
- self.stateN = -1
-
- def state4(self,c):
- if c.isdigit():
- self.stateN = 5
- else:
- self.stateN = -1
-
- def state5(self,c):
- if c.isdigit():
- self.stateN = 5
- else:
- self.stateN = -1
-
- def verified(self,token):
- if isAccepted(token)
- return true
- else:
+class automata_flot:
+ stateN = 0
+ def isAccepted(self, _str):
+ i = len(_str)
+ _len = len(_str)
+
+ for i in range(len):
+ if self.stateN == 0:
+ self.start(_str[i])
+ if self.stateN == 1:
+ self.state1(_str[i])
+ if self.stateN == 2:
+ self.state2(_str[i])
+ if self.stateN == 3:
+ self.state3(_str[i])
+ if self.stateN == 4:
+ self.state4(_str[i])
+ if self.stateN == 5:
+ self.state5(_str[i])
+ else:
+ return 0
+
+ if self.stateN == 5:
+ return 1
+ else:
+ return 0
+
+ def start(self, c):
+ if (c == '0'):
+ self.stateN = 1
+ else if(c == '-'):
+ self.stateN = 2
+ else if(c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or
+ c == '6' or c == '7' or c == '8' or c == '9'):
+ self.stateN = 3
+ else:
+ self.stateN = -1
+
+ def state1(self,c):
+ if (c == '.'):
+ self.stateN = 4
+ else:
+ self.stateN = -1
+
+ def state2(self,c):
+ if(c == '0'):
+ self.stateN = 1
+ else if(c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or
+ c == '6' or c == '7' or c == '8' or c == '9'):
+ self.stateN = 3
+ else:
+ self.stateN = -1
+
+ def state3(self,c):
+ if(c == '.'):
+ self.stateN = 4
+ else if c.isdigit():
+ stateN = 3
+ else:
+ self.stateN = -1
+
+ def state4(self,c):
+ if c.isdigit():
+ self.stateN = 5
+ else:
+ self.stateN = -1
+
+ def state5(self,c):
+ if c.isdigit():
+ self.stateN = 5
+ else:
+ self.stateN = -1
+
+ def verified(self,token):
+ if isAccepted(token)
+ return true
+ else:
return false \ No newline at end of file
diff --git a/automata_identificadores.py b/compilador/automatas/automata_identificadores.py
index 7955616..c26adfb 100644
--- a/automata_identificadores.py
+++ b/compilador/automatas/automata_identificadores.py
@@ -1,36 +1,36 @@
-class automata_ident:
- stateN = 0
-
- def isAccepted(self, _str):
- i = len(_str)
- _len = len(_str)
-
- for i in range(len):
- if self.stateN == 0:
- self.start(_str[i])
- if self.stateN == 1:
- self.state1(_str[i])
- else:
- return 0
- if self.stateN == 1:
- return 1
- else:
- return 0
-
- def start(self, c):
- if (c.isalpha() or c == '_'):
- self.stateN = 1
- else:
- self.stateN = -1
-
- def state1(self, c):
- if (c.isalpha() or c == '_' or c.isdigit()):
- self.stateN = 1
- else:
- self.stateN = -1
-
- def no_es_main(self,token):
- if isAccepted(token):
- return true
- else:
+class automata_ident:
+ stateN = 0
+
+ def isAccepted(self, _str):
+ i = len(_str)
+ _len = len(_str)
+
+ for i in range(len):
+ if self.stateN == 0:
+ self.start(_str[i])
+ if self.stateN == 1:
+ self.state1(_str[i])
+ else:
+ return 0
+ if self.stateN == 1:
+ return 1
+ else:
+ return 0
+
+ def start(self, c):
+ if (c.isalpha() or c == '_'):
+ self.stateN = 1
+ else:
+ self.stateN = -1
+
+ def state1(self, c):
+ if (c.isalpha() or c == '_' or c.isdigit()):
+ self.stateN = 1
+ else:
+ self.stateN = -1
+
+ def no_es_main(self,token):
+ if isAccepted(token):
+ return true
+ else:
return false \ No newline at end of file
diff --git a/automata_operadores.py b/compilador/automatas/automata_operadores.py
index 354bfe8..af10e61 100644
--- a/automata_operadores.py
+++ b/compilador/automatas/automata_operadores.py
@@ -1,96 +1,96 @@
-
-class automata_ope:
- stateN = 0
-
- def isAccepted(self, _str):
- i = len(_str)
- _len = len(_str)
-
- for i in range(len):
- if self.stateN == 0:
- self.start(_str[i])
- if self.stateN == 1:
- self.state1(_str[i])
- if self.stateN == 2:
- self.state2(_str[i])
- if self.stateN == 3:
- self.state3(_str[i])
- if self.stateN == 4:
- self.start4(_str[i])
- if self.stateN == 5:
- self.state5(_str[i])
- if self.stateN == 6:
- self.state6(_str[i])
- if self.stateN == 7:
- self.state7(_str[i])
- if self.stateN == 8:
- self.state8(_str[i])
- else:
- return 0
- if (self.stateN == 1 or self.stateN == 7 or self.stateN == 8 or self.stateN == 2 or self.stateN == 3 or self.stateN == 6):
- return 1
- else:
- return 0
-
- def start(self,c):
- if(c == '=' or c == '>' or c == '<' or c == '/' or c == '*' or c == '%' or c == '!'):
- self.stateN = 1
- else if(c == '&'):
- self.stateN = 4
- else if(c == '|'):
- self.stateN = 5
- else if(c == '-'):
- selfstateN = 6
- else if(c == '+'):
- selfstateN = 3
- else:
- self.stateN = -1
-
- def state1(self,c):
- if(c == '='):
- self.stateN = 2
- else:
- self.stateN = -1
-
- def state2(self,c):
- self.stateN = -1
-
- def state3(self,c):
- if(c == '+'):
- self.stateN = 7
- else if(c == '='):
- self.stateN = 2
- else:
- self.stateN = -1
-
- def state4(self,c):
- if(c == '&'):
- self.stateN = 2
- else:
- self.stateN = -1
-
- def state5(self,c):
- if(c == '|'):
- self.stateN = 2
- else:
- self.stateN = -1
-
- def state6(self,c):
- if(c == '-'):
- self.stateN = 8
- else if(c == '='):
- self.stateN = 2
- else:
- self.stateN = -1
-
- def state7(self,c):
- self.stateN = -1
-
- def state8(self,c):
- self.stateN = -1
-
- def verified(self,token):
- if isAccepted(token):
- return true
- else:
+
+class automata_ope:
+ stateN = 0
+
+ def isAccepted(self, _str):
+ i = len(_str)
+ _len = len(_str)
+
+ for i in range(len):
+ if self.stateN == 0:
+ self.start(_str[i])
+ if self.stateN == 1:
+ self.state1(_str[i])
+ if self.stateN == 2:
+ self.state2(_str[i])
+ if self.stateN == 3:
+ self.state3(_str[i])
+ if self.stateN == 4:
+ self.start4(_str[i])
+ if self.stateN == 5:
+ self.state5(_str[i])
+ if self.stateN == 6:
+ self.state6(_str[i])
+ if self.stateN == 7:
+ self.state7(_str[i])
+ if self.stateN == 8:
+ self.state8(_str[i])
+ else:
+ return 0
+ if (self.stateN == 1 or self.stateN == 7 or self.stateN == 8 or self.stateN == 2 or self.stateN == 3 or self.stateN == 6):
+ return 1
+ else:
+ return 0
+
+ def start(self,c):
+ if(c == '=' or c == '>' or c == '<' or c == '/' or c == '*' or c == '%' or c == '!'):
+ self.stateN = 1
+ else if(c == '&'):
+ self.stateN = 4
+ else if(c == '|'):
+ self.stateN = 5
+ else if(c == '-'):
+ selfstateN = 6
+ else if(c == '+'):
+ selfstateN = 3
+ else:
+ self.stateN = -1
+
+ def state1(self,c):
+ if(c == '='):
+ self.stateN = 2
+ else:
+ self.stateN = -1
+
+ def state2(self,c):
+ self.stateN = -1
+
+ def state3(self,c):
+ if(c == '+'):
+ self.stateN = 7
+ else if(c == '='):
+ self.stateN = 2
+ else:
+ self.stateN = -1
+
+ def state4(self,c):
+ if(c == '&'):
+ self.stateN = 2
+ else:
+ self.stateN = -1
+
+ def state5(self,c):
+ if(c == '|'):
+ self.stateN = 2
+ else:
+ self.stateN = -1
+
+ def state6(self,c):
+ if(c == '-'):
+ self.stateN = 8
+ else if(c == '='):
+ self.stateN = 2
+ else:
+ self.stateN = -1
+
+ def state7(self,c):
+ self.stateN = -1
+
+ def state8(self,c):
+ self.stateN = -1
+
+ def verified(self,token):
+ if isAccepted(token):
+ return true
+ else:
return false \ No newline at end of file
diff --git a/lexer.py b/compilador/lexer.py
index 1952a16..1952a16 100644
--- a/lexer.py
+++ b/compilador/lexer.py
diff --git a/compilador/main.py b/compilador/main.py
new file mode 100644
index 0000000..c27c107
--- /dev/null
+++ b/compilador/main.py
@@ -0,0 +1,38 @@
+import sys, getopt
+from tkinter import *
+from tkinter import ttk, filedialog
+from lexer import *
+
+class Main:
+ input_file = None
+ output_file = None
+
+ def print_help (self, arg0):
+ print("Uso: % s -i entrada.ñ -o salida.ñ" % arg0)
+ print(" % s -h" % arg0)
+
+ def main(self, argv):
+ try:
+ opts, args = getopt.getopt(argv[1:], "hi:o:", ["input=", "output="])
+ except getopt.GetoptError as err:
+ print(err)
+ print_help(argv[0]);
+ sys.exit(2)
+
+ for o, a in opts:
+ if o == "-h":
+ self.print_help (argv[0])
+ elif o in ("-i", "--input"):
+ self.input_file = a
+ elif o in ("-o", "--output"):
+ self.output_file = a
+ else:
+ assert False, "opción desconocida"
+
+ if self.input_file and self.output_file:
+ with open(self.input_file) as f:
+ data = f.read()
+ Lexer(data).inicio()
+
+if __name__ == "__main__":
+ Main().main(sys.argv)
diff --git a/parser.py b/compilador/parser.py
index 61ab21a..61ab21a 100644
--- a/parser.py
+++ b/compilador/parser.py
diff --git a/shared.py b/compilador/shared.py
index e356255..e356255 100644
--- a/shared.py
+++ b/compilador/shared.py
diff --git a/tabla.py b/compilador/tabla.py
index c8ca424..c8ca424 100644
--- a/tabla.py
+++ b/compilador/tabla.py
diff --git a/main.py b/main.py
deleted file mode 100644
index c541b16..0000000
--- a/main.py
+++ /dev/null
@@ -1,92 +0,0 @@
-import sys, getopt
-from tkinter import *
-from tkinter import ttk, filedialog
-from lexer import *
-
-class Main:
- input_file = None
- output_file = None
-
- # GUI widgets
- text = None
- msgarea = None
- symbols = None
-
- def abrir_archivo(self):
- self.input_file = filedialog.askopenfilename()
- with open(self.input_file) as f:
- data = f.read()
- self.text.insert(END, data)
-
- def guardar_archivo(self):
- data = self.text.get('1.0', 'end-1c')
- with open(self.input_file, "r+") as f:
- f.truncate(0)
- f.write(data)
-
- def compilar_programa(self):
- self.output_file = filedialog.asksaveasfilename()
- data = self.text.get('1.0', 'end-1c')
- Lexer(data).inicio()
-
- def ejecutar_programa(self):
- print('ejecutar_programa()')
-
- def salir(self):
- exit(0)
-
- def main_gui(self, argv):
- root = Tk()
- root.title ("Javañol")
- root.columnconfigure(0, weight=1)
- root.rowconfigure(0, weight=1)
- root.option_add('*tearOff', FALSE)
-
- mainframe = ttk.Frame(root, padding="3 3 12 12")
- mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
- mainframe.columnconfigure(0, weight=1)
- mainframe.rowconfigure(0, weight=1)
- mainframe.rowconfigure(1, weight=0)
-
- # Menú
- menubar = Menu(root)
- root['menu'] = menubar
-
- menu_file = Menu(menubar)
- menubar.add_cascade(menu=menu_file, label='Archivo')
- menu_file.add_command(label='Abrir', command=self.abrir_archivo)
- menu_file.add_command(label='Guardar', command=self.guardar_archivo)
- menu_file.add_command(label='Salir', command=self.salir)
-
- menu_program = Menu(menubar)
- menubar.add_cascade(menu=menu_program, label='Programa')
- menu_program.add_command(label='Compilar', command=self.compilar_programa)
- menu_program.add_command(label='Ejecutar', command=self.ejecutar_programa)
-
- # Editor de código
- self.text = Text(mainframe)
- self.text.grid(column=0, row=0, sticky=(N, W, E, S))
-
- # Área de mensajes
- msgarealf = LabelFrame(mainframe, text='Área de mensajes', height=10)
- msgarealf.grid(column=0, row=1, sticky=(W, E, S))
-
- self.msgarea = Text(msgarealf, height=10)
- self.msgarea.grid(column=0, row=0, sticky=(N, W, E, S))
- self.msgarea.rowconfigure(0, weight=1)
- self.msgarea.columnconfigure(0, weight=1)
-
- # Tabla de símbolos
- symbolslf = LabelFrame(mainframe, text='Símbolos', width=100)
- symbolslf.grid(column=1, row=0, rowspan=2, sticky=(N, W, E, S))
-
- self.symbols = Text(symbolslf, width=20)
- self.symbols.grid(column=0, row=0, sticky=(N, W, E, S))
- self.msgarea.rowconfigure(0, weight=1)
- self.msgarea.columnconfigure(0, weight=1)
-
- root.mainloop()
-
-if __name__ == "__main__":
- main = Main()
- main.main_gui(sys.argv)