remoo69 / Compiler-Sheesh

Compiler for the self-developed language Sheesh#.
MIT License
2 stars 1 forks source link

infinite loop when this input is entered in Lexer #60

Open jldav1d opened 3 weeks ago

jldav1d commented 3 weeks ago

Code: \\

This code produces an infinite loop, causing the whole compiler to crash

After tinkering with the source code using the VS code debugger with breakpoints. It may be a bug within the get_symbol function which doesn't return the remaining characters when the input is the code above.

def get_symbol(token):
    try:
        size=len(token)
        i=0
        symbol_buffer=''
        if token[i]=="#" and len(token)==1:
            return token, token.replace(token, '', 1)
        elif token[i] in const.all_symbols_nonop and token[i+1] in const.symbols_delims[token[i]]:
            symbol_buffer+=token[i]
            return token[i], token.replace(token[i], '', 1)
        elif token[i:2]=="::" and (len(token)==2 or token[i+2] in const.symbols_delims["::"]): 
                return "::", token.replace("::", '', 1)

    except IndexError:
        if token in const.grouping_symbols and None in const.symbols_delims[token]:
            return token, token.replace(token, '', 1)
remoo69 commented 3 weeks ago

image the issue might've been because "\" isn't in any symbol list. I've put it into the "invalid_symbols" category. Will this conflict with anything? Do we use \ for anything other than withing text?

jldav1d commented 3 weeks ago

Will this conflict with anything?

Nope, I don't think so.

Do we use \ for anything other than withing text?

As far as i know, no. But "\", based on our document, is used to display "\" onto the screen. So another thing to check if it works on the Lexer.