public statement MyStmt(expression ex, statement st) { // Проверить, что в ex - целый тип // Сделать специальный узел для проверки new semantic_check("Тип проверки",params syntax_node[] ob) // Включать этот узел первым для "сахарных" узлов синтаксического дерева var sc = new semantic_check("ExprIsInteger", ex); var id = new ident("#my"); var idlist = new ident_list(id); var typ = new named_type_reference("integer"); var one = new int32_const(1); var vdef = new var_def_statement(idlist, typ, one, definition_attribute.None, false, null); var vstat = new var_statement(vdef, null); var ass = new assign(new ident("#my"), one, Operators.AssignmentAddition); var stlistwhile = new statement_list(st); stlistwhile.Add(ass); var bin = new bin_expr(id, ex, Operators.LessEqual); var wh = new while_node(bin, stlistwhile, WhileCycleType.While); var stlist = new statement_list(sc); stlist.Add(vstat); stlist.Add(wh); return(stlist); }
public const_node create_int_const(string text, SourceContext sc, System.Globalization.NumberStyles NumberStyles) { //таблица целых констант на уровне синтаксиса // не может быть - 0 + // 32--------16----8----|----8----16--------32----------------64(bits) // [ int64 )[ int32 ]( int64 ]( uint64 ] if (NumberStyles == System.Globalization.NumberStyles.HexNumber) { text = text.Substring(1); } const_node cn = new int32_const(); if (text.Length < 8) { (cn as int32_const).val = Int32.Parse(text, NumberStyles); } else { try { UInt64 uint64 = UInt64.Parse(text, NumberStyles); if (uint64 <= Int32.MaxValue) { (cn as int32_const).val = (Int32)uint64; } else if (uint64 <= Int64.MaxValue) { cn = new int64_const((Int64)uint64); } else { cn = new uint64_const(uint64); } } catch (Exception) { if (NumberStyles == System.Globalization.NumberStyles.HexNumber) { errors.Add(new BadHex(CurrentFileName, sc, null)); } else { errors.Add(new BadInt(CurrentFileName, sc, null)); } } } cn.source_context = sc; return(cn); }
private void CheckIfCanBeMatched(expression tuple, int32_const length) { var expressionType = convert_strong(tuple).type; var expressionTypeName = expressionType.BaseFullName; var tupleName = "System.Tuple"; if (expressionTypeName.StartsWith(tupleName) && int.Parse(expressionTypeName.Substring(tupleName.Length + 1, 1)) == length.val) { return; } AddError(get_location(tuple), "EXPRESSION_OF_TYPE_{0}_CANNOT_BE_MATCHED_AGAINST_PATTERN_WITH_TYPE_{1}", expressionType.name, "Tuple`" + length.val); }
public virtual const_node create_int_const(string text, LexLocation loc, System.Globalization.NumberStyles NumberStyles) { if (NumberStyles == System.Globalization.NumberStyles.HexNumber) { text = text.Substring(1); } const_node cn = new int32_const(); if (text.Length < 8) { (cn as int32_const).val = Int32.Parse(text, System.Globalization.NumberStyles.Integer); } else { try { UInt64 uint64 = UInt64.Parse(text, System.Globalization.NumberStyles.Integer); if (uint64 <= Int32.MaxValue) { (cn as int32_const).val = (Int32)uint64; } else if (uint64 <= Int64.MaxValue) { cn = new int64_const((Int64)uint64); } else { cn = new uint64_const(uint64); } } catch (Exception) { if (NumberStyles == System.Globalization.NumberStyles.HexNumber) { GPPGParser.errors.Add(new BadHex(GPPGParser.current_file_name, GetTokenSourceContext(loc), new syntax_tree_node())); } else { GPPGParser.errors.Add(new BadInt(GPPGParser.current_file_name, GetTokenSourceContext(loc), new syntax_tree_node())); } } } cn.source_context = GetTokenSourceContext(loc); return(cn); }
public int32_const Convert(expression expr) { if (expr == null) { return(null); } try { expr.visit(this); } catch { return(null); } if (intStack.Count == 1) { int32_const i = new int32_const(intStack.Pop()); i.source_context = expr.source_context; return(i); } return(null); }
public virtual void post_do_visit(int32_const _int32_const) { }
public override void visit(int32_const _int32_const) { DefaultVisit(_int32_const); pre_do_visit(_int32_const); post_do_visit(_int32_const); }
public override void Exit(syntax_tree_node st) { bracket_expr bre = st as bracket_expr; if (bre != null) { if (bre.expr is int32_const) { Replace(st, bre.expr); } } bin_expr vs = st as bin_expr; if (vs != null) { if (vs.left is int32_const && vs.right is int32_const) { var a = vs.left as int32_const; var b = vs.right as int32_const; var op = vs.operation_type; syntax_tree_node res; switch (op) { case Operators.Plus: res = new int32_const(a.val + b.val); break; case Operators.Minus: res = new int32_const(a.val - b.val); break; case Operators.Multiplication: res = new int32_const(a.val * b.val); break; case Operators.Division: res = new double_const((double)a.val / b.val); break; case Operators.Greater: res = new bool_const(a.val > b.val); break; case Operators.Less: res = new bool_const(a.val < b.val); break; case Operators.GreaterEqual: res = new bool_const(a.val >= b.val); break; case Operators.LessEqual: res = new bool_const(a.val <= b.val); break; default: res = vs; break; } Replace(vs, res); } if (vs.left is int32_const && vs.right is double_const || vs.right is int32_const && vs.left is double_const || vs.left is double_const && vs.right is double_const) { double x, y; if (vs.left is int32_const) { x = (vs.left as int32_const).val; } else { x = (vs.left as double_const).val; } if (vs.right is int32_const) { y = (vs.right as int32_const).val; } else { y = (vs.right as double_const).val; } var op = vs.operation_type; syntax_tree_node res; switch (op) { case Operators.Plus: res = new double_const(x + y); break; case Operators.Minus: res = new double_const(x - y); break; case Operators.Multiplication: res = new double_const(x * y); break; case Operators.Division: res = new double_const(x / y); break; case Operators.Greater: res = new bool_const(x > y); break; case Operators.Less: res = new bool_const(x < y); break; case Operators.GreaterEqual: res = new bool_const(x >= y); break; case Operators.LessEqual: res = new bool_const(x <= y); break; default: res = vs; break; } Replace(vs, res); } } base.Exit(st); // это обязательно! }
public override void visit(int32_const _int32_const) { intStack.Push(_int32_const.val); }
public override void visit(int32_const _int_const) { }
public override void visit(int32_const i) { fs.WriteLine(i.val); }
public virtual void visit(int32_const _int32_const) { }
public virtual void visit(int32_const _int32_const) { DefaultVisit(_int32_const); }
private semantic_check_sugared_statement_node GetTypeCompatibilityCheck(expression tuple, int32_const length) => new semantic_check_sugared_statement_node(SemanticCheckType.MatchedTuple, new List <syntax_tree_node>() { tuple, length });
public override void visit(int32_const _int_const) { text = "Value: " + _int_const.val.ToString(); }
public override void visit(int32_const _int32_const) { AddPossibleComments(_int32_const, true, true); }
public override void visit(int32_const _int32_const) { executer.visit(_int32_const); if (_int32_const.attributes != null) this.visit((dynamic)_int32_const.attributes); }