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) {
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;

View file

@ -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

View file

@ -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<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) {
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) {
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<string> 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(),

View file

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