String-Parsing List Constructor - Online Code


The following code implements a constructor for nonempty lists that takes a String representation of a list and parses it into a list. The parser used is a general-purpose parser for S-expressions. S-expressions (short for symbolic expressions) are built from a set of atomic elements (called atoms or symbols). Given the set of atoms, any S-expression is either an atom or a list of S-expressions. In order to avoid namespace clash with java.util, all S-expression classes (including List classes) are prepended with S. The constructor itself appears in class SCons. It also appears as a Factory method in class SExp.

Source Code

import java.util.*;

interface StackI {


   * @ pre ! isEmpty()


  public Object top();

  public Object pop();

  public void push(Object o);

  public boolean isEmpty();


class SExpParseExcep
... (login or register to view full code)

To view full code, you must Login or Register, its FREE.

Hey, registering yourself just takes less than a minute and opens up a whole new GetGyan experience.


No comment yet. Be the first to post a comment.