This commit is contained in:
kudzu_cp 2012-06-18 16:02:48 +00:00
parent 96bb89aaf5
commit 429b770bc2
4 changed files with 27 additions and 21 deletions

View file

@ -90,7 +90,7 @@ namespace Cosmos.Compiler.XSharp {
if (string.IsNullOrWhiteSpace(xString) && xString.Length > 0) { if (string.IsNullOrWhiteSpace(xString) && xString.Length > 0) {
xToken.Type = TokenType.WhiteSpace; xToken.Type = TokenType.WhiteSpace;
} else if (char.IsLetter(xChar1) || xChar1 == '_') { } else if (char.IsLetter(xChar1) || xChar1 == '_' || xChar1 == '.') {
string xUpper = xString.ToUpper(); string xUpper = xString.ToUpper();
if (mAllowPatterns) { if (mAllowPatterns) {
@ -138,8 +138,6 @@ namespace Cosmos.Compiler.XSharp {
xToken.Type = TokenType.Colon; xToken.Type = TokenType.Colon;
} else if (xString == "$") { } else if (xString == "$") {
xToken.Type = TokenType.Dollar; xToken.Type = TokenType.Dollar;
} else if (xString == ".") {
xToken.Type = TokenType.Dot;
} else if (xString == ",") { } else if (xString == ",") {
xToken.Type = TokenType.Comma; xToken.Type = TokenType.Comma;
} else if (xString == "<") { } else if (xString == "<") {
@ -211,7 +209,10 @@ namespace Cosmos.Compiler.XSharp {
xChar = mData[i]; xChar = mData[i];
if (char.IsWhiteSpace(xChar)) { if (char.IsWhiteSpace(xChar)) {
xCharType = CharType.WhiteSpace; 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; xCharType = CharType.Identifier;
} else { } else {
xCharType = CharType.Symbol; xCharType = CharType.Symbol;

View file

@ -12,7 +12,8 @@ namespace Cosmos.Compiler.XSharp {
// Values // Values
, ValueInt , ValueInt
// Symbols // 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 , WhiteSpace
// For now used during scanning while user is typing, but in future could be user methods we have to find etc // For now used during scanning while user is typing, but in future could be user methods we have to find etc

View file

@ -49,14 +49,18 @@ namespace Cosmos.Compiler.XSharp {
return mGroup + "_" + mProcedureName + "_" + aLabel; return mGroup + "_" + mProcedureName + "_" + aLabel;
} }
protected string GetLabel(TokenList aTokens, int aIndex) { protected string GetLabel(Token aToken) {
if (aTokens[aIndex].Type == TokenType.AlphaNum) { if (aToken.Type != TokenType.AlphaNum) {
return ProcLabel(aIndex); throw new Exception("Label must be AlphaNum.");
} else if (aTokens[aIndex + 1].Type == TokenType.Dot) {
return aTokens[aIndex + 2].Value;
} else {
return GroupLabel(aIndex + 1);
} }
string xValue = aToken.Value;
if (xValue.StartsWith("..")) {
return xValue;
} else if (xValue.StartsWith(".")) {
return GroupLabel(xValue);
}
return ProcLabel(xValue);
} }
protected void AddPatterns() { protected void AddPatterns() {
@ -76,29 +80,29 @@ namespace Cosmos.Compiler.XSharp {
// ..Name: - Global level. Emitted exactly as is. // ..Name: - Global level. Emitted exactly as is.
// .Name: - Group level. Group_Name // .Name: - Group level. Group_Name
// Name: - Procedure level. Group_ProcName_Name // Name: - Procedure level. Group_ProcName_Name
AddPattern(new string[] { ".._ABC:", "._ABC:", "_ABC:" }, AddPattern(new string[] { "_ABC:" },
delegate(TokenList aTokens, ref List<string> rCode) { delegate(TokenList aTokens, ref List<string> 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<string> rCode) { delegate(TokenList aTokens, ref List<string> 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<string> rCode) { delegate(TokenList aTokens, ref List<string> rCode) {
string xLabel = GetLabel(aTokens, 3); string xLabel = GetLabel(aTokens[3]);
rCode.Add("new ConditionalJump {{ Condition = ConditionalTestEnum.LessThan, DestinationLabel = " + Quoted(xLabel) + " }};"); 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<string> rCode) { delegate(TokenList aTokens, ref List<string> rCode) {
rCode.Add("new Compare {{ DestinationReg = RegistersEnum.{2}, SourceValue = {4} }};"); 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) + " }};"); 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) { protected void AddPattern(string aPattern, CodeFunc aCode) {
var xParser = new Parser(aPattern, false, true); var xParser = new Parser(aPattern, false, true);
var xPattern = new Pattern() { var xPattern = new Pattern() {
Tokens = xParser.Tokens, Tokens = xParser.Tokens,
Hash = xParser.Tokens.GetHashCode(), Hash = xParser.Tokens.GetHashCode(),

View file

@ -34,7 +34,6 @@
To Do</h3> To Do</h3>
<ul> <ul>
<li>X#<ul> <li>X#<ul>
<li>_LABEL</li>
<li>Combine register code</li> <li>Combine register code</li>
<li>Find out why installer doesnt replace XSharp extension without manual uninstall <li>Find out why installer doesnt replace XSharp extension without manual uninstall
- important for user kit too</li> - important for user kit too</li>