internal Field(string name, UoToken uotypetoken, ScopedNode locationnode, ParsingContext context, bool isconst = false) { Name = name; Description = string.Empty; Node = locationnode; if (Node != null) { AddReference(Node); } if (uotypetoken != null) { UoTypeToken = uotypetoken; Type = uotypetoken.Value; } else { Type = null; UoTypeToken = null; } Value = null; DefFilename = context.CurrentParseTree.FileName; isConst = isconst; }
public override void Init(ParsingContext context, ParseTreeNode treeNode) { base.Init(context, treeNode); SetUoTypeToken(Types.Int); Field = (UoFieldExpressionNode)treeNode.FirstChild.AstNode; Operator = ((Tokenizer)treeNode.LastChild.LastChild.Term).Tokenize(); AsString = Operator.Value; }
bool warned = false; // This prevents multiple error messages public bool CheckAssignTo(UoToken type, ParsingContext context) { if (this.UoTypeToken == type || this.UoTypeToken == null /*any*/) { return(true); } if (type == Types.List) { return(true); } if (type == Types.String && ( UoTypeToken == Types.Int || UoTypeToken == Types.Obj )) { return(true); } if (type == Types.Int && UoTypeToken == Types.String) { if (!warned) { context.AddParserMessage(ParserErrorLevel.Info, Span, "Type mismatch, but valid: int=string"); } warned = true; return(true); } if (type == UOSLBase.KeyToken <UoToken.UoTypeName_loc> .Token) { if (Expression.IsValidLocationList(context)) { Expression.SetUoTypeToken(UOSLBase.KeyToken <UoToken.UoTypeName_loc> .Token); return(true); } else { if (!warned) { context.AddParserMessage(ParserErrorLevel.Error, Span, "Not a valid Location assignment."); } warned = true; return(false); } } if (!warned) { context.AddParserMessage(ParserErrorLevel.Error, Span, "Assignment Type mismatch."); } warned = true; return(false); }
public override void Init(ParsingContext context, ParseTreeNode treeNode) { base.Init(context, treeNode); int index = treeNode.ChildNodes.Count > 1 ? 1 : 0; m_UoToken = ((Tokenizer)treeNode.ChildNodes[index].Term).Tokenize(treeNode.ChildNodes[index].Token.Value); if (m_UoToken is UoToken.UoConstantString && ((UoToken.UoConstantString)m_UoToken).Value.Length > 127) { context.AddParserMessage(ParserErrorLevel.Error, treeNode.ChildNodes[index].Span, "The maximum length is 127 characters."); } }
public override void Init(ParsingContext context, ParseTreeNode treeNode) { base.Init(context, treeNode); ExpectedTerms = new List <Terminal>(treeNode.State.ExpectedTerminals); TreeFuncs = UOSLBase.GetFuncs(context); TreeNode = treeNode; if (treeNode.Token != null && treeNode.Token.KeyTerm is Tokenizer) { m_UoTypeToken = ((Tokenizer)treeNode.Token.KeyTerm).TokenType; } else if (treeNode.ChildNodes.Count == 1 && treeNode.FirstChild.AstNode is ScopedNode) { SetUoToken(((ScopedNode)treeNode.FirstChild.AstNode).UoToken); SetUoTypeToken(((ScopedNode)treeNode.FirstChild.AstNode).UoTypeToken); } }
public override void Init(ParsingContext context, ParseTreeNode treeNode) { base.Init(context, treeNode); if (treeNode.LastChild.AstNode is ExpressionNode) // If not, this is probably a unary assignment { Expression = (ExpressionNode)treeNode.LastChild.AstNode; if (Expression.ChildNodes.Count == 1 && Expression.AsString == "ExpressionList") // single expression ExpressionList { Expression = (ExpressionNode)Expression.ChildNodes[0]; } AsString = "="; Operator = ((Tokenizer)(treeNode.FirstChild.Term is Tokenizer ? treeNode.FirstChild.Term : treeNode.FirstChild.FirstChild.Term)).Tokenize(); if (!(Operator is UoToken.UoOperator_Assignment)) { context.AddParserMessage(ParserErrorLevel.Warning, this.Span, "While this symbol ({0}) will compile as an assignment, it is poor form.", Operator.Value); } ChildNodes.Add(Expression); Expression.Parent = this; SetUoTypeToken(Expression.UoTypeToken); } }
public ConstantListElement(UoToken uotoken, UoToken uotypetoken) { UoToken = uotoken; UoTypeToken = uotypetoken; }
public void SetUoToken(UoToken token) { m_UoToken = token; }
public override void CheckScope(ParsingContext context) { leftType = ((ScopedNode)ChildNodes[0]).UoTypeToken; rightType = ((ScopedNode)ChildNodes[1]).UoTypeToken; // This should be written to use then UoTokens, may need a new function for determining valid types for operations switch (Operator.Value) { case "==": case "!=": if ((leftType != null && leftType != Types.Int && leftType != Types.String && leftType != Types.Loc && leftType != Types.Obj) || (rightType != null && rightType != Types.Int && rightType != Types.String && rightType != Types.Loc && rightType != Types.Obj)) { context.AddParserMessage(ParserErrorLevel.Error, m_Operation.Span, "Binary expression: Equivalency can only be performed between int, string, location or object."); } SetUoTypeToken(Types.Int); break; case "+": if (leftType == null) { leftType = rightType; } if ((leftType == Types.String || rightType == Types.Char) && (rightType == Types.String || rightType == Types.Char || rightType == Types.Int || rightType == Types.Loc) || rightType == null) { SetUoTypeToken(Types.String); // Check length on constant string concatenation if (Left.UoToken is UoToken.UoConstantString && Right.UoToken is UoToken.UoConstantString) { if (Left.UoToken.Value.Length + Right.UoToken.Value.Length > 2047) { context.AddParserMessage(ParserErrorLevel.Error, m_Operation.Span, "The maximum result length of this expression is 2047 characters."); } } break; } if (leftType != null || rightType != null) { goto case "-"; } break; // if both null we can't set; case "-": case "*": case "/": case "%": case "<": case ">": case "<=": case ">=": case "^": case "&&": case "||": if (leftType != null && leftType != Types.Int) { context.AddParserMessage(ParserErrorLevel.Error, Left.Span, "Binary expression ({0}): Integer required.", Operator.Value); } if (rightType != null && rightType != Types.Int) { context.AddParserMessage(ParserErrorLevel.Error, Right.Span, "Binary expression ({0}): Integer required.", Operator.Value); } SetUoTypeToken(Types.Int); break; default: // require matched types context.AddParserMessage(ParserErrorLevel.Error, m_Operation.Span, "Binary expression: Unknown operator."); break; } }
public override void CheckScope(ParsingContext context) { ExpressionType = ((ScopedNode)ChildNodes[0]).UoTypeToken; SetUoTypeToken(ExpressionType); }