Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/17 11:23:05 (8 years ago)
Author:
pkimmesw
Message:

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Parser/PushParser.cs

    r14777 r14952  
    22  using System.Collections.Generic;
    33  using System.Globalization;
    4 
     4  using System.Linq;
    55  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    66
     
    5757        // expression
    5858        if (ExpressionTable.TryGetStatelessExpression(symbol, out expression)
    59             || ExpressionTable.TryGetStatefulExpression(symbol, out expression)) {
     59         || ExpressionTable.TryGetStatefulExpression(symbol, out expression)) {
    6060          expressions.Insert(0, expression);
    6161          continue;
     
    7979
    8080    private static bool TryParseLiteral(string word, out Expression expression) {
     81      if (word.StartsWith("'") && word.EndsWith("'") && word.Length == 3) {
     82        expression = new CharPushExpression(word[1]);
     83        return true;
     84      }
     85
     86      if (word.StartsWith("\"") && word.EndsWith("\"")) {
     87        expression = new StringPushExpression(word);
     88        return true;
     89      }
     90
     91      // "[]" has no values and can therefer not parsed correctly as vector of a specific type
     92      if (word.StartsWith("[") && word.EndsWith("]") && word.Length > 3) {
     93        var vectorEntries = word
     94          .Substring(1, word.Length - 2)
     95          .Split(',')
     96          .Select(x => {
     97            Expression e;
     98            var success = TryParseLiteral(x.Trim(), out e);
     99
     100            return new { success, e, type = e.GetType() };
     101          })
     102          .ToArray();
     103
     104        if (vectorEntries.Length == 0) {
     105          expression = null;
     106          return false;
     107        }
     108
     109        var vectorEntryType = vectorEntries.First().type;
     110        if (vectorEntries.Any(x => !x.success || x.type != vectorEntryType)) {
     111          expression = null;
     112          return false;
     113        }
     114
     115        var result = vectorEntries
     116          .Select(x => x.e)
     117          .ToArray();
     118
     119        // TODO
     120        //switch(vectorEntryType.GetHashCode())
     121        //{
     122        //  case typeof(IntegerPushExpression).GetHashCode(): return new IntegerVectorPushExpression(result)
     123        //}
     124
     125        //expression = new StringPushExpression(word);
     126        //return true;
     127      }
     128
    81129      long longValue;
    82130      if (long.TryParse(word, out longValue)) {
Note: See TracChangeset for help on using the changeset viewer.