Ejemplo n.º 1
0
        public void UpdateValue()
        {
            switch (Type)
            {
            case ReceiptFieldType.Number:
                Value = ValueNumber?.ToString() ?? string.Empty;
                break;

            case ReceiptFieldType.PhoneNumber:
                Value = ValuePhoneNumber;
                break;

            case ReceiptFieldType.Date:
                Value = ValueDate;
                break;

            case ReceiptFieldType.Time:
                Value = ValueTime;
                break;

            case ReceiptFieldType.String:
            default:
                Value = ValueString;
                break;
            }
        }
Ejemplo n.º 2
0
		private static Sentence _ParseEnumDefine(string src, int size, int pos, out int nextPos) {
			nextPos = pos;
			if (!Grammar.MatchEnum(src, size, pos, out pos)) {
				return null;
			}
			if (!Jump(src, size, pos, out pos)) {
				return null;
			}
			string name;
			if (!Grammar.MatchName(src, size, pos, out pos, out name)) {
				return null;
			}
			Jump(src, size, pos, out pos);
			if (!Grammar.MatchObjectBegin(src, size, pos, out pos)) {
				return null;
			}
			var checkNameSet = new HashSet<string>();
			var checkValueSet = new HashSet<double>();
			var valueList = new LinkedList<KeyValuePair<string, ValueNumber>>();
			double indexValue = 0;
			while (true) {
				if (pos >= size) {
					return null;
				}
				Jump(src, size, pos, out pos);
				if (Grammar.MatchObjectEnd(src, size, pos, out pos)) {
					break;
				}
				string valueName = "";
				if (!Grammar.MatchName(src, size, pos, out pos, out valueName)) {
					return null;
				}
				Jump(src, size, pos, out pos);
				if (Grammar.MatchAssign(src, size, pos, out pos)) {
					Jump(src, size, pos, out pos);
					if (!Grammar.MatchNumber(src, size, pos, out pos, out indexValue)) {
						return null;
					}
					Jump(src, size, pos, out pos);
				}

				var valueNumber = new ValueNumber(indexValue);
				if (!ValueTool.IsInteger(valueNumber)) {
					return null;
				}

				if (checkNameSet.Contains(valueName)) {
					return null;
				}
				if (checkValueSet.Contains(indexValue)) {
					return null;
				}
				checkNameSet.Add(valueName);
				checkValueSet.Add(indexValue);
				valueList.AddLast(new KeyValuePair<string, ValueNumber>(valueName, valueNumber));

				Jump(src, size, pos, out pos);
				if (!Grammar.MatchSplitSymbol(src, size, pos, out pos)) {
					if (Grammar.MatchObjectEnd(src, size, pos, out pos)) {
						break;
					}
					return null;
				}

				indexValue += 1;
			}
			nextPos = pos;
			return new SentenceEnumDefine(name, valueList);
		}
Ejemplo n.º 3
0
        public Mnemonic Get(ASTNode?node)
        {
            Mnemonic result = null;
            var      symbol = node.Value.Symbol.Name;

            switch (symbol)
            {
            case "assigment":
                result = new Assigment(node, this);
                break;

            case "expression":
                result = new Expression(node, this);
                break;

            case "expression_arg":
            case "expression_sum":
            case "expression_mult":
            case "expression_cmp":
            case "expression_bracket":
            case "expression_bool":
                result = new ExpressionCommon(node, this);
                break;

            case "expression_prefix":
                result = new ExpressionPrefix(node, this);
                break;

            case "NUMBER":
                result = new ValueNumber(node);
                break;

            case "STRING":
                result = new ValueString(node);
                break;

            case "method_call":
                result = new MethodCall(node, this);
                break;

            case "emptyLine":
                result = new Nop(node);
                break;

            case "variable_name":
                result = new VariableName(node, this);
                break;

            case "if":
                result = new If(node, this);
                break;

            case "block_of_lopla":
                result = new Block(node, this);
                break;

            case "method":
                result = new MethodDeclaration(node, this);
                break;

            case "declare_table":
                result = new DeclareTable(node, this);
                break;

            case "var_value_table":
                result = new ValueTable(node, this);
                break;

            case "while":
                result = new While(node, this);
                break;

            case "return":
                result = new Return(node, this);
                break;

            default:
                AddError(
                    new CompilationError($"{symbol} not handled by compiler. line: {node?.Position.Line}"));
                break;
            }

            return(result);
        }