chkn / AluminumLua

NOTE: THIS WAS A TOY PROJECT AND IS NOT MAINTAINED
100 stars 13 forks source link

Added conditional statement if .. then .. else for interpreter #3

Closed nyashes closed 11 years ago

nyashes commented 11 years ago

Hello, I just added if .. then .. else in the interpreter because I needed it (but not in the compiler because I do not understand how it works) anyway the parser is ok and if you have some documentation on the compiler I would be happy to implement it

chkn commented 11 years ago

These look like solid improvements. However there are a lot of line ending changes and whitespace noise in your diffs that make them hard to review. I've added a gitattributes file that should cause git to normalize the line endings. Please also make sure you are using tabs and not spaces for indentation. It would also be nice if you squashed your revert commits so that the commit log only shows the meaningful changes. Thanks!

nyashes commented 11 years ago

Ok But I think that the problem is more vicious, in some case it was effectively an end of line problem but many other lines was rewritten by visual studio to match the "good presentation", I also squashed commits and and added your gitattributes file anyway in the LuaParser I added

//In method Parse
case "if":
        ParseConditionalStatement();
        if (CurrentExecutor is CompilerExecutor) CurrentExecutor.PopStack();
        break;
//In method TryParseOperator
case '+':
                    Consume();
                    ParseRVal();
                    CurrentExecutor.Add();
                    break;

                case '-':
                    Consume();
                    ParseRVal();
                    CurrentExecutor.Subtract();
                    break;

                case '*':
                    Consume();
                    ParseRVal();
                    CurrentExecutor.Multiply();
                    break;

                case '/':
                    Consume();
                    ParseRVal();
                    CurrentExecutor.Divide();
                    break;

                case 'o':
                case 'O':
                    Consume();
                    if (char.ToLowerInvariant(Consume()) != 'r')
                        Err("unexpected 'o'");
                    ParseRVal();
                    CurrentExecutor.Or();
                    break;

                case 'a':
                case 'A':
                    Consume();
                    if (char.ToLowerInvariant(Consume()) != 'n')
                        Err("unexpected 'a'");
                    if (char.ToLowerInvariant(Consume()) != 'd')
                        Err("unexpected 'an'");
                    ParseRVal();
                    CurrentExecutor.And();
                    break;
                case '>':
                    Consume();
                    bool OrEqual = Peek() == '=';
                    if (OrEqual) Consume();
                    ParseRVal();
                    if (OrEqual) CurrentExecutor.GreaterOrEqual(); else CurrentExecutor.Greater();
                    break;
                case '<':
                    Consume();
                    bool OrEqual2 = Peek() == '=';
                    if (OrEqual2) Consume();
                    ParseRVal();
                    if (OrEqual2) CurrentExecutor.SmallerOrEqual(); else CurrentExecutor.Smaller();
                    break;
                case '=':
                    Consume();
                    if (Consume() != '=')
                        Err("unexpected '='");
                    ParseRVal();
                    CurrentExecutor.Equal();
                    break;

                case '~':
                    Consume();
                    if (Consume() != '=')
                        Err("unexpected '~'");
                    ParseRVal();
                    CurrentExecutor.NotEqual();
                    break;
//Added protected void ParseConditionalStatement()

other files should be correct now