private ItemType AnalyzeExpressionType() { _expressionAnalyzer = new ExpressionAnalyzer(_symbolTable); AnalyzeExpression(); var type = ItemType.None; try { var tokens = _expressionAnalyzer.Analyze(out type); GenerateCodeForExpression(tokens); } catch (ExpressionException ex) { throw new CompilationException(string.Format(GenericErrorMessage, _lexical.Position.Line, _lexical.Position.Column, ex.Message)); } catch (Exception ex) { //Todo: log error here. throw new CompilationException(ex.Message); } return(type); }
public void BOOLEAN_EXPRESSION_TEST() { var expressionAnalyzer = new ExpressionAnalyzer(_symbolTable); var output = string.Empty; var expectedOutput = "fnaogou"; var token = new Token { Lexeme = "nao", Symbol = Symbols.SNao }; var type = ItemType.None; expressionAnalyzer.Add(token); token = new Token { Lexeme = "f", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "ou", Symbol = Symbols.SOu }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "g", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); expressionAnalyzer.Analyze(out type); output = expressionAnalyzer.ToString(); Assert.AreEqual(type, ItemType.Boolean); Assert.AreEqual(output, expectedOutput); }
public void INTEGER_BOOLEAN_EXPRESSION_TEST() { var expressionAnalyzer = new ExpressionAnalyzer(_symbolTable); var output = string.Empty; var expectedOutput = "ab+cd-<"; var token = new Token { Lexeme = "(", Symbol = Symbols.SAbreParenteses }; var type = ItemType.None; expressionAnalyzer.Add(token); token = new Token { Lexeme = "a", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "+", Symbol = Symbols.SMais }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "b", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = ")", Symbol = Symbols.SFechaParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "<", Symbol = Symbols.SMenorIg }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "(", Symbol = Symbols.SAbreParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "c", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "-", Symbol = Symbols.SMenos }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "d", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = ")", Symbol = Symbols.SFechaParenteses }; expressionAnalyzer.Add(token); expressionAnalyzer.Analyze(out type); output = expressionAnalyzer.ToString(); Assert.AreEqual(type, ItemType.Boolean); Assert.AreEqual(output, expectedOutput); }
public void INTEGER_UNARY_EXPRESSION_TEST() { var expressionAnalyzer = new ExpressionAnalyzer(_symbolTable); var output = string.Empty; var expectedOutput = "a-cd-e*+"; var token = new Token { Lexeme = "-", Symbol = Symbols.SMaisUnario }; var type = ItemType.None; expressionAnalyzer.Add(token); token = new Token { Lexeme = "a", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "+", Symbol = Symbols.SMais }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "(", Symbol = Symbols.SAbreParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "c", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "-", Symbol = Symbols.SMenos }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "d", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = ")", Symbol = Symbols.SFechaParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "*", Symbol = Symbols.SMult }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "e", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); expressionAnalyzer.Analyze(out type); output = expressionAnalyzer.ToString(); Assert.AreEqual(type, ItemType.Integer); Assert.AreEqual(output, expectedOutput); }
public void INTEGER_EXPRESSION_TEST() { var expressionAnalyzer = new ExpressionAnalyzer(_symbolTable); var output = string.Empty; var expectedOutput = "ab+cd*+e+"; var token = new Token { Lexeme = "a", Symbol = Symbols.SIdentificador }; var type = ItemType.None; expressionAnalyzer.Add(token); token = new Token { Lexeme = "+", Symbol = Symbols.SMais }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "b", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "+", Symbol = Symbols.SMais }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "c", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "*", Symbol = Symbols.SMult }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "d", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "+", Symbol = Symbols.SMais }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "e", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); expressionAnalyzer.Analyze(out type); output = expressionAnalyzer.ToString(); Assert.AreEqual(type, ItemType.Integer); Assert.AreEqual(output, expectedOutput); }
public string Parse() { Guard.Argument(_expression).NotNull(); var analyzer = new ExpressionAnalyzer(); var context = analyzer.Analyze(_expression); StartQuery(context, _queryString); QueryParametrs(context, _queryString); _queryString.Append("{"); StartQueryBody(context, _queryString); EndQueryBody(context, _queryString); _queryString.Append("}"); return(_queryString.ToString()); }
public void Property <T>(string property_name, Expression <Func <T> > getter) { log.Trace(string.Format("Adding property {0} of type {1}", property_name, typeof(T))); var property = new DelegatePropertyDescriptor(property_name, this, typeof(T)); var compiled_getter = getter.Compile(); property.Getter = x => compiled_getter(); // Analyse getter for dependencies var tree = ExpressionAnalyzer.Analyze(getter); property.AddDependencies(tree, () => NotifyPropertyChanged(property_name)); AddProperty(property); }
public void Dependency <T>(string native_property, Expression <Func <T> > dependencies) { var property_info = GetType().GetProperty(native_property); var property = new DelegatePropertyDescriptor(native_property, this, typeof(T)); property.Getter = x => property_info.GetValue(this, null); if (property_info.CanWrite) { property.Setter = (x, v) => property_info.SetValue(this, v, null); } // Analyse getter for dependencies var tree = ExpressionAnalyzer.Analyze(dependencies); property.AddDependencies(tree, () => NotifyPropertyChanged(native_property)); AddProperty(property); }
public void INTEGER_CONSTS_ONLY_TEST() { var expressionAnalyzer = new ExpressionAnalyzer(_symbolTable); var output = string.Empty; var expectedOutput = "32-45*+"; var token = new Token { Lexeme = "3", Symbol = Symbols.SNumero }; var type = ItemType.None; expressionAnalyzer.Add(token); token = new Token { Lexeme = "-", Symbol = Symbols.SMenos }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "2", Symbol = Symbols.SNumero }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "+", Symbol = Symbols.SMais }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "4", Symbol = Symbols.SNumero }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "*", Symbol = Symbols.SMult }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "5", Symbol = Symbols.SNumero }; expressionAnalyzer.Add(token); expressionAnalyzer.Analyze(out type); output = expressionAnalyzer.ToString(); Assert.AreEqual(type, ItemType.Integer); Assert.AreEqual(output, expectedOutput); }
public IReactiveCollection <T> Collection <T>(string property_name, Expression <Func <IEnumerable <T> > > items) { log.Trace(string.Format("Adding collection property {0} of element type {1}", property_name, typeof(T))); // Create reactive collection var reactive_collection = new ReactiveCollection <T>(); // Create property var property = new DelegatePropertyDescriptor(property_name, this, typeof(ObservableCollection <ViewModelBase>)); property.Getter = x => reactive_collection.WrappedCollection; // Analyse items for dependencies var tree = ExpressionAnalyzer.Analyze(items); // Create and attach a collection node to the tree var property_node = tree.GetPropertyNode(property_name); var collection_node = new CollectionNode <T>(property_node, reactive_collection); property_node.Children.Add(collection_node); // Subscribe to events property.AddDependencies(tree, () => NotifyPropertyChanged(property_name)); AddProperty(property); return(reactive_collection); }
public DependencyMethod <T> OnChanged <TResult>(Expression <Func <T, TResult> > property_accessor) { // Build property access tree from expression PropertyAccessTree property_access_tree = ExpressionAnalyzer.Analyze(property_accessor); if (!property_access_tree.DoesEntireTreeSupportINotifyPropertyChangedAndChanging()) { throw new ArgumentException("All objects must implement INotifyPropertyChanged and INotifyPropertyChanging"); } if (property_change_subscribers == null) { property_change_subscribers = new List <PropertyAccessTreeSubscriber <DependencyMethod <T> > >(); } // Build subscription tree from property access tree log.Trace("Creating subscription tree"); var subscriber = property_access_tree.CreateSubscriptionTree <DependencyMethod <T> >(OnAnyPropertyInSubscriptionChanges); subscriber.DumpToLog(); property_change_subscribers.Add(subscriber); return(this); }
public void INTEGER_BOOLEAN_EXPRESSION_COMPLEX_TEST() { var expressionAnalyzer = new ExpressionAnalyzer(_symbolTable); var output = string.Empty; var expectedOutput = "a-badivab-**<nao"; var token = new Token { Lexeme = "nao", Symbol = Symbols.SNao }; var type = ItemType.None; expressionAnalyzer.Add(token); token = new Token { Lexeme = "(", Symbol = Symbols.SAbreParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "(", Symbol = Symbols.SAbreParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "-", Symbol = Symbols.SMenosUnario }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "a", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = ")", Symbol = Symbols.SFechaParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "<", Symbol = Symbols.SMenor }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "(", Symbol = Symbols.SAbreParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "(", Symbol = Symbols.SAbreParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "b", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "div", Symbol = Symbols.SDiv }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "a", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = ")", Symbol = Symbols.SFechaParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "*", Symbol = Symbols.SMult }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "(", Symbol = Symbols.SAbreParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "a", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "*", Symbol = Symbols.SMult }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "(", Symbol = Symbols.SAbreParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "-", Symbol = Symbols.SMenosUnario }; expressionAnalyzer.Add(token); token = new Token { Lexeme = "b", Symbol = Symbols.SIdentificador }; expressionAnalyzer.Add(token); token = new Token { Lexeme = ")", Symbol = Symbols.SFechaParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = ")", Symbol = Symbols.SFechaParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = ")", Symbol = Symbols.SFechaParenteses }; expressionAnalyzer.Add(token); token = new Token { Lexeme = ")", Symbol = Symbols.SFechaParenteses }; expressionAnalyzer.Add(token); expressionAnalyzer.Analyze(out type); output = expressionAnalyzer.ToString(); Assert.AreEqual(type, ItemType.Boolean); Assert.AreEqual(output, expectedOutput); }
private ItemType AnalyzeExpressionType() { _expressionAnalyzer = new ExpressionAnalyzer(_symbolTable); AnalyzeExpression(); var type = ItemType.None; try { var tokens = _expressionAnalyzer.Analyze(out type); GenerateCodeForExpression(tokens); } catch (ExpressionException ex) { throw new CompilationException(string.Format(GenericErrorMessage, _lexical.Position.Line, _lexical.Position.Column, ex.Message)); } catch (Exception ex) { //Todo: log error here. throw new CompilationException(ex.Message); } return type; }