Ejemplo n.º 1
0
		private string GetParameterizedSortName(IConsTerm term)
		{
			string name = ((IConsTerm)term[0]).Name;
			IListTerm args = (IListTerm)term[1];

			return String.Format("{0}_{1}", name, String.Join("", args.SubTerms.Select(t => ((IConsTerm)t).Name)));
		}
Ejemplo n.º 2
0
		/// <inheritdoc />
		protected override void WriteConsTerm(IConsTerm term, TextWriter writer)
		{
			// CONTRACT: Inherited from TermTextWriter

			// TODO: Escape constructor name.
			writer.Write(term.Name);
			writer.Write('(');
			this.WriteTermsList(term.SubTerms, ",", writer);
			writer.Write(')');
			this.WriteAnnotations(term.Annotations, writer);
		}
Ejemplo n.º 3
0
		public string TryGetSort(IConsTerm term)
		{
			if (term.IsCons("cf", 1))
				return TryGetSort((IConsTerm)term[0]);
			if (term.IsCons("lex", 1))
				return TryGetSort((IConsTerm)term[0]);
			if (term.IsCons("sort", 1))
				return term[0].ToString();
			if (term.IsCons("parameterized-sort", 2))
				return GetParameterizedSortName(term);
			if (term.IsCons("char-class", 1))
				return null;
			if (term.IsCons("alt", 2))
				return GetAltSortName(term);
			return null;
		}
Ejemplo n.º 4
0
        /// <inheritdoc />
        protected override void WriteConsTerm(IConsTerm term, TextWriter writer)
        {
            #region Contract
            if (term == null)
            {
                throw new ArgumentNullException(nameof(term));
            }
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            #endregion

            // TODO: Escape constructor name.
            writer.Write(term.Name);
            writer.Write('(');
            this.WriteTermsList(term.SubTerms, ",", writer);
            writer.Write(')');
            this.WriteAnnotations(term.Annotations, writer);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Writes a application term to the specified writer.
 /// </summary>
 /// <param name="term">The term to write.</param>
 /// <param name="writer">The text writer to write to.</param>
 protected abstract void WriteConsTerm(IConsTerm term, TextWriter writer);
Ejemplo n.º 6
0
		private string GetAltSortName(IConsTerm term)
		{
			string left = GetSort((IConsTerm)term[0]);
			string right = GetSort((IConsTerm)term[1]);
			return String.Format("{0}_{1}0", left, right);
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Gets the RTG sort name of a production, or the RTG element sort name for a list.
		/// </summary>
		/// <param name="term"></param>
		/// <returns></returns>
		public string GetSort(IConsTerm term)
		{
			string sort = TryGetSort(term);
			return sort ?? (term.SubTerms.Count > 0 ? GetSort((IConsTerm)term[0]) : null);
		}
Ejemplo n.º 8
0
		/// <summary>
		/// Implode a `appl(_, _)`.
		/// </summary>
		/// <param name="term"></param>
		/// <returns></returns>
		private ITerm ImplodeAppl(IConsTerm term)
		{
			
			throw new NotImplementedException();
		}
Ejemplo n.º 9
0
			protected override void WriteConsTerm(IConsTerm term, TextWriter writer)
			{
				Contract.Requires(term != null);
				Contract.Requires(writer != null);
			}
Ejemplo n.º 10
0
		/// <summary>
		/// Writes a application term to the specified writer.
		/// </summary>
		/// <param name="term">The term to write.</param>
		/// <param name="writer">The text writer to write to.</param>
		protected abstract void WriteConsTerm(IConsTerm term, TextWriter writer);
		/// <summary>
		/// Parses a reduce action item.
		/// </summary>
		/// <param name="term">The term.</param>
		/// <param name="labels">The labels in the parse table.</param>
		/// <returns>The parsed action item.</returns>
		/// <example>
		/// The term might look like this (without lookahead)
		/// <code>
		/// reduce(0,280,0)
		/// </code>
		/// or this (with lookahead)
		/// <code>
		/// reduce(0,280,0,[follow-restriction([char-class([42,47])])])
		/// </code>
		/// </example>
		private ActionItem ParseReduce(IConsTerm term, IReadOnlyList<Label> labels)
		{
			#region Contract
			Contract.Requires<ArgumentNullException>(term != null);
			Contract.Requires<ArgumentException>(term.IsCons("reduce", 3) || term.IsCons("reduce", 4));
			Contract.Requires<ArgumentNullException>(labels != null);
			Contract.Ensures(Contract.Result<ActionItem>() != null);
			#endregion

			int productionArity = term[0].ToInt32();
			var label = new LabelRef(term[1].ToInt32() - SpoofaxParseTableFormat.LabelBase);
			ProductionType status = (ProductionType)term[2].ToInt32();
			bool isRecover = labels[label.Index].Production.IsRecover;
			bool isCompletion = labels[label.Index].Production.IsCompletion;
			var followRestriction = term.SubTerms.Count == 4 ? ParseLookaheadCharRanges((IListTerm)term[3]) : ArrayExt.Empty<IReadOnlySet<CodePoint>>();

			// Redundant information. Let's check it while we're at it.
			var production = labels[label.Index].Production;
			Contract.Assert(production.Arity == productionArity);
			Contract.Assert(production.IsCompletion == isCompletion);
			Contract.Assert(production.IsRecover == isRecover);
			Contract.Assert(production.Type == status);

			return new ReduceActionItem(label, followRestriction);
		}
		/// <summary>
		/// Parses a shift action item.
		/// </summary>
		/// <param name="term">The term.</param>
		/// <returns>The parsed action item.</returns>
		/// <example>
		/// The term might look like this:
		/// <code>
		/// shift(22)
		/// </code>
		/// </example>
		private ActionItem ParseShift(IConsTerm term)
		{
			#region Contract
			Contract.Requires<ArgumentNullException>(term != null);
			Contract.Requires<ArgumentException>(term.IsCons("shift", 1));
			Contract.Ensures(Contract.Result<ActionItem>() != null);
			#endregion

			var nextState = new StateRef(term[0].ToInt32());

			return new ShiftActionItem(nextState);
		}
		/// <summary>
		/// Parses an accept action item.
		/// </summary>
		/// <param name="term">The term.</param>
		/// <returns>The parsed action item.</returns>
		/// <example>
		/// The term might look like this:
		/// <code>
		/// accept()
		/// </code>
		/// </example>
		private ActionItem ParseAccept(IConsTerm term)
		{
			#region Contract
			Contract.Requires<ArgumentNullException>(term != null);
			Contract.Requires<ArgumentException>(term.IsCons("accept", 0));
			Contract.Ensures(Contract.Result<ActionItem>() != null);
			#endregion

			return new AcceptActionItem();
		}
Ejemplo n.º 14
0
			public void VisitCons(IConsTerm term)
			{
				Contract.Requires<ArgumentNullException>(term != null);
			}