BadScript 2
Loading...
Searching...
No Matches
BadOperatorTable.cs
Go to the documentation of this file.
9
11
15public class BadOperatorTable
16{
59
63 private readonly List<BadUnaryPrefixOperator> m_UnaryPrefixOperators = new List<BadUnaryPrefixOperator>
64 {
70 };
71
75 private readonly List<BadValueParser> m_ValueParsers = new List<BadValueParser>
76 {
81 };
82
86 private BadOperatorTable() { }
87
91 public static BadOperatorTable Instance { get; } = new BadOperatorTable();
92
96 public IEnumerable<string> BinarySymbols => m_Operators.Select(x => x.Symbol);
97
101 public IEnumerable<string> UnaryPrefixSymbols => m_UnaryPrefixOperators.Select(x => x.Symbol);
102
109 {
110 return m_ValueParsers.FirstOrDefault(x => x.IsValue(parser));
111 }
112
117 public void AddValueParser(BadValueParser parser)
118 {
119 m_ValueParsers.Add(parser);
120 }
121
127 {
128 m_Operators.Add(op);
129 }
130
139
146 public BadBinaryOperator? FindBinaryOperator(string symbol, int precedence)
147 {
148 return m_Operators.FirstOrDefault(
149 op => op.Symbol == symbol &&
150 (op.IsLeftAssociative && op.Precedence < precedence ||
151 !op.IsLeftAssociative && op.Precedence <= precedence)
152 );
153 }
154
161 public BadUnaryPrefixOperator? FindUnaryPrefixOperator(string symbol, int precedence)
162 {
163 return m_UnaryPrefixOperators.FirstOrDefault(
164 op => op.Symbol == symbol &&
165 (op.IsLeftAssociative && op.Precedence < precedence ||
166 !op.IsLeftAssociative && op.Precedence <= precedence)
167 );
168 }
169}
The Parser of the Language. It turns Source Code into an Expression Tree.
Base class for all binary operators.
Implements the Operator Table used by the Parser.
void AddUnaryPrefixOperator(BadUnaryPrefixOperator op)
Adds a Unary Prefix Operator Parser to the List of Unary Prefix Operators.
readonly List< BadBinaryOperator > m_Operators
List of Binary operators.
void AddOperator(BadBinaryOperator op)
Adds a Binary Operator Parser to the List of Binary Operators.
readonly List< BadValueParser > m_ValueParsers
List of Value Parsers.
readonly List< BadUnaryPrefixOperator > m_UnaryPrefixOperators
List of Unary Prefix Operators.
IEnumerable< string > BinarySymbols
Enumeration of all Binary Operator Symbols.
BadValueParser? GetValueParser(BadSourceParser parser)
Returns a Value Parser that is able to parse the given Token.
void AddValueParser(BadValueParser parser)
Adds a Value parser to the List of Value Parsers.
IEnumerable< string > UnaryPrefixSymbols
Enumeration of all Unary Prefix Operator Symbols.
BadBinaryOperator? FindBinaryOperator(string symbol, int precedence)
Finds a Binary Operator by its Symbol.
BadUnaryPrefixOperator? FindUnaryPrefixOperator(string symbol, int precedence)
Finds a Unary Prefix Operator by its Symbol.
static BadOperatorTable Instance
The Operator Table Instance.
Base class for all Unary Prefix Operators.
Base class for all Value Parsers.
Implements the Post Decrement Operator.
Implements the Post Increment Operator.
Contains the Comparison Operators for the BadScript2 Language.
Contains the Self-Assigning Logic Operators for the BadScript2 Language.
Contains the Logic Operators for the BadScript2 Language.
Contains the Self-Assignung Math Operators for the BadScript2 Language.
Contains the Atomic Math Operators for the BadScript2 Language.
Contains the Math Operators for the BadScript2 Language.
Contains the Binary Operators for the BadScript2 Language.
Contains the Operators for the BadScript2 Language.