Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/S-expressions/Java/s-expressions-6.java
Normal file
47
Task/S-expressions/Java/s-expressions-6.java
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package jfkbits;
|
||||
|
||||
|
||||
public class LispParser
|
||||
{
|
||||
LispTokenizer tokenizer;
|
||||
|
||||
public LispParser(LispTokenizer input)
|
||||
{
|
||||
tokenizer=input;
|
||||
}
|
||||
|
||||
public class ParseException extends Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface Expr
|
||||
{
|
||||
// abstract parent for Atom and ExprList
|
||||
}
|
||||
|
||||
public Expr parseExpr() throws ParseException
|
||||
{
|
||||
Token token = tokenizer.next();
|
||||
switch(token.type)
|
||||
{
|
||||
case '(': return parseExprList(token);
|
||||
case '"': return new StringAtom(token.text);
|
||||
default: return new Atom(token.text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected ExprList parseExprList(Token openParen) throws ParseException
|
||||
{
|
||||
ExprList acc = new ExprList();
|
||||
while(tokenizer.peekToken().type != ')')
|
||||
{
|
||||
Expr element = parseExpr();
|
||||
acc.add(element);
|
||||
}
|
||||
Token closeParen = tokenizer.next();
|
||||
return acc;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue