From 1ecf0ed2bdc64479448cd53ecc61989a5ed029a7 Mon Sep 17 00:00:00 2001 From: arookas Date: Mon, 22 Feb 2016 20:00:22 -0500 Subject: [PATCH] Renamed various productions and nodes --- ssc/ast/nodes.operators.cs | 116 ++++++++++++++++++------------------- ssc/ast/nodes.variables.cs | 4 +- ssc/parser.cs | 68 +++++++++++----------- ssc/sunscript.grammar | 62 ++++++++++---------- 4 files changed, 125 insertions(+), 125 deletions(-) diff --git a/ssc/ast/nodes.operators.cs b/ssc/ast/nodes.operators.cs index 568c69d..af2bd0c 100644 --- a/ssc/ast/nodes.operators.cs +++ b/ssc/ast/nodes.operators.cs @@ -18,191 +18,191 @@ namespace arookas { } // precedence 0 - class sunLogOR : sunOperator { + class sunLogicalOrOperator : sunOperator { public override int Precedence { get { return 0; } } - public sunLogOR(sunSourceLocation location) + public sunLogicalOrOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteOR(); } } // precedence 1 - class sunLogAND : sunOperator { + class sunLogicalAndOperator : sunOperator { public override int Precedence { get { return 1; } } - public sunLogAND(sunSourceLocation location) + public sunLogicalAndOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteAND(); } } // precedence 2 - class sunBitOR : sunOperator { + class sunBitwiseOrOperator : sunOperator { public override int Precedence { get { return 2; } } - public sunBitOR(sunSourceLocation location) + public sunBitwiseOrOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteBOR(); } } // precedence 3 - class sunBitAND : sunOperator { + class sunBitwiseAndOperator : sunOperator { public override int Precedence { get { return 3; } } - public sunBitAND(sunSourceLocation location) + public sunBitwiseAndOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteBAND(); } } // precedence 4 - class sunEq : sunOperator { + class sunEqualOperator : sunOperator { public override int Precedence { get { return 4; } } - public sunEq(sunSourceLocation location) + public sunEqualOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteEQ(); } } - class sunNtEq : sunOperator { + class sunNotEqualOperator : sunOperator { public override int Precedence { get { return 4; } } - public sunNtEq(sunSourceLocation location) + public sunNotEqualOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteNE(); } } // precedence 5 - class sunLt : sunOperator { + class sunLessThanOperator : sunOperator { public override int Precedence { get { return 5; } } - public sunLt(sunSourceLocation location) + public sunLessThanOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteLT(); } } - class sunLtEq : sunOperator { + class sunLessEqualOperator : sunOperator { public override int Precedence { get { return 5; } } - public sunLtEq(sunSourceLocation location) + public sunLessEqualOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteLE(); } } - class sunGt : sunOperator { + class sunGreaterThanOperator : sunOperator { public override int Precedence { get { return 5; } } - public sunGt(sunSourceLocation location) + public sunGreaterThanOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteGT(); } } - class sunGtEq : sunOperator { + class sunGreaterEqualOperator : sunOperator { public override int Precedence { get { return 5; } } - public sunGtEq(sunSourceLocation location) + public sunGreaterEqualOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteGE(); } } // precedence 6 - class sunBitLsh : sunOperator { + class sunShiftLeftOperator : sunOperator { public override int Precedence { get { return 6; } } - public sunBitLsh(sunSourceLocation location) + public sunShiftLeftOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteSHL(); } } - class sunBitRsh : sunOperator { + class sunShiftRightOperator : sunOperator { public override int Precedence { get { return 6; } } - public sunBitRsh(sunSourceLocation location) + public sunShiftRightOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteSHR(); } } // precedence 7 - class sunAdd : sunOperator { + class sunAddOperator : sunOperator { public override int Precedence { get { return 7; } } - public sunAdd(sunSourceLocation location) + public sunAddOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteADD(); } } - class sunSub : sunOperator { + class sunSubtractOperator : sunOperator { public override int Precedence { get { return 7; } } - public sunSub(sunSourceLocation location) + public sunSubtractOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteSUB(); } } // precedence 8 - class sunMul : sunOperator { + class sunMultiplyOperator : sunOperator { public override int Precedence { get { return 8; } } - public sunMul(sunSourceLocation location) + public sunMultiplyOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteMUL(); } } - class sunDiv : sunOperator { + class sunDivideOperator : sunOperator { public override int Precedence { get { return 8; } } - public sunDiv(sunSourceLocation location) + public sunDivideOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteDIV(); } } - class sunMod : sunOperator { + class sunModuloOperator : sunOperator { public override int Precedence { get { return 8; } } - public sunMod(sunSourceLocation location) + public sunModuloOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteMOD(); } } // precedence 9 - class sunLogNOT : sunOperator { + class sunLogicalNotOperator : sunOperator { public override int Precedence { get { return 9; } } - public sunLogNOT(sunSourceLocation location) + public sunLogicalNotOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteNOT(); } } - class sunNeg : sunOperator { + class sunNegateOperator : sunOperator { public override int Precedence { get { return 9; } } - public sunNeg(sunSourceLocation location) + public sunNegateOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler) { compiler.Binary.WriteNEG(); } } // assignment operators - class sunAssign : sunOperator { + class sunAssignOperator : sunOperator { public override Associativity Associativity { get { return Associativity.Right; } } public override int Precedence { get { return -1; } } - public sunAssign(sunSourceLocation location) + public sunAssignOperator(sunSourceLocation location) : base(location) { } public virtual void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression) { @@ -211,8 +211,8 @@ namespace arookas { } } - class sunAssignAdd : sunAssign { - public sunAssignAdd(sunSourceLocation location) + class sunAssignAddOperator : sunAssignOperator { + public sunAssignAddOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression) { @@ -223,8 +223,8 @@ namespace arookas { } } - class sunAssignSub : sunAssign { - public sunAssignSub(sunSourceLocation location) + class sunAssignSubtractOperator : sunAssignOperator { + public sunAssignSubtractOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression) { @@ -235,8 +235,8 @@ namespace arookas { } } - class sunAssignMul : sunAssign { - public sunAssignMul(sunSourceLocation location) + class sunAssignMultiplyOperator : sunAssignOperator { + public sunAssignMultiplyOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression) { @@ -247,8 +247,8 @@ namespace arookas { } } - class sunAssignDiv : sunAssign { - public sunAssignDiv(sunSourceLocation location) + class sunAssignDivideOperator : sunAssignOperator { + public sunAssignDivideOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression) { @@ -259,8 +259,8 @@ namespace arookas { } } - class sunAssignMod : sunAssign { - public sunAssignMod(sunSourceLocation location) + class sunAssignModuloOperator : sunAssignOperator { + public sunAssignModuloOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression) { @@ -271,8 +271,8 @@ namespace arookas { } } - class sunAssignBitAND : sunAssign { - public sunAssignBitAND(sunSourceLocation location) + class sunAssignBitwiseAndOperator : sunAssignOperator { + public sunAssignBitwiseAndOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression) { @@ -283,8 +283,8 @@ namespace arookas { } } - class sunAssignBitOR : sunAssign { - public sunAssignBitOR(sunSourceLocation location) + class sunAssignBitwiseOrOperator : sunAssignOperator { + public sunAssignBitwiseOrOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression) { @@ -295,8 +295,8 @@ namespace arookas { } } - class sunAssignBitLsh : sunAssign { - public sunAssignBitLsh(sunSourceLocation location) + class sunAssignShiftLeftOperator : sunAssignOperator { + public sunAssignShiftLeftOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression) { @@ -307,8 +307,8 @@ namespace arookas { } } - class sunAssignBitRsh : sunAssign { - public sunAssignBitRsh(sunSourceLocation location) + class sunAssignShiftRightOperator : sunAssignOperator { + public sunAssignShiftRightOperator(sunSourceLocation location) : base(location) { } public override void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression) { diff --git a/ssc/ast/nodes.variables.cs b/ssc/ast/nodes.variables.cs index 59a461e..3a4c6f8 100644 --- a/ssc/ast/nodes.variables.cs +++ b/ssc/ast/nodes.variables.cs @@ -38,7 +38,7 @@ class sunVariableDefinition : sunNode { public sunIdentifier Name { get { return this[1] as sunIdentifier; } } - public sunAssign Operator { get { return this[2] as sunAssign; } } + public sunAssignOperator Operator { get { return this[2] as sunAssignOperator; } } public sunExpression Expression { get { return this[3] as sunExpression; } } public sunSymbolModifiers Modifiers { @@ -56,7 +56,7 @@ class sunStorableAssignment : sunNode { public sunIdentifier Name { get { return this[0] as sunIdentifier; } } - public sunAssign Operator { get { return this[1] as sunAssign; } } + public sunAssignOperator Operator { get { return this[1] as sunAssignOperator; } } public sunExpression Expression { get { return this[2] as sunExpression; } } public sunStorableAssignment(sunSourceLocation location) diff --git a/ssc/parser.cs b/ssc/parser.cs index 6cf5f86..38e9df8 100644 --- a/ssc/parser.cs +++ b/ssc/parser.cs @@ -90,11 +90,11 @@ namespace arookas { // literals switch (id) { - case __sunConstants.INT_NUMBER: return new sunIntLiteral(location, token); - case __sunConstants.HEX_NUMBER: return new sunHexLiteral(location, token); - case __sunConstants.DEC_NUMBER: return new sunFloatLiteral(location, token); - case __sunConstants.ADR_NUMBER: return new sunAddressLiteral(location, token); - case __sunConstants.STRING: return new sunStringLiteral(location, token); + case __sunConstants.INTEGER_LITERAL: return new sunIntLiteral(location, token); + case __sunConstants.HEX_LITERAL: return new sunHexLiteral(location, token); + case __sunConstants.FLOAT_LITERAL: return new sunFloatLiteral(location, token); + case __sunConstants.ADDRESS_LITERAL: return new sunAddressLiteral(location, token); + case __sunConstants.STRING_LITERAL: return new sunStringLiteral(location, token); case __sunConstants.IDENTIFIER: return new sunIdentifier(location, token); case __sunConstants.ELLIPSIS: return new sunEllipsis(location); case __sunConstants.TRUE: return new sunTrue(location); @@ -103,44 +103,44 @@ namespace arookas { // operators switch (id) { - case __sunConstants.ADD: return new sunAdd(location); + case __sunConstants.ADD: return new sunAddOperator(location); case __sunConstants.SUB: { if (parent == __sunConstants.UNARY_OPERATOR) { - return new sunNeg(location); + return new sunNegateOperator(location); } - return new sunSub(location); + return new sunSubtractOperator(location); } - case __sunConstants.MUL: return new sunMul(location); - case __sunConstants.DIV: return new sunDiv(location); - case __sunConstants.MOD: return new sunMod(location); + case __sunConstants.MUL: return new sunMultiplyOperator(location); + case __sunConstants.DIV: return new sunDivideOperator(location); + case __sunConstants.MOD: return new sunModuloOperator(location); - case __sunConstants.BIT_AND: return new sunBitAND(location); - case __sunConstants.BIT_OR: return new sunBitOR(location); - case __sunConstants.BIT_LSH: return new sunBitLsh(location); - case __sunConstants.BIT_RSH: return new sunBitRsh(location); + case __sunConstants.BAND: return new sunBitwiseAndOperator(location); + case __sunConstants.BOR: return new sunBitwiseOrOperator(location); + case __sunConstants.LSH: return new sunShiftLeftOperator(location); + case __sunConstants.RSH: return new sunShiftRightOperator(location); - case __sunConstants.LOG_AND: return new sunLogAND(location); - case __sunConstants.LOG_OR: return new sunLogOR(location); - case __sunConstants.LOG_NOT: return new sunLogNOT(location); + case __sunConstants.AND: return new sunLogicalAndOperator(location); + case __sunConstants.OR: return new sunLogicalOrOperator(location); + case __sunConstants.NOT: return new sunLogicalNotOperator(location); - case __sunConstants.EQ: return new sunEq(location); - case __sunConstants.NEQ: return new sunNtEq(location); - case __sunConstants.LT: return new sunLt(location); - case __sunConstants.GT: return new sunGt(location); - case __sunConstants.LTEQ: return new sunLtEq(location); - case __sunConstants.GTEQ: return new sunGtEq(location); + case __sunConstants.EQ: return new sunEqualOperator(location); + case __sunConstants.NE: return new sunNotEqualOperator(location); + case __sunConstants.LT: return new sunLessThanOperator(location); + case __sunConstants.GT: return new sunGreaterThanOperator(location); + case __sunConstants.LE: return new sunLessEqualOperator(location); + case __sunConstants.GE: return new sunGreaterEqualOperator(location); - case __sunConstants.ASSIGN: return new sunAssign(location); - case __sunConstants.ASSIGN_ADD: return new sunAssignAdd(location); - case __sunConstants.ASSIGN_SUB: return new sunAssignSub(location); - case __sunConstants.ASSIGN_MUL: return new sunAssignMul(location); - case __sunConstants.ASSIGN_DIV: return new sunAssignDiv(location); - case __sunConstants.ASSIGN_MOD: return new sunAssignMod(location); + case __sunConstants.ASSIGN: return new sunAssignOperator(location); + case __sunConstants.ASSIGN_ADD: return new sunAssignAddOperator(location); + case __sunConstants.ASSIGN_SUB: return new sunAssignSubtractOperator(location); + case __sunConstants.ASSIGN_MUL: return new sunAssignMultiplyOperator(location); + case __sunConstants.ASSIGN_DIV: return new sunAssignDivideOperator(location); + case __sunConstants.ASSIGN_MOD: return new sunAssignModuloOperator(location); - case __sunConstants.ASSIGN_BIT_AND: return new sunAssignBitAND(location); - case __sunConstants.ASSIGN_BIT_OR: return new sunAssignBitOR(location); - case __sunConstants.ASSIGN_BIT_LSH: return new sunAssignBitLsh(location); - case __sunConstants.ASSIGN_BIT_RSH: return new sunAssignBitRsh(location); + case __sunConstants.ASSIGN_BAND: return new sunAssignBitwiseAndOperator(location); + case __sunConstants.ASSIGN_BOR: return new sunAssignBitwiseOrOperator(location); + case __sunConstants.ASSIGN_LSH: return new sunAssignShiftLeftOperator(location); + case __sunConstants.ASSIGN_RSH: return new sunAssignShiftRightOperator(location); case __sunConstants.INCREMENT: return new sunIncrement(location); case __sunConstants.DECREMENT: return new sunDecrement(location); diff --git a/ssc/sunscript.grammar b/ssc/sunscript.grammar index 3deb192..c32b51d 100644 --- a/ssc/sunscript.grammar +++ b/ssc/sunscript.grammar @@ -17,8 +17,8 @@ IMPORT = "import" BUILTIN = "builtin" FUNCTION = "function" VAR = "var" -CONST = "const" LOCAL = "local" +CONST = "const" IF = "if" ELSE = "else" @@ -59,21 +59,21 @@ MUL = "*" DIV = "/" MOD = "%" -BIT_AND = "&" -BIT_OR = "|" -BIT_LSH = "<<" -BIT_RSH = ">>" +BAND = "&" +BOR = "|" +LSH = "<<" +RSH = ">>" -LOG_NOT = "!" -LOG_AND = "&&" -LOG_OR = "||" +NOT = "!" +AND = "&&" +OR = "||" EQ = "==" -NEQ = "!=" +NE = "!=" LT = "<" -LTEQ = "<=" +LE = "<=" GT = ">" -GTEQ = ">=" +GE = ">=" ASSIGN = "=" ASSIGN_ADD = "+=" @@ -81,21 +81,21 @@ ASSIGN_SUB = "-=" ASSIGN_MUL = "*=" ASSIGN_DIV = "/=" ASSIGN_MOD = "%=" -ASSIGN_BIT_AND = "&=" -ASSIGN_BIT_OR = "|=" -ASSIGN_BIT_LSH = "<<=" -ASSIGN_BIT_RSH = ">>=" +ASSIGN_BAND = "&=" +ASSIGN_BOR = "|=" +ASSIGN_LSH = "<<=" +ASSIGN_RSH = ">>=" INCREMENT = "++" DECREMENT = "--" // literals IDENTIFIER = <<[_A-Za-z][_A-Za-z0-9]*>> -DEC_NUMBER = <<-?[0-9]+\.[0-9]+>> -HEX_NUMBER = <<-?0x[0-9A-Fa-f]+>> -INT_NUMBER = <<-?[0-9]+>> -ADR_NUMBER = <<\$[0-9A-Fa-f]{8}>> -STRING = <<"(\\.|[^"])*">> +FLOAT_LITERAL = <<-?[0-9]+\.[0-9]+>> +HEX_LITERAL = <<-?0x[0-9A-Fa-f]+>> +INTEGER_LITERAL = <<-?[0-9]+>> +ADDRESS_LITERAL = <<\$[0-9A-Fa-f]{8}>> +STRING_LITERAL = <<"(\\.|[^"])*">> %productions% @@ -132,7 +132,7 @@ compound_statement_item = function_call; statement_block = L_BRACE {statement} R_BRACE; -import_statement = IMPORT STRING; +import_statement = IMPORT STRING_LITERAL; yield_statement = YIELD; exit_statement = EXIT; lock_statement = LOCK; @@ -141,14 +141,14 @@ unlock_statement = UNLOCK; name_label = IDENTIFIER COLON; // operators -assignment_operator = ASSIGN | ASSIGN_ADD | ASSIGN_SUB | ASSIGN_MUL | ASSIGN_DIV | ASSIGN_MOD | ASSIGN_BIT_AND | ASSIGN_BIT_OR | ASSIGN_BIT_LSH | ASSIGN_BIT_RSH; +assignment_operator = ASSIGN | ASSIGN_ADD | ASSIGN_SUB | ASSIGN_MUL | ASSIGN_DIV | ASSIGN_MOD | ASSIGN_BAND | ASSIGN_BOR | ASSIGN_LSH | ASSIGN_RSH; ternary_operator = expression QMARK expression COLON expression; binary_operator = ADD | SUB | MUL | DIV | MOD | // arithmetic - BIT_AND | BIT_OR | BIT_LSH | BIT_RSH | // bitwise - EQ | NEQ | LT | LTEQ | GT | GTEQ | // comparison - LOG_AND | LOG_OR; // logical -unary_operator = LOG_NOT | SUB; + BAND | BOR | LSH | RSH | // bitwise + EQ | NE | LT | LE | GT | GE | // comparison + AND | OR; // logical +unary_operator = NOT | SUB; augment_operator = INCREMENT | DECREMENT; // expressions @@ -158,11 +158,11 @@ term = function_call | variable_reference | variable_augment | - STRING | - DEC_NUMBER | - ADR_NUMBER | - HEX_NUMBER | - INT_NUMBER | + STRING_LITERAL | + FLOAT_LITERAL | + ADDRESS_LITERAL | + HEX_LITERAL | + INTEGER_LITERAL | TRUE | FALSE | L_PAREN expression R_PAREN |