Beispiel #1
0
        /// <summary>Declares that the specified literal represents a boolean value.</summary>
        /// <param name="literal">The literal to declare as boolean.</param>
        /// <param name="value">The boolean value of the specified literal.</param>
        /// <param name="position">The start position of the boolean declaration in the source code.</param>
        public void DeclareBoolean(PredefinedLiteral literal, bool value, TextPosition position)
        {
            if (!TopLevel)
            {
                throw new ParserException("Boolean declarations are only allowed as top-level statements.", position);
            }

            switch (literal)
            {
            case PredefinedLiteral.Positive: polarityIsBoolean = true; positiveIsTrue = value; break;

            case PredefinedLiteral.Negative: polarityIsBoolean = true; positiveIsTrue = !value; break;

            case PredefinedLiteral.North: magneticIsBoolean = true; northIsTrue = value; break;

            case PredefinedLiteral.South: magneticIsBoolean = true; northIsTrue = !value; break;

            case PredefinedLiteral.Clockwise: curlIsBoolean = true; clockwiseIsTrue = value; break;

            case PredefinedLiteral.Counterclockwise: clockwiseIsTrue = true; clockwiseIsTrue = !value; break;

            case PredefinedLiteral.Open: circuitIsBoolean = true; openIsTrue = value; break;

            case PredefinedLiteral.Closed: circuitIsBoolean = true; openIsTrue = !value; break;
            }
        }
        static DataType GetType(PredefinedLiteral literal)
        {
            switch (literal)
            {
            case PredefinedLiteral.True:
            case PredefinedLiteral.False: return(DataType.Logic);

            case PredefinedLiteral.Positive:
            case PredefinedLiteral.Negative: return(DataType.Polarity);

            case PredefinedLiteral.North:
            case PredefinedLiteral.South: return(DataType.Magnetic);

            case PredefinedLiteral.Clockwise:
            case PredefinedLiteral.Counterclockwise: return(DataType.Curl);

            case PredefinedLiteral.Open:
            case PredefinedLiteral.Closed: return(DataType.Circuit);

            default: return(DataType.None);
            }
        }
Beispiel #3
0
 static void Add(string word, PredefinedLiteral literal)
 {
     Add(word, TokenType.Literal);
     literals[word] = literal;
 }
Beispiel #4
0
 /// <summary>Checks whether this token is the specified predefined literal token.</summary>
 /// <param name="literal">The predefined literal to check.</param>
 /// <returns>If this token equals the specified literal, true; otherwise, false.</returns>
 public virtual bool Equals(PredefinedLiteral literal)
 {
     return(false);
 }
 /// <summary>Checks whether this token is the specified predefined literal token.</summary>
 /// <param name="literal">The predefined literal to check.</param>
 /// <returns>If this token equals the specified literal, true; otherwise, false.</returns>
 public override bool Equals(PredefinedLiteral literal)
 {
     return(value == literal);
 }
 /// <summary>Initializes a new instance of the <see cref="PredefinedLiteralToken"/> class.</summary>
 /// <param name="value">The value of the literal.</param>
 /// <param name="startPosition">The start position.</param>
 /// <param name="endPosition">The end position.</param>
 internal PredefinedLiteralToken(PredefinedLiteral value, TextPosition startPosition, TextPosition endPosition)
     : base(GetType(value), startPosition, endPosition)
 {
     this.value = value;
 }