public ExpressionCompilerNotFoundEvent(HlExpression expr) : base( $"No Compiler found for expression: ({expr.Type}) '{expr}'", ErrorEventKeys.s_HlCompilerNotFound, false ) { }
ExpressionTarget IHlExpressionCompiler.Parse( HlCompilation compilation, HlExpression expr, ExpressionTarget outputTarget) { return(InnerParseExpression(compilation, ( T )expr, outputTarget)); }
/// <summary> /// Returns true if the parser is in a state that allows the creation of an implemented operator /// </summary> /// <param name="parser">Parser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns>True if this Expression operator can create an expression</returns> public override bool CanCreate(HlExpressionParser parser, HlExpression currentNode) { return((parser.CurrentToken.Type == HlTokenType.OpAsterisk || parser.CurrentToken.Type == HlTokenType.OpFwdSlash || parser.CurrentToken.Type == HlTokenType.OpPercent) && parser.Reader.PeekNext().Type != HlTokenType.OpEquality); }
/// <summary> /// Returns true if the parser is in a state that allows the creation of an implemented operator /// </summary> /// <param name="parser">Parser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns>True if this Expression operator can create an expression</returns> public override bool CanCreate(HlExpressionParser parser, HlExpression currentNode) { return(parser.CurrentToken.Type == HlTokenType.OpLessThan && parser.Reader.PeekNext().Type == HlTokenType.OpLessThan || parser.CurrentToken.Type == HlTokenType.OpGreaterThan && parser.Reader.PeekNext().Type == HlTokenType.OpGreaterThan); }
/// <summary> /// Public Constructor /// </summary> /// <param name="context">XL Context</param> /// <param name="left">Left Side Expression</param> /// <param name="memberName"></param> public HlMemberAccessOp(HlExpression left, HlExpression memberName) : base( left.SourceIndex ) { Left = left; MemberName = memberName; }
/// <summary> /// Returns true if the parser is in a state that allows the creation of an implemented operator /// </summary> /// <param name="parser">Parser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns>True if this Expression operator can create an expression</returns> public override bool CanCreate(HlExpressionParser parser, HlExpression currentNode) { return(parser.CurrentToken.Type == HlTokenType.OpPlus && parser.Reader.PeekNext().Type == HlTokenType.OpPlus || parser.CurrentToken.Type == HlTokenType.OpMinus && parser.Reader.PeekNext().Type == HlTokenType.OpMinus); }
/// <summary> /// Public Constructor /// </summary> /// <param name="context">XL Context</param> /// <param name="left">Left Side</param> /// <param name="operationType">Operation FunctionType</param> /// <param name="right">Right Side</param> public HlBinaryOp( HlExpression left, HlTokenType operationType, HlExpression right) : base(left.SourceIndex) { Left = left; OperationType = operationType; Right = right; }
/// <summary> /// Returns true if the parser is in a state that allows the creation of an implemented operator /// </summary> /// <param name="parser">Parser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns>True if this Expression operator can create an expression</returns> public override bool CanCreate(HlExpressionParser parser, HlExpression currentNode) { return(parser.CurrentToken.Type == HlTokenType.OpMinus && parser.Reader.PeekNext().Type == HlTokenType.OpMinus || parser.CurrentToken.Type == HlTokenType.OpBang && parser.Reader.PeekNext().Type != HlTokenType.OpEquality || parser.CurrentToken.Type == HlTokenType.OpTilde && parser.Reader.PeekNext().Type != HlTokenType.OpEquality); }
/// <summary> /// Creates an implemented expression /// </summary> /// <param name="parser">XLExpressionParser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns></returns> public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode) { parser.Eat(HlTokenType.OpCap); return(new HlBinaryOp( currentNode, HlTokenType.OpCap, parser.ParseExpr(PrecedenceLevel) )); }
/// <summary> /// Creates an implemented expression /// </summary> /// <param name="parser">XLExpressionParser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns></returns> public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode) { HlTokenType type = parser.CurrentToken.Type; parser.Eat(type); HlExpression token = new HlUnaryOp(parser.ParseExpr(PrecedenceLevel), type); return(token); }
/// <summary> /// Public Constructor /// </summary> /// <param name="context">XL Context</param> /// <param name="vDecl">Variable Declaration</param> /// <param name="condition">For Continue Condition</param> /// <param name="vInc">Variable Change Expression</param> /// <param name="operationType">Operation FunctionType</param> /// <param name="exprBody">The Expression Body</param> public HlForOp( HlExpression vDecl, HlExpression condition, HlExpression vInc, HlExpression[] exprBody, int sourceIdx) : base(sourceIdx) { Condition = condition; VDecl = vDecl; VInc = vInc; ExprBody = exprBody; }
/// <summary> /// Creates an implemented expression /// </summary> /// <param name="parser">XLExpressionParser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns></returns> public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode) { HlTokenType tt = parser.CurrentToken.Type == HlTokenType.OpPlus ? HlTokenType.OpUnaryPostfixIncrement : HlTokenType.OpUnaryPostfixDecrement; parser.Eat(parser.CurrentToken.Type); parser.Eat(parser.CurrentToken.Type); HlExpression token = new HlUnaryOp(currentNode, tt); return(token); }
/// <summary> /// Creates an implemented expression /// </summary> /// <param name="parser">XLExpressionParser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns></returns> public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode) { parser.Eat(HlTokenType.OpBang); parser.Eat(HlTokenType.OpEquality); return(new HlUnaryOp( new HlBinaryOp( currentNode, HlTokenType.OpComparison, parser.ParseExpr(PrecedenceLevel) ), HlTokenType.OpBang )); }
/// <summary> /// Returns true if the parser is in a state that allows the creation of an implemented operator /// </summary> /// <param name="parser">Parser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns>True if this Expression operator can create an expression</returns> public override bool CanCreate(HlExpressionParser parser, HlExpression currentNode) { return((parser.CurrentToken.Type == HlTokenType.OpPlus || parser.CurrentToken.Type == HlTokenType.OpMinus || parser.CurrentToken.Type == HlTokenType.OpAsterisk || parser.CurrentToken.Type == HlTokenType.OpFwdSlash || parser.CurrentToken.Type == HlTokenType.OpPercent || parser.CurrentToken.Type == HlTokenType.OpAnd || parser.CurrentToken.Type == HlTokenType.OpPipe || parser.CurrentToken.Type == HlTokenType.OpCap) && parser.Reader.PeekNext().Type == HlTokenType.OpEquality || parser.CurrentToken.Type == HlTokenType.OpLessThan && parser.Reader.PeekNext().Type == HlTokenType.OpLessThan && parser.Reader.PeekNext(2).Type == HlTokenType.OpLessThan || parser.CurrentToken.Type == HlTokenType.OpGreaterThan && parser.Reader.PeekNext().Type == HlTokenType.OpGreaterThan && parser.Reader.PeekNext(2).Type == HlTokenType.OpLessThan); }
/// <summary> /// Creates an implemented expression /// </summary> /// <param name="parser">XLExpressionParser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns></returns> public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode) { HlTokenType type = parser.CurrentToken.Type; parser.Eat(parser.CurrentToken.Type); HlExpression node = null; if (type == HlTokenType.OpLessThan) { if (parser.CurrentToken.Type == HlTokenType.OpEquality) { parser.Eat(HlTokenType.OpEquality); node = new HlBinaryOp( currentNode, HlTokenType.OpLessOrEqual, parser.ParseExpr(PrecedenceLevel) ); } else { node = new HlBinaryOp(currentNode, type, parser.ParseExpr(PrecedenceLevel)); } } else if (type == HlTokenType.OpGreaterThan) { if (parser.CurrentToken.Type == HlTokenType.OpEquality) { parser.Eat(HlTokenType.OpEquality); node = new HlBinaryOp( currentNode, HlTokenType.OpGreaterOrEqual, parser.ParseExpr(PrecedenceLevel) ); } else { node = new HlBinaryOp(currentNode, type, parser.ParseExpr(PrecedenceLevel)); } } return(node); }
/// <summary> /// Parses a For Expression from the Parser /// </summary> /// <param name="parser">The Parser</param> /// <returns>Parsed Expression</returns> public static HlExpression ReadFor(HlExpressionParser parser) { IHlToken ft = parser.CurrentToken; parser.Eat(HlTokenType.OpFor); parser.Eat(HlTokenType.OpBracketOpen); HlExpression vDecl = parser.ParseExpr(); if (parser.CurrentToken.Type == HlTokenType.OpSemicolon) { parser.Eat(HlTokenType.OpSemicolon); } HlExpression condition = parser.ParseExpr(); if (parser.CurrentToken.Type == HlTokenType.OpSemicolon) { parser.Eat(HlTokenType.OpSemicolon); } HlExpression vInc = parser.ParseExpr(); parser.Eat(HlTokenType.OpBracketClose); HlExpression token = null; List <HlExpression> block; if (parser.CurrentToken.Type != HlTokenType.OpBlockToken) { block = new List <HlExpression> { parser.ParseExpr() }; } else { block = HlExpressionParser.Create(new HlExpressionReader(parser.CurrentToken.GetChildren())). Parse(). ToList(); } token = new HlForOp(vDecl, condition, vInc, block.ToArray(), ft.SourceIndex); return(token); }
public override string ToString() { StringBuilder ret = new StringBuilder($"{Left}("); for (int i = 0; i < ParameterList.Length; i++) { HlExpression hlExpression = ParameterList[i]; ret.Append(hlExpression); if (i != ParameterList.Length - 1) { ret.Append(','); } } ret.Append(')'); return(ret.ToString()); }
/// <summary> /// Creates an implemented expression /// </summary> /// <param name="parser">XLExpressionParser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns></returns> public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode) { HlTokenType type = parser.CurrentToken.Type; parser.Eat(type); parser.Eat(type); if (type == HlTokenType.OpLessThan) { type = HlTokenType.OpShiftLeft; } else if (type == HlTokenType.OpGreaterThan) { type = HlTokenType.OpShiftRight; } return(new HlBinaryOp( currentNode, type, parser.ParseExpr(PrecedenceLevel) )); }
/// <summary> /// Creates an implemented expression /// </summary> /// <param name="parser">XLExpressionParser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns></returns> public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode) { parser.Eat(HlTokenType.OpIndexerBracketOpen); List <HlExpression> parameterList = new List <HlExpression>(); bool comma = false; while (parser.CurrentToken.Type != HlTokenType.OpIndexerBracketClose) { if (comma) { parser.Eat(HlTokenType.OpComma); } else { parameterList.Add(parser.ParseExpr()); comma = true; } } parser.Eat(HlTokenType.OpIndexerBracketClose); return(new HlArrayAccessorOp(currentNode, parameterList)); }
/// <summary> /// Parses the Expression starting at the specified Operator Precedence /// </summary> /// <param name="stopAt">Operator Precedence</param> /// <returns>Expression at the Specified Index</returns> public HlExpression ParseExpr(int stopAt) { if (stopAt == -1) { stopAt = m_OpCollection.Highest; } HlExpression node = ValueCreator.CreateValue(this, ( uint )stopAt); if (CurrentToken.Type == HlTokenType.OpSemicolon) { Eat(HlTokenType.OpSemicolon); return(node); } int end = Math.Min(stopAt, m_OpCollection.Highest); for (int i = 0; i <= end; i++) { if (!m_OpCollection.HasLevel(i)) { continue; } List <HlExpressionOperator> ops = m_OpCollection.GetLevel(i); HlExpressionOperator current = ops.FirstOrDefault(x => x.CanCreate(this, node)); if (current != null) { node = current.Create(this, node); } } return(node); }
/// <summary> /// Returns true if the parser is in a state that allows the creation of an implemented operator /// </summary> /// <param name="parser">Parser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns>True if this Expression operator can create an expression</returns> public override bool CanCreate(HlExpressionParser parser, HlExpression currentNode) { return(parser.CurrentToken.Type == HlTokenType.OpIndexerBracketOpen); }
/// <summary> /// Public Constructor /// </summary> /// <param name="context">XL Context</param> /// <param name="left">Left Side</param> /// <param name="operationType">Operation FunctionType</param> public HlUnaryOp(HlExpression left, HlTokenType operationType) : base(left.SourceIndex) { Left = left; OperationType = operationType; }
/// <summary> /// Public Constructor /// </summary> /// <param name="context">XL Context</param> /// <param name="right">Right side Expression</param> public HlReturnOp(HlExpression right, int sourceIdx) : base(sourceIdx) { Right = right; }
/// <summary> /// Public Constructor /// </summary> /// <param name="context">XL Context</param> /// <param name="list">Left Side Array</param> /// <param name="parameterList">Array Accessor Parameters</param> public HlArrayAccessorOp(HlExpression list, List <HlExpression> parameterList) : base(list.SourceIndex) { Left = list; ParameterList = parameterList.ToArray(); }
public override ExpressionTarget ParseExpression(HlCompilation compilation, HlVarDefOperand expr) { if (expr.VariableDefinition.Modifiers.All(x => x.Type != HlTokenType.OpConstMod)) { string asmVarName = expr.VariableDefinition.Name.ToString(); if (compilation.ContainsLocalVariable(asmVarName)) { EventManager <ErrorEvent> .SendEvent(new DuplicateVarDefinitionEvent( asmVarName )); } HlTypeDefinition vdef = m_TypeSystem.GetType( compilation.Root, expr.VariableDefinition.TypeName.ToString() ); uint arrSize = expr.VariableDefinition.Size?.ToString().ParseUInt() ?? 1; if (arrSize != 1) { vdef = new ArrayTypeDefintion(compilation.Root, vdef, arrSize); } HlExpression init = expr.Initializer.FirstOrDefault(); if (vdef.GetSize() > 1) { if (init is HlVarOperand vo) { } } compilation.CreateVariable( asmVarName, arrSize, vdef, expr.VariableDefinition.Modifiers.Any( x => x.Type == HlTokenType.OpPublicMod ) ? VariableDataEmitFlags.Visible : VariableDataEmitFlags.None ); if (init != null) { if (init is HlValueOperand vOp && vOp.Value.Type == HlTokenType.OpStringLiteral) { ExpressionTarget svar = new ExpressionTarget( compilation.GetFinalName(asmVarName), true, vdef ); string content = vOp.Value.ToString(); VariableDataEmitFlags emFlags = vdef is CStringTypeDefinition ? VariableDataEmitFlags.CStyle : VariableDataEmitFlags.None; if (expr.VariableDefinition.Modifiers.Any(x => x.Type == HlTokenType.OpPackedMod)) { emFlags |= VariableDataEmitFlags.Packed; } compilation.CreateVariable(asmVarName, content, vdef, emFlags); return(new ExpressionTarget( svar.ResultAddress, true, vdef )); } } ExpressionTarget dvar = new ExpressionTarget( compilation.GetFinalName(asmVarName), true, vdef ); if (init != null) { ExpressionTarget initVal = compilation.Parse(init, dvar); ExpressionTarget initRet = initVal.CopyIfNotNull(compilation, dvar); compilation.ReleaseTempVar(initVal.ResultAddress); return(initRet); } return(dvar); } else { string asmVarName = expr.VariableDefinition.Name.ToString(); if (compilation.ConstValTypes.Contains(asmVarName)) { EventManager <ErrorEvent> .SendEvent(new DuplicateConstVarDefinitionEvent( asmVarName )); } compilation.ConstValTypes.Set( asmVarName, new ConstantValueItem() { Value = expr.VariableDefinition.InitializerExpression. FirstOrDefault()?. ToString(), IsPublic = expr.VariableDefinition.Modifiers.Any( x => x.Type == HlTokenType.OpPublicMod ), IsInternal = expr.VariableDefinition.Modifiers.Any( x => x.Type == HlTokenType.OpInternalMod ) } ); return(new ExpressionTarget( asmVarName, true, compilation.TypeSystem.GetType( compilation.Root, expr.VariableDefinition.TypeName.ToString() ) )); } EventManager <ErrorEvent> .SendEvent(new DynamicVariablesNotSupportedEvent()); return(new ExpressionTarget()); }
/// <summary> /// Public Constructor /// </summary> /// <param name="context">XL Context</param> /// <param name="condition">Continue Condition</param> /// <param name="operationType">Operation FunctionType</param> /// <param name="exprBody">Expression Body</param> public HlWhileOp(HlExpression condition, HlExpression[] block, int sourceIdx) : base(sourceIdx) { Condition = condition; Block = block; }
/// <summary> /// Creates an implemented expression /// </summary> /// <param name="parser">XLExpressionParser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns></returns> public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode) { parser.Eat(HlTokenType.OpDot); return(new HlMemberAccessOp(currentNode, parser.ParseExpr(PrecedenceLevel))); }
/// <summary> /// Returns true if the parser is in a state that allows the creation of an implemented operator /// </summary> /// <param name="parser">Parser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns>True if this Expression operator can create an expression</returns> public override bool CanCreate(HlExpressionParser parser, HlExpression currentNode) { return(parser.CurrentToken.Type == HlTokenType.OpDot); }
/// <summary> /// Creates an implemented expression /// </summary> /// <param name="parser">XLExpressionParser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns></returns> public abstract HlExpression Create(HlExpressionParser parser, HlExpression currentNode);
/// <summary> /// Creates an implemented expression /// </summary> /// <param name="parser">XLExpressionParser</param> /// <param name="currentNode">Current Expression Node</param> /// <returns></returns> public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode) { IHlToken token = parser.CurrentToken; HlTokenType tt; switch (parser.CurrentToken.Type) { case HlTokenType.OpPlus: tt = HlTokenType.OpSumAssign; break; case HlTokenType.OpMinus: tt = HlTokenType.OpDifAssign; break; case HlTokenType.OpAsterisk: tt = HlTokenType.OpProdAssign; break; case HlTokenType.OpFwdSlash: tt = HlTokenType.OpQuotAssign; break; case HlTokenType.OpPercent: tt = HlTokenType.OpRemAssign; break; case HlTokenType.OpPipe: tt = HlTokenType.OpOrAssign; break; case HlTokenType.OpAnd: tt = HlTokenType.OpAndAssign; break; case HlTokenType.OpCap: tt = HlTokenType.OpXOrAssign; break; case HlTokenType.OpGreaterThan: tt = HlTokenType.OpShiftRightAssign; parser.Eat(token.Type); break; case HlTokenType.OpLessThan: tt = HlTokenType.OpShiftLeftAssign; parser.Eat(token.Type); break; default: EventManager <ErrorEvent> .SendEvent( new HlTokenReadEvent( HlTokenType.Any, parser.CurrentToken.Type ) ); tt = HlTokenType.Unknown; break; } parser.Eat(token.Type); parser.Eat(HlTokenType.OpEquality); return(new HlBinaryOp(currentNode, tt, parser.ParseExpr(PrecedenceLevel))); }