From 429b770bc2d0949b7f3f2f4d96c44dd89ffdb7c7 Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Mon, 18 Jun 2012 16:02:48 +0000 Subject: [PATCH] X# --- source2/Compiler/Cosmos.XSharp/Parser.cs | 9 ++--- source2/Compiler/Cosmos.XSharp/Token.cs | 3 +- .../Compiler/Cosmos.XSharp/TokenPatterns.cs | 35 +++++++++++-------- source2/Users/Kudzu/Kudzu-Notes.html | 1 - 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/source2/Compiler/Cosmos.XSharp/Parser.cs b/source2/Compiler/Cosmos.XSharp/Parser.cs index cb5288c39..b98d379d5 100644 --- a/source2/Compiler/Cosmos.XSharp/Parser.cs +++ b/source2/Compiler/Cosmos.XSharp/Parser.cs @@ -90,7 +90,7 @@ namespace Cosmos.Compiler.XSharp { if (string.IsNullOrWhiteSpace(xString) && xString.Length > 0) { xToken.Type = TokenType.WhiteSpace; - } else if (char.IsLetter(xChar1) || xChar1 == '_') { + } else if (char.IsLetter(xChar1) || xChar1 == '_' || xChar1 == '.') { string xUpper = xString.ToUpper(); if (mAllowPatterns) { @@ -138,8 +138,6 @@ namespace Cosmos.Compiler.XSharp { xToken.Type = TokenType.Colon; } else if (xString == "$") { xToken.Type = TokenType.Dollar; - } else if (xString == ".") { - xToken.Type = TokenType.Dot; } else if (xString == ",") { xToken.Type = TokenType.Comma; } else if (xString == "<") { @@ -211,7 +209,10 @@ namespace Cosmos.Compiler.XSharp { xChar = mData[i]; if (char.IsWhiteSpace(xChar)) { xCharType = CharType.WhiteSpace; - } else if (char.IsLetterOrDigit(xChar) || xChar == '_') { + } else if (char.IsLetterOrDigit(xChar) || xChar == '_' || xChar == '.') { + // _ and . were never likely to stand on their own. ie ESP _ 2 and ESP . 2 are never likely to be used. + // Having them on their own required a lot of code + // to treat them as a single unit where we did use them. So we treat them as AlphaNum. xCharType = CharType.Identifier; } else { xCharType = CharType.Symbol; diff --git a/source2/Compiler/Cosmos.XSharp/Token.cs b/source2/Compiler/Cosmos.XSharp/Token.cs index 915efafa7..6df32b226 100644 --- a/source2/Compiler/Cosmos.XSharp/Token.cs +++ b/source2/Compiler/Cosmos.XSharp/Token.cs @@ -12,7 +12,8 @@ namespace Cosmos.Compiler.XSharp { // Values , ValueInt // Symbols - , Equals, BracketLeft, BracketRight, Plus, Minus, Colon, Dollar, CurlyLeft, CurlyRight, Dot, Comma, LessThan, GreaterThan, Question + // _ and . are AlphaNum. See comments in Parser + , Equals, BracketLeft, BracketRight, Plus, Minus, Colon, Dollar, CurlyLeft, CurlyRight, Comma, LessThan, GreaterThan, Question // , WhiteSpace // For now used during scanning while user is typing, but in future could be user methods we have to find etc diff --git a/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs b/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs index e7200915e..32a23a695 100644 --- a/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs +++ b/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs @@ -49,14 +49,18 @@ namespace Cosmos.Compiler.XSharp { return mGroup + "_" + mProcedureName + "_" + aLabel; } - protected string GetLabel(TokenList aTokens, int aIndex) { - if (aTokens[aIndex].Type == TokenType.AlphaNum) { - return ProcLabel(aIndex); - } else if (aTokens[aIndex + 1].Type == TokenType.Dot) { - return aTokens[aIndex + 2].Value; - } else { - return GroupLabel(aIndex + 1); + protected string GetLabel(Token aToken) { + if (aToken.Type != TokenType.AlphaNum) { + throw new Exception("Label must be AlphaNum."); } + + string xValue = aToken.Value; + if (xValue.StartsWith("..")) { + return xValue; + } else if (xValue.StartsWith(".")) { + return GroupLabel(xValue); + } + return ProcLabel(xValue); } protected void AddPatterns() { @@ -76,29 +80,29 @@ namespace Cosmos.Compiler.XSharp { // ..Name: - Global level. Emitted exactly as is. // .Name: - Group level. Group_Name // Name: - Procedure level. Group_ProcName_Name - AddPattern(new string[] { ".._ABC:", "._ABC:", "_ABC:" }, + AddPattern(new string[] { "_ABC:" }, delegate(TokenList aTokens, ref List rCode) { - rCode.Add("new Label(" + Quoted(GetLabel(aTokens, 0)) + ");"); + rCode.Add("new Label(" + Quoted(GetLabel(aTokens[0])) + ");"); } ); - AddPattern(new string[] { "Call .._ABC", "Call ._ABC", "Call _ABC" }, + AddPattern("Call _ABC" , delegate(TokenList aTokens, ref List rCode) { - rCode.Add("new Call {{ DestinationLabel = " + Quoted(GetLabel(aTokens, 1)) + " }};"); + rCode.Add("new Call {{ DestinationLabel = " + Quoted(GetLabel(aTokens[1])) + " }};"); } ); - AddPattern(new string[] { "if < goto .._ABC", "if < goto ._ABC", "if < goto _ABC" }, + AddPattern("if < goto _ABC", delegate(TokenList aTokens, ref List rCode) { - string xLabel = GetLabel(aTokens, 3); + string xLabel = GetLabel(aTokens[3]); rCode.Add("new ConditionalJump {{ Condition = ConditionalTestEnum.LessThan, DestinationLabel = " + Quoted(xLabel) + " }};"); } ); - AddPattern(new string[] { "if (_REG < 123) goto .._ABC", "if (_REG < 123) goto ._ABC", "if (_REG < 123) goto _ABC" }, + AddPattern("if (_REG < 123) goto _ABC", delegate(TokenList aTokens, ref List rCode) { rCode.Add("new Compare {{ DestinationReg = RegistersEnum.{2}, SourceValue = {4} }};"); - string xLabel = GetLabel(aTokens, 7); + string xLabel = GetLabel(aTokens[7]); rCode.Add("new ConditionalJump {{ Condition = ConditionalTestEnum.LessThan, DestinationLabel = " + Quoted(xLabel) + " }};"); } ); @@ -258,6 +262,7 @@ namespace Cosmos.Compiler.XSharp { } protected void AddPattern(string aPattern, CodeFunc aCode) { var xParser = new Parser(aPattern, false, true); + var xPattern = new Pattern() { Tokens = xParser.Tokens, Hash = xParser.Tokens.GetHashCode(), diff --git a/source2/Users/Kudzu/Kudzu-Notes.html b/source2/Users/Kudzu/Kudzu-Notes.html index adec90340..5db7593b8 100644 --- a/source2/Users/Kudzu/Kudzu-Notes.html +++ b/source2/Users/Kudzu/Kudzu-Notes.html @@ -34,7 +34,6 @@ To Do
  • X#
      -
    • _LABEL
    • Combine register code
    • Find out why installer doesnt replace XSharp extension without manual uninstall - important for user kit too