public decimal GetNumberValue(string variableName) { var variableId = GetQuestionNode(variableName).Id; if (m_symbolTable.Exists <int>(variableId)) { return(m_symbolTable.Lookup <int>(variableId)); } if (m_symbolTable.Exists <decimal>(variableId)) { return(m_symbolTable.Lookup <decimal>(variableId)); } throw new ArgumentException(nameof(variableName), $"question {variableName} used as numeric but is not"); }
/// <summary> /// Returns the next character using the given options, or <see cref="DONE"/> if there /// are no more characters, and advance the position to the next /// character. /// </summary> /// <param name="options">One or more of the following options, bitwise-OR-ed /// together: <see cref="RuleCharacterIteratorOptions.ParseVariables"/>, /// <see cref="RuleCharacterIteratorOptions.ParseEscapes"/>, /// <see cref="RuleCharacterIteratorOptions.SkipWhitespace"/>.</param> /// <returns>The current 32-bit code point, or <see cref="DONE"/>.</returns> public virtual int Next(RuleCharacterIteratorOptions options) { int c = DONE; isEscaped = false; for (; ;) { c = Current(); Advance(UTF16.GetCharCount(c)); if (c == SymbolTable.SYMBOL_REF && buf == null && (options & RuleCharacterIteratorOptions.ParseVariables) != 0 && sym != null) { string name = sym.ParseReference(text, pos, text.Length); // If name == null there was an isolated SYMBOL_REF; // return it. Caller must be prepared for this. if (name == null) { break; } bufPos = 0; buf = sym.Lookup(name); if (buf == null) { throw new ArgumentException( "Undefined variable: " + name); } // Handle empty variable value if (buf.Length == 0) { buf = null; } continue; } if ((options & RuleCharacterIteratorOptions.SkipWhitespace) != 0 && PatternProps.IsWhiteSpace(c)) { continue; } if (c == '\\' && (options & RuleCharacterIteratorOptions.ParseEscapes) != 0) { int[] offset = new int[] { 0 }; c = Utility.UnescapeAt(Lookahead(), offset); Jumpahead(offset[0]); isEscaped = true; if (c < 0) { throw new ArgumentException("Invalid escape"); } } break; } return(c); }
public string GetValue(ISymbolTable symbolTable, IQuestionNode question) { return(symbolTable .Lookup <decimal>(question.Id) .ToString(CultureInfo.InvariantCulture)); }
public bool Evaluate(IBooleanVariableNode node) { return(m_lookup.Lookup <bool>(GetQuestionId(node))); }
public string GetValue(ISymbolTable symbolTable, IQuestionNode question) { return(symbolTable.Lookup <string>(question.Id) ?? ""); }
public string GetValue(ISymbolTable symbolTable, IQuestionNode question) { return(symbolTable.Lookup <bool>(question.Id).ToString()); }
private void MainClass() { Match(Tokens.FinalT); Match(Tokens.ClassT); _symTab.Insert(Globals.Lexeme, Globals.Token, Globals.Depth, EntryType.ClassType); var type = _symTab.Lookup(Globals.Lexeme); type.TypeOfEntry = new Union <EntryType>(new ClassType(), EntryType.ClassType); _tacWriter.PrintLine("proc main"); _asmWriter.MainProc = "main"; _asmWriter.AddFunction(new TableNode { Depth = Globals.Depth, Lexeme = new Lexeme("main"), Token = Tokens.MainT, TypeOfEntry = new Union <EntryType>(new FunctionType(), EntryType.FunctionType) }); Match(Tokens.IdT); //Globals.Depth++; Match(Tokens.LBraceT); Match(Tokens.PublicT); Match(Tokens.StaticT); Match(Tokens.VoidT); //_symTab.Insert("Main", Tokens.IdT, Globals.Depth, EntryType.FunctionType); Match(Tokens.MainT); //Globals.Depth++; Match(Tokens.LParenT); Match(Tokens.StringT); Match(Tokens.LBrackT); Match(Tokens.RBrackT); // _symTab.Insert(Globals.Lexeme, Globals.Token, Globals.Depth, EntryType.VarType); Match(Tokens.IdT); Match(Tokens.RParenT); //Globals.Depth--; Match(Tokens.LBraceT); SeqOfStatements(); Match(Tokens.RBraceT); Match(Tokens.RBraceT); _tacWriter.PrintLine("endp main"); //Globals.Depth--; }