private SNodeBase ParseList(CLex lexer) { SNodeList node = new SNodeList(); node.Items = new List <SNodeBase>(); lexer.GetToken(); while ((lexer.CurToken.Type != TokenType.EOF) && !((lexer.CurToken.Type == TokenType.Symbol) && (lexer.CurToken.Value == ")") ) ) { // node.Items.Add(ParseNode(lexer)); } // == ) lexer.GetToken(); return(node); }
private SNodeBase ParseNode(CLex lexer) { if ((lexer.CurToken.Type == TokenType.Symbol) && (lexer.CurToken.Value == "(")) { //return ParseList(lexer); SNodeBase node = ParseList(lexer); if (node is SNodeList) { SNodeList list = node as SNodeList; // if (list.Items.Count > 0) { SExpression sexpr = new SExpression(); if (list.Items[0] is SNodeAtom) { SNodeAtom value = list.Items[0] as SNodeAtom; sexpr.Name = value.Value; } sexpr.Items = new List <SNodeBase>(); for (int index = 1; index < list.Items.Count; index++) { sexpr.Items.Add(list.Items[index]); } // return(sexpr); } else { return(node); } } else { return(node); } } else { // string SNodeAtom node; if (lexer.CurToken.Type == TokenType.StringLiteral) { string value = lexer.CurToken.Value; if (value.StartsWith("\"") && value.EndsWith("\"")) { value = value.Substring(1, value.Length - 2); // descape " and \ } node = new SNodeAtom(value); } else { node = new SNodeAtom(lexer.CurToken.Value); } lexer.GetToken(); return(node); } }