Esempio n. 1
0
 public override object VisitExp([NotNull] SLangGrammarParser.ExpContext context)
 {
     Visit(context.simpleExpr());
     if (context.exp() != null)
     {
         var op = context.BoolEq() ?? context.BoolG() ?? context.BoolGeq() ?? context.BoolL() ?? context.BoolLeq() ?? context.BoolNeq();
         cppText.Write($" {op.GetText()} ");
         Visit(context.exp());
     }
     return(null);
 }
Esempio n. 2
0
 private void TranslateDeclare(VariableNameTableItem item, SLangGrammarParser.ExpContext expContext)
 {
     if (!inProgramBlock && currentRoutine == null)
     {
         TranslateDeclareHead(item, headerText);
     }
     TranslateDeclareHead(item, cppText);
     if (expContext != null)
     {
         cppText.Write(" = ");
         Visit(expContext);
     }
 }
Esempio n. 3
0
        public override object VisitExp([NotNull] SLangGrammarParser.ExpContext context)
        {
            // что можно сравнивать в языке?
            // int и float и char и bool только между собой -- все простые типы кроме строк
            // указатели любого типа только между собой

            if (context.exp() != null)
            {
                var leftResultType  = (Visit(context.simpleExpr()) as ExpressionResult)?.Type;
                var rightResultType = (Visit(context.exp()) as ExpressionResult)?.Type;
                var allowedTypes    = new[] { SlangSimpleType.Int, SlangSimpleType.Real, SlangSimpleType.Boolean, SlangSimpleType.Character };
                var relOp           = context.BoolEq() ?? context.BoolNeq() ?? context.BoolG() ?? context.BoolGeq() ?? context.BoolL() ?? context.BoolLeq();

                if ((leftResultType is SlangSimpleType lt && rightResultType is SlangSimpleType rt &&
                     lt.Equals(rt) && allowedTypes.Contains(lt)) ||
                    ((leftResultType is SlangPointerType || leftResultType is SlangNullType) && (rightResultType is SlangPointerType || rightResultType is SlangNullType)))
                {
                    return(new ExpressionResult(SlangSimpleType.Boolean, ExpressionValueType.Value));
                }

                ThrowInvalidTypesForBinaryOperationException(relOp.Symbol, file, leftResultType, rightResultType);
            }
            return(Visit(context.simpleExpr()) as ExpressionResult);
        }
Esempio n. 4
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="SLangGrammarParser.exp"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitExp([NotNull] SLangGrammarParser.ExpContext context)
 {
 }
 /// <summary>
 /// Visit a parse tree produced by <see cref="SLangGrammarParser.exp"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitExp([NotNull] SLangGrammarParser.ExpContext context)
 {
     return(VisitChildren(context));
 }