# implementacion de un lenguaje basico (gdos), basado en BASIC, con la finalidad de comprobar el interprete

from ply import *

keywords = (
    'LET','LEER','DATO','IMPRIMIR','CONTINUAR','SI','ENTONCES','PARA','PROX','A','ETAPA',
    'FIN','PARE','DEF','GOSUB','DIM','coment','RETORNA','CORRER','LISTA','NUEVO',
)

tokens = keywords + (
     'IGUAL','MAS','MENOS','POR','DIVIDE','ELEVADO',
     'IPAREN','DPAREN','MENOR','MENIGU','MAYOR','MAYIGU','DIFE',
     'COMA','PCOMA', 'ENTERO','DECIMAL', 'CADENAT',
     'ID','NLINEA'
)

t_ignore = ' \t'

def t_coment(t):
    r'coment .*'
    return t

def t_ID(t):
    r'[A-Z][A-Z0-9]*'
    if t.value in keywords:
        t.type = t.value
    return t
    
t_IGUAL  = r'='
t_MAS    = r'\+'
t_MENOS   = r'-'
t_POR   = r'\*'
t_ELEVADO   = r'\^'
t_DIVIDE  = r'/'
t_IPAREN  = r'\('
t_DPAREN  = r'\)'
t_MENOR      = r'<'
t_MENIGU      = r'<='
t_MAYOR      = r'>'
t_MAYIGU      = r'>='
t_DIFE      = r'<>'
t_COMA   = r'\,'
t_PCOMA    = r';'
t_ENTERO = r'\d+'    
t_DECIMAL   = r'((\d*\.\d+)(E[\+-]?\d+)?|([1-9]\d*E[\+-]?\d+))'
t_CADENAT  = r'\".*?\"'

def t_NLINEA(t):
    r'\n'
    t.lexer.lineno += 1
    return t

def t_error(t):
    print("Caracter Ilegal: %s" % t.value[0])
    t.lexer.skip(1)

lex.lex(debug=0)
fa050d110ccdc5ab6a29a28c75622ff5c637b064
<mask token>


def t_coment(t):
    """coment .*"""
    return t


def t_ID(t):
    """[A-Z][A-Z0-9]*"""
    if t.value in keywords:
        t.type = t.value
    return t


<mask token>


def t_NLINEA(t):
    """\\n"""
    t.lexer.lineno += 1
    return t


def t_error(t):
    print('Caracter Ilegal: %s' % t.value[0])
    t.lexer.skip(1)


<mask token>

<mask token>


def t_coment(t):
    """coment .*"""
    return t


def t_ID(t):
    """[A-Z][A-Z0-9]*"""
    if t.value in keywords:
        t.type = t.value
    return t


<mask token>


def t_NLINEA(t):
    """\\n"""
    t.lexer.lineno += 1
    return t


def t_error(t):
    print('Caracter Ilegal: %s' % t.value[0])
    t.lexer.skip(1)


lex.lex(debug=0)

<mask token>
keywords = ('LET', 'LEER', 'DATO', 'IMPRIMIR', 'CONTINUAR', 'SI',
    'ENTONCES', 'PARA', 'PROX', 'A', 'ETAPA', 'FIN', 'PARE', 'DEF', 'GOSUB',
    'DIM', 'coment', 'RETORNA', 'CORRER', 'LISTA', 'NUEVO')
tokens = keywords + ('IGUAL', 'MAS', 'MENOS', 'POR', 'DIVIDE', 'ELEVADO',
    'IPAREN', 'DPAREN', 'MENOR', 'MENIGU', 'MAYOR', 'MAYIGU', 'DIFE',
    'COMA', 'PCOMA', 'ENTERO', 'DECIMAL', 'CADENAT', 'ID', 'NLINEA')
t_ignore = ' \t'


def t_coment(t):
    """coment .*"""
    return t


def t_ID(t):
    """[A-Z][A-Z0-9]*"""
    if t.value in keywords:
        t.type = t.value
    return t


t_IGUAL = '='
t_MAS = '\\+'
t_MENOS = '-'
t_POR = '\\*'
t_ELEVADO = '\\^'
t_DIVIDE = '/'
t_IPAREN = '\\('
t_DPAREN = '\\)'
t_MENOR = '<'
t_MENIGU = '<='
t_MAYOR = '>'
t_MAYIGU = '>='
t_DIFE = '<>'
t_COMA = '\\,'
t_PCOMA = ';'
t_ENTERO = '\\d+'
t_DECIMAL = '((\\d*\\.\\d+)(E[\\+-]?\\d+)?|([1-9]\\d*E[\\+-]?\\d+))'
t_CADENAT = '\\".*?\\"'


def t_NLINEA(t):
    """\\n"""
    t.lexer.lineno += 1
    return t


def t_error(t):
    print('Caracter Ilegal: %s' % t.value[0])
    t.lexer.skip(1)


lex.lex(debug=0)

from ply import *
keywords = ('LET', 'LEER', 'DATO', 'IMPRIMIR', 'CONTINUAR', 'SI',
    'ENTONCES', 'PARA', 'PROX', 'A', 'ETAPA', 'FIN', 'PARE', 'DEF', 'GOSUB',
    'DIM', 'coment', 'RETORNA', 'CORRER', 'LISTA', 'NUEVO')
tokens = keywords + ('IGUAL', 'MAS', 'MENOS', 'POR', 'DIVIDE', 'ELEVADO',
    'IPAREN', 'DPAREN', 'MENOR', 'MENIGU', 'MAYOR', 'MAYIGU', 'DIFE',
    'COMA', 'PCOMA', 'ENTERO', 'DECIMAL', 'CADENAT', 'ID', 'NLINEA')
t_ignore = ' \t'


def t_coment(t):
    """coment .*"""
    return t


def t_ID(t):
    """[A-Z][A-Z0-9]*"""
    if t.value in keywords:
        t.type = t.value
    return t


t_IGUAL = '='
t_MAS = '\\+'
t_MENOS = '-'
t_POR = '\\*'
t_ELEVADO = '\\^'
t_DIVIDE = '/'
t_IPAREN = '\\('
t_DPAREN = '\\)'
t_MENOR = '<'
t_MENIGU = '<='
t_MAYOR = '>'
t_MAYIGU = '>='
t_DIFE = '<>'
t_COMA = '\\,'
t_PCOMA = ';'
t_ENTERO = '\\d+'
t_DECIMAL = '((\\d*\\.\\d+)(E[\\+-]?\\d+)?|([1-9]\\d*E[\\+-]?\\d+))'
t_CADENAT = '\\".*?\\"'


def t_NLINEA(t):
    """\\n"""
    t.lexer.lineno += 1
    return t


def t_error(t):
    print('Caracter Ilegal: %s' % t.value[0])
    t.lexer.skip(1)


lex.lex(debug=0)

# implementacion de un lenguaje basico (gdos), basado en BASIC, con la finalidad de comprobar el interprete

from ply import *

keywords = (
    'LET','LEER','DATO','IMPRIMIR','CONTINUAR','SI','ENTONCES','PARA','PROX','A','ETAPA',
    'FIN','PARE','DEF','GOSUB','DIM','coment','RETORNA','CORRER','LISTA','NUEVO',
)

tokens = keywords + (
     'IGUAL','MAS','MENOS','POR','DIVIDE','ELEVADO',
     'IPAREN','DPAREN','MENOR','MENIGU','MAYOR','MAYIGU','DIFE',
     'COMA','PCOMA', 'ENTERO','DECIMAL', 'CADENAT',
     'ID','NLINEA'
)

t_ignore = ' \t'

def t_coment(t):
    r'coment .*'
    return t

def t_ID(t):
    r'[A-Z][A-Z0-9]*'
    if t.value in keywords:
        t.type = t.value
    return t
    
t_IGUAL  = r'='
t_MAS    = r'\+'
t_MENOS   = r'-'
t_POR   = r'\*'
t_ELEVADO   = r'\^'
t_DIVIDE  = r'/'
t_IPAREN  = r'\('
t_DPAREN  = r'\)'
t_MENOR      = r'<'
t_MENIGU      = r'<='
t_MAYOR      = r'>'
t_MAYIGU      = r'>='
t_DIFE      = r'<>'
t_COMA   = r'\,'
t_PCOMA    = r';'
t_ENTERO = r'\d+'    
t_DECIMAL   = r'((\d*\.\d+)(E[\+-]?\d+)?|([1-9]\d*E[\+-]?\d+))'
t_CADENAT  = r'\".*?\"'

def t_NLINEA(t):
    r'\n'
    t.lexer.lineno += 1
    return t

def t_error(t):
    print("Caracter Ilegal: %s" % t.value[0])
    t.lexer.skip(1)

lex.lex(debug=0)