Mon Jan 30 07:10:19 2023
EVENTS
 FREE
SOFTWARE
INSTITUTE

POLITICS
JOBS
MEMBERS'
CORNER

MAILING
LIST

NYLXS Mailing Lists and Archives
NYLXS Members have a lot to say and share but we don't keep many secrets. Join the Hangout Mailing List and say your peice.

DATE 2016-02-01

HANGOUT

2023-01-30 | 2022-12-30 | 2022-11-30 | 2022-10-30 | 2022-09-30 | 2022-08-30 | 2022-07-30 | 2022-06-30 | 2022-05-30 | 2022-04-30 | 2022-03-30 | 2022-02-28 | 2022-01-28 | 2021-12-28 | 2021-11-28 | 2021-10-28 | 2021-09-28 | 2021-08-28 | 2021-07-28 | 2021-06-28 | 2021-05-28 | 2021-04-28 | 2021-03-28 | 2021-02-28 | 2021-01-28 | 2020-12-28 | 2020-11-28 | 2020-10-28 | 2020-09-28 | 2020-08-28 | 2020-07-28 | 2020-06-28 | 2020-05-28 | 2020-04-28 | 2020-03-28 | 2020-02-28 | 2020-01-28 | 2019-12-28 | 2019-11-28 | 2019-10-28 | 2019-09-28 | 2019-08-28 | 2019-07-28 | 2019-06-28 | 2019-05-28 | 2019-04-28 | 2019-03-28 | 2019-02-28 | 2019-01-28 | 2018-12-28 | 2018-11-28 | 2018-10-28 | 2018-09-28 | 2018-08-28 | 2018-07-28 | 2018-06-28 | 2018-05-28 | 2018-04-28 | 2018-03-28 | 2018-02-28 | 2018-01-28 | 2017-12-28 | 2017-11-28 | 2017-10-28 | 2017-09-28 | 2017-08-28 | 2017-07-28 | 2017-06-28 | 2017-05-28 | 2017-04-28 | 2017-03-28 | 2017-02-28 | 2017-01-28 | 2016-12-28 | 2016-11-28 | 2016-10-28 | 2016-09-28 | 2016-08-28 | 2016-07-28 | 2016-06-28 | 2016-05-28 | 2016-04-28 | 2016-03-28 | 2016-02-28 | 2016-01-28 | 2015-12-28 | 2015-11-28 | 2015-10-28 | 2015-09-28 | 2015-08-28 | 2015-07-28 | 2015-06-28 | 2015-05-28 | 2015-04-28 | 2015-03-28 | 2015-02-28 | 2015-01-28 | 2014-12-28 | 2014-11-28 | 2014-10-28 | 2014-09-28 | 2014-08-28 | 2014-07-28 | 2014-06-28 | 2014-05-28 | 2014-04-28 | 2014-03-28 | 2014-02-28 | 2014-01-28 | 2013-12-28 | 2013-11-28 | 2013-10-28 | 2013-09-28 | 2013-08-28 | 2013-07-28 | 2013-06-28 | 2013-05-28 | 2013-04-28 | 2013-03-28 | 2013-02-28 | 2013-01-28 | 2012-12-28 | 2012-11-28 | 2012-10-28 | 2012-09-28 | 2012-08-28 | 2012-07-28 | 2012-06-28 | 2012-05-28 | 2012-04-28 | 2012-03-28 | 2012-02-28 | 2012-01-28 | 2011-12-28 | 2011-11-28 | 2011-10-28 | 2011-09-28 | 2011-08-28 | 2011-07-28 | 2011-06-28 | 2011-05-28 | 2011-04-28 | 2011-03-28 | 2011-02-28 | 2011-01-28 | 2010-12-28 | 2010-11-28 | 2010-10-28 | 2010-09-28 | 2010-08-28 | 2010-07-28 | 2010-06-28 | 2010-05-28 | 2010-04-28 | 2010-03-28 | 2010-02-28 | 2010-01-28 | 2009-12-28 | 2009-11-28 | 2009-10-28 | 2009-09-28 | 2009-08-28 | 2009-07-28 | 2009-06-28 | 2009-05-28 | 2009-04-28 | 2009-03-28 | 2009-02-28 | 2009-01-28 | 2008-12-28 | 2008-11-28 | 2008-10-28 | 2008-09-28 | 2008-08-28 | 2008-07-28 | 2008-06-28 | 2008-05-28 | 2008-04-28 | 2008-03-28 | 2008-02-28 | 2008-01-28 | 2007-12-28 | 2007-11-28 | 2007-10-28 | 2007-09-28 | 2007-08-28 | 2007-07-28 | 2007-06-28 | 2007-05-28 | 2007-04-28 | 2007-03-28 | 2007-02-28 | 2007-01-28 | 2006-12-28 | 2006-11-28 | 2006-10-28 | 2006-09-28 | 2006-08-28 | 2006-07-28 | 2006-06-28 | 2006-05-28 | 2006-04-28 | 2006-03-28 | 2006-02-28 | 2006-01-28 | 2005-12-28 | 2005-11-28 | 2005-10-28 | 2005-09-28 | 2005-08-28 | 2005-07-28 | 2005-06-28 | 2005-05-28 | 2005-04-28 | 2005-03-28 | 2005-02-28 | 2005-01-28 | 2004-12-28 | 2004-11-28 | 2004-10-28 | 2004-09-28 | 2004-08-28 | 2004-07-28 | 2004-06-28 | 2004-05-28 | 2004-04-28 | 2004-03-28 | 2004-02-28 | 2004-01-28 | 2003-12-28 | 2003-11-28 | 2003-10-28 | 2003-09-28 | 2003-08-28 | 2003-07-28 | 2003-06-28 | 2003-05-28 | 2003-04-28 | 2003-03-28 | 2003-02-28 | 2003-01-28 | 2002-12-28 | 2002-11-28 | 2002-10-28 | 2002-09-28 | 2002-08-28 | 2002-07-28 | 2002-06-28 | 2002-05-28 | 2002-04-28 | 2002-03-28 | 2002-02-28 | 2002-01-28 | 2001-12-28 | 2001-11-28 | 2001-10-28 | 2001-09-28 | 2001-08-28 | 2001-07-28 | 2001-06-28 | 2001-05-28 | 2001-04-28 | 2001-03-28 | 2001-02-28 | 2001-01-28 | 2000-12-28 | 2000-11-28 | 2000-10-28 | 2000-09-28 | 2000-08-28 | 2000-07-28 | 2000-06-28 | 2000-05-28 | 2000-04-28 | 2000-03-28 | 2000-02-28 | 2000-01-28 | 1999-12-28

Key: Value:

Key: Value:

MESSAGE
DATE 2016-02-21
FROM Ruben Safir
SUBJECT Subject: [Hangout-NYLXS] Antlr
From hangout-bounces-at-nylxs.com Sun Feb 21 04:12:40 2016
Return-Path:
X-Original-To: archive-at-mrbrklyn.com
Delivered-To: archive-at-mrbrklyn.com
Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82])
by mrbrklyn.com (Postfix) with ESMTP id 0BE2F163D98;
Sun, 21 Feb 2016 04:12:25 -0500 (EST)
X-Original-To: hangout-at-nylxs.com
Delivered-To: hangout-at-nylxs.com
Received: from [10.0.0.19] (stat13.mrbrklyn.com [10.0.0.19])
by mrbrklyn.com (Postfix) with ESMTP id 56B181616D8
for ; Sun, 21 Feb 2016 03:40:34 -0500 (EST)
To: Hangout
From: Ruben Safir
Message-ID: <56C97802.6080004-at-mrbrklyn.com>
Date: Sun, 21 Feb 2016 03:40:34 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
Thunderbird/38.5.1
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------030007050405090704000103"
Subject: [Hangout-NYLXS] Antlr
X-BeenThere: hangout-at-nylxs.com
X-Mailman-Version: 2.1.17
Precedence: list
Reply-To: NYLXS Discussions List
List-Id: NYLXS Discussions List
List-Unsubscribe: ,

List-Archive:
List-Post:
List-Help:
List-Subscribe: ,

Errors-To: hangout-bounces-at-nylxs.com
Sender: "hangout"

This is a multi-part message in MIME format.
--------------030007050405090704000103
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

anyone try to use Antlr yet? It is a decent gammer parser. I got it
working on the command line, but it has a working plugin for netbeans

We've been writing lexers and parser in Java so far with a gradle
compiler for java. Java is really a PIA.

this is not all my code, but you can get an idea of how the compiler
shapes up

Ruben
--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

--------------030007050405090704000103
Content-Type: text/x-java;
name="Interpreter.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Interpreter.java"

package pico;

import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Stack;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collections;



public class Interpreter {

Stack stack = new Stack();//Where is the keyword Value defined?
HashMap dict = new HashMap<>(); //symbols table (dynamic)

public void interpret(TokenSource lists_of_stuff) {
for(Token token = lists_of_stuff.nextToken();
token.type != Token.Type.EOF;
token = lists_of_stuff.nextToken())
{
switch(token.type) {
case INT:
case STR:
case SYM:
stack.push(new Value(token)); //sends token to Value
break;
case LBRACE:
stack.push(new Value(lists_of_stuff));// sends a
break;
case OP:
// First check the dictionary.
Value v = dict.get(token.text); //This is hash behavior
if(v != null) {
if(v.type == Value.Type.BLOCK) {
interpret(v.asTokenSource()); //RECURSIVE CALL
}
else {
stack.push(v);
}
}
else {
try {
// Invoke by reflection -- looks for a public void
// method with same name as the operator.
Method m = Interpreter.class.getMethod("__" + token.text);
m.invoke(this);
} catch (NoSuchMethodException e) {
throw new RuntimeError("Unknown operator: " + token.text);
} catch (IllegalAccessException e) {
throw new RuntimeError(e);
} catch (InvocationTargetException e) {
throw new RuntimeError(e + token.text );
}
}
break;
default:
throw new RuntimeError("Unhandled token type: " + token.type);
}
}
}

public void __add() {
BigInteger y = stack.pop().asInteger();
BigInteger x = stack.pop().asInteger();
stack.push(new Value(x.add(y)));
}

public void __idiv() {
BigInteger y = stack.pop().asInteger();
BigInteger x = stack.pop().asInteger();
stack.push(new Value(x.divide(y)));
}

public void __mul() {
BigInteger y = stack.pop().asInteger();
BigInteger x = stack.pop().asInteger();
stack.push(new Value(x.multiply(y)));
}

public void __sub() {
BigInteger y = stack.pop().asInteger();
BigInteger x = stack.pop().asInteger();
stack.push(new Value(x.subtract(y)));
}

public void __mod() {
BigInteger y = stack.pop().asInteger();
BigInteger x = stack.pop().asInteger();
stack.push(new Value(x.mod(y)));
}

public void __length() {
Value str_val_tok = stack.pop();
String str_1 = str_val_tok.text;
stack.push( new Value( BigInteger.valueOf( (str_1.length() ) ) ) );
}

public void __get() {
BigInteger pos = stack.pop().asInteger();
Value str_val_tok = stack.pop();
String str_2 = str_val_tok.text;
int stop = str_2.length();
System.out.println( "stop ==>" + stop + "pos ==> " + pos + ":" + str_2);
if(pos.intValue() < stop){
char tmp = str_2.charAt(pos.intValue());
System.out.println( "tmp ==>" + tmp + "pos ==> " + pos + ":" + str_2);
stack.push( new Value( BigInteger.valueOf( (int) tmp )));
}
else{
throw new RuntimeError("strewed");
}
}

public void __strcat(){
Value str_val_tok = stack.pop();
Value str_val_tok2 = stack.pop();
String str_3 = str_val_tok.text;
String str_4 = str_val_tok2.text;
String whole_string = new StringBuffer().append(str_4).append(str_3).toString();
Token tmp_tok = new Token( Token.Type.STR, whole_string );
stack.push(new Value(tmp_tok));
}

public void __tostr(){
Value unknown_tok = stack.pop();
if(unknown_tok.type == Value.Type.BOOL ){
String tmp = Boolean.toString(unknown_tok.truth);
Token tmp_lextok = new Token(Token.Type.STR,tmp);
stack.push(new Value(tmp_lextok));
}else if(unknown_tok.type == Value.Type.INT){
String tmp = unknown_tok.integer.toString(10);
Token tmp_lextok = new Token(Token.Type.STR,tmp);
stack.push(new Value(tmp_lextok));
}
else{
throw new RuntimeError("Unhandled token type: " + unknown_tok.type);
}
}

public void __tochar(){
Value unknown_tok = stack.pop();
if(unknown_tok.type == Value.Type.INT){
if(unknown_tok.integer.intValue() > 2097152 ){
throw new RuntimeError("Unhandled token value Greater than 2097152 " + unknown_tok.integer.intValue());
}
int ascii = unknown_tok.integer.intValue();
char letter = (char)ascii;
String tmp = Character.toString(letter);
stack.push(new Value(new Token(Token.Type.STR, tmp)));
}else{
throw new RuntimeError("Unhandled token type: " + unknown_tok.type);
}
}

public void __true(){
System.out.println("Welcome to __true");
stack.push(new Value(true));
}
public void __false(){
System.out.println("Welcome to __false");
stack.push(new Value(false));
}

public void __eq(){
int t = __cmp();
if(t == 0){
stack.push(new Value(true));
}
else{
stack.push(new Value(false));
}
}

public void __ne(){
int t = __cmp();
if(t == 0){
stack.push(new Value(false));
}
else{
stack.push(new Value(true));
}
}

public void __ge(){
int t = __cmp();
if (t == -99){
throw new RuntimeError("Wrong Compare Operand Types");
}else{
if(t == 0){
stack.push(new Value(true));
}else if(t > 0){
stack.push(new Value(true));
}else if(t < 0 ){
stack.push(new Value(false));
}else{
throw new RuntimeError("Nomans land " + t);
}
}

}

public void __gt(){
int t = __cmp();
if (t == -99){
throw new RuntimeError("Wrong Compare Operand Types");
}else{
if(t == 0){
stack.push(new Value(false));
}else if(t > 0){
stack.push(new Value(true));
}else if(t < 0 ){
stack.push(new Value(false));
}else{
throw new RuntimeError("Nomans land " + t);
}
}

}

public void __le(){
int t = __cmp();
if (t == -99){
throw new RuntimeError("Wrong Compare Operand Types");
}else{
if(t == 0){
stack.push(new Value(true));
}else if(t > 0){
stack.push(new Value(false));
}else if(t < 0 ){
stack.push(new Value(true));
}else{
throw new RuntimeError("Nomans land " + t);
}
}

}

public void __lt(){
int t = __cmp();
if (t == -99){
throw new RuntimeError("Wrong Compare Operand Types");
}else{
if(t == 0){
stack.push(new Value(false));
}else if(t > 0){
stack.push(new Value(false));
}else if(t < 0 ){
stack.push(new Value(true));
}else{
throw new RuntimeError("Nomans land " + t);
}
}
}

public void __and(){
Value tmp1 = stack.pop();
Value tmp2 = stack.pop();
if((tmp1.type != Value.Type.BOOL) && (tmp2.type != Value.Type.BOOL)){
throw new RuntimeError("Wrong Compare Operator types - Not BOOL");
}
else{
if((tmp1.truth == true) && (tmp2.truth == true) ){
stack.push(new Value(true));
}else{
stack.push(new Value(false));
}
}
}

public void __or(){
Value tmp1 = stack.pop();
Value tmp2 = stack.pop();
if((tmp1.type != Value.Type.BOOL) && (tmp2.type != Value.Type.BOOL)){
throw new RuntimeError("Wrong Compare Operator types - Not BOOL");
}
else{
if((tmp1.truth == true) || (tmp2.truth == true) ){
stack.push(new Value(true));
}else{
stack.push(new Value(false));
}
}
}

public void __not(){
Value tmp1 = stack.pop();
if(tmp1.type != Value.Type.BOOL ){
throw new RuntimeError("Wrong Compare Operator types - Not BOOL");
}
else{
if(tmp1.truth == true ){
stack.push(new Value(false));
}else{
stack.push(new Value(true));
}
}
}

public void __if(){
//Takes 2 values. The second is a BOOL value. If the second one is true, then run the first
//which might be a block
Value tmp1 = stack.pop();
Value tmp2 = stack.pop(); //Boolean
if(tmp2.type != Value.Type.BOOL){
throw new RuntimeError("Wrong Compare Operator types - Not BOOL");
}
if(tmp1.type != Value.Type.BLOCK){
throw new RuntimeError("Wrong Compare Operator types - Not BLOCK");
}
if(tmp2.truth == true){
interpret(tmp1.asTokenSource());
}
}

public void __ifelse(){
//Takes 2 values. The second is a BOOL value. If the second one is true, then run the first
//which might be a block
Value tmp1a = stack.pop();//FALSE BLOCK
Value tmp1b = stack.pop();//TRUE BLOCK
Value tmp2 = stack.pop(); //Boolean
if(tmp2.type != Value.Type.BOOL){
throw new RuntimeError("Wrong Compare Operator types - Not BOOL");
}
if(tmp1b.type != Value.Type.BLOCK){
throw new RuntimeError("Wrong Compare Operator types - Not BLOCK");
}
if(tmp1a.type != Value.Type.BLOCK){
throw new RuntimeError("Wrong Compare Operator types - Not BLOCK");
}
if(tmp2.truth == true){
interpret(tmp1b.asTokenSource());
}else{
interpret(tmp1a.asTokenSource());
}
}

public void __repeat(){
Value tmp2= stack.pop();//int
Value tmp = stack.pop();//block
BigInteger one = new BigInteger("1"); //THAT SUCKS
System.out.println("Welcome to Repeat " + one );
BigInteger i = new BigInteger("0");
// System.out.println("Welcome to Repeat i=>" + i );
// System.out.println("Welcome to Repeat integer=> " + tmp.integer );
for(; tmp.integer.compareTo(i) > 0 ; i = i.add(one) )
{
// System.out.println("Welcome to Repeat " + one );
// System.out.println("Welcome to Repeat");
interpret(tmp2.asTokenSource());
}
}

public void __for(){
Value proc_block = stack.pop();
Value limit = stack.pop();
Value increment = stack.pop();
Value initial = stack.pop();
BigInteger control = initial.integer;
//System.out.println("For : control: " + control );
//System.out.println("limit => " + limit.integer );
//System.out.println("increment => " + increment.integer );
//System.out.println("initial => " + initial.integer );
//System.out.println(control.compareTo(limit.integer));
while(control.compareTo(limit.integer) < 0){
stack.push(new Value(control));
//System.out.println("For : control: " + control );
//System.out.println("PROCBLOCK TYPE ==>" + proc_block.type );
//System.out.println("block procedure==>" + proc_block );
//System.out.println("Stack Top" + stack.peek() );
interpret(proc_block.asTokenSource()) ;
//System.out.println("Stack Top" + stack.peek() );
control = control.add(increment.integer);
}
}

public void __while(){
Value ex = stack.pop();
System.out.println("ex block procedure==>" + ex );
Value bl = stack.pop();
System.out.println("bl block procedure==>" + bl );
interpret(bl.asTokenSource());
System.out.println("Stack Top => " + stack.peek() );
while(stack.pop().truth){
interpret(ex.asTokenSource());
interpret(bl.asTokenSource());
}
}



private int __cmp(){
Value tmp1 = stack.pop();
Value tmp2 = stack.pop();

switch(tmp1.type) {
case STR:
case INT:
case SYM:
case BOOL:
break;
default:
return -99;
}
switch (tmp2.type) {
case STR:
case INT:
case SYM:
case BOOL:
break;
default:
return -99;
}
if(tmp2.type != tmp1.type){
return -1;
}
if(tmp1.type == Value.Type.INT){
return tmp2.integer.compareTo(tmp1.integer);
}
if( tmp1.type == Value.Type.STR ){
return tmp2.text.compareTo(tmp1.text);
}

if( tmp1.type == Value.Type.SYM ){
if( tmp1.text.compareTo(tmp2.text) == 0 ){
return 0;
}else{
return -1;
}
}
if ( tmp1.type == Value.Type.BOOL){
if(tmp1.truth == false || tmp2.truth == false){
return -1;
}else{
return 0;
}
}
return -99;

}

public void __pop(){
stack.pop();
}

public void __def() {
Value v = stack.pop();
String id = stack.pop().asSymbol();
dict.put(id, v);
}

public void __dup() {
stack.push(stack.peek());
}
public void __exch() {
Value tmp = stack.pop();
Value tmp2 = stack.pop();
stack.push(tmp);
stack.push(tmp2);
}

public void __copy(){
Value elem = stack.pop();
ArrayList tmp_storage;
tmp_storage = new ArrayList();
BigInteger top = elem.integer;
BigInteger one = new BigInteger("1");
BigInteger i = new BigInteger("0");
while(top.compareTo(i) > 0 ){
tmp_storage.add(stack.pop());
i = i.add(one);
}
Collections.reverse(tmp_storage);
Iterator itr = tmp_storage.iterator();

while(itr.hasNext()){
stack.push( itr.next() );
}

itr = tmp_storage.iterator();
while(itr.hasNext()){
stack.push( itr.next() );
}
}

public void __index(){
ArrayList tmp_storage;
tmp_storage = new ArrayList();
Value elem = stack.pop();
Value tmp_to_push_at_the_end = elem;
BigInteger top = elem.integer; //index - need to add one
BigInteger one = new BigInteger("1");
BigInteger i = new BigInteger("0");
top = top.add(one);
while(top.compareTo(i) > 0 ){
tmp_to_push_at_the_end = stack.pop();
tmp_storage.add(tmp_to_push_at_the_end);
i = i.add(one);
}
Collections.reverse(tmp_storage);
Iterator itr = tmp_storage.iterator();
while(itr.hasNext()){
stack.push( itr.next() );
}
stack.push(tmp_to_push_at_the_end);
}

public void __clear(){
stack.clear();
}

public void __count(){
stack.push(new Value( BigInteger.valueOf(stack.size()) ));
}


public static void main(String[] args)
{
System.out.println(
"Patiently awaiting your code (^D or ^Z to end)");
Lexer lexer = new Lexer(new InputStreamReader(System.in));
Interpreter i = new Interpreter();
i.interpret(lexer);
System.out.println(i.stack);
}
}

--------------030007050405090704000103
Content-Type: text/x-java;
name="Lexer.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Lexer.java"

package pico;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;

/** Tokenizer for Picoscript */
public class Lexer implements TokenSource {

/** We'll use the character representation of -1 to represent end-of-input
* (the -1 actually becomes 65535 due to Java's UNSIGNED two-byte
* characters, but that code point is uninhabited in Unicode so it's safe).
*/
static final char EOF = (char)-1;

Reader reader; // The input character stream
char lookahead; // The single lookahead character
int line = 1, column = 0; // Current position


/** Basic constructor uses the `Reader` type, so we can get one char at
* a time.
*/
public Lexer(Reader reader) {
this.reader = reader;
consume();
}

/** Convenience constructor for tokenizing a string. */
public Lexer(String s) {
this(new StringReader(s));
}

/** Discard the current lookahead character and load the next one. */
private void consume() {
try {
lookahead = (char)reader.read();
if(lookahead == '\n') {
line++; column=0;
} else {
column++;
}
}
catch(IOException exn) {
lookahead = EOF;
}
}

public Token nextToken() {
// TODO: this is the heart of your lexer
while(lookahead != EOF) {
Token t;
int tokenLine = line;
int tokenColumn = column;
switch(lookahead) {
case ' ':
case '\t':
case '\n':
case '\r':
consume();
continue;
case '%':
skipComment();
continue;
case '{':
consume();
t = new Token(Token.Type.LBRACE);
break;
case '}':
consume();
t = new Token(Token.Type.RBRACE);
break;
case '/':
consume();
t = new Token(Token.Type.SYM, scanIdentifier());
break;
case '(':
consume();
t = scanString();
break;
default:
if(Character.isDigit(lookahead) ||
lookahead == '-') {
t = scanInteger();
}
else if(Character.isAlphabetic(lookahead)) {
t = new Token(Token.Type.OP, scanIdentifier());
}
else {
throw new LexError(line, column,
"Invalid character: " + lookahead);
}
}
if(t != null) return t.setPosition(tokenLine, tokenColumn);
}
return new Token(Token.Type.EOF);
}

void skipComment() {
do {
consume();
} while(lookahead != '\n' && lookahead != EOF);
}

Token scanInteger() {
StringBuilder buffer = new StringBuilder();
do {
buffer.append(lookahead);
consume();
} while(Character.isDigit(lookahead));
return new Token(Token.Type.INT, buffer.toString());
}

static boolean isSeparator(char c) {
switch(c) {
case ' ':
case '\n':
case '\t':
case '\r':
case '{':
case '}':
case '(':
case ')':
case '%':
case EOF:
return true;
default:
return false;
}
}

String scanIdentifier() {
StringBuilder buffer = new StringBuilder();
do {
buffer.append(lookahead);
consume();
} while(!isSeparator(lookahead));
return buffer.toString();
}

Token scanString() {
StringBuilder buffer = new StringBuilder();
int depth = 1;
while(true)
{
switch(lookahead) {
case '(':
depth++;
break;
case ')':
depth--;
if(depth == 0) {
consume();
return new Token(Token.Type.STR, buffer.toString());
}
break;
case '\\':
consume();
switch(lookahead) {
case 'n': lookahead = '\n'; break;
}
break;
case EOF:
throw new LexError(line, column, "Unterminated string");
}
buffer.append(lookahead);
consume();
}
}

/** Here is a sample program that reads an expression from standard
* input. Press control-D (or maybe control-Z) to send the EOF and
* print the tokens.
*/
public static void main(String[] args) {
/* Read from standard input */
System.out.println(
"Patiently awaiting your code (^D or ^Z to end)");
Lexer lexer = new Lexer(new InputStreamReader(System.in));
Token token;
do {
token = lexer.nextToken();
System.out.println(token);
} while(token.type != Token.Type.EOF);
}

}

--------------030007050405090704000103
Content-Type: text/x-java;
name="LexError.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="LexError.java"

package pico;

public class LexError extends Error {
public LexError(int line, int column, String message) {
super(message + " -at-" + line + ":" + column);
}
}
--------------030007050405090704000103
Content-Type: text/x-java;
name="RuntimeError.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="RuntimeError.java"

package pico;

public class RuntimeError extends Error {
public RuntimeError(String message)
{
super(message);
}

public RuntimeError(Exception cause) {
super(cause);
}
}
--------------030007050405090704000103
Content-Type: text/x-java;
name="Token.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Token.java"

package pico;

import org.junit.Assert;

import java.math.BigInteger;
import java.util.List;

public class Token {
//// TOKEN DATA
Type type; // Required: what type of token is this?
int line, column; // Optional: where is it in the source?
String text; // Variant: only used for type in (STR,SYM,OP)

enum Type {
EOF, // End of input
LBRACE, // Left curly '{'
RBRACE, // Right curly '}'
INT, // Integer literal
STR, // String literal
SYM, // Unevaluated symbol
OP, // Named operator, such as 'add' or 'dup'
}

/** Basic constructor */
Token(Type type, String text) {
this.type = type;
this.text = text;
}

/** Convenience constructor for when `text` can be null. */
Token(Type type) {
this(type, null);
}

/** Provide the position information */
public Token setPosition(int line, int column) {
if(line <= 0) throw new IllegalArgumentException("Line# should be >0");
this.line = line;
this.column = column;
return this;
}

public Token clearPosition() {
line = column = 0;
return this;
}

/** We override toString so we can get sensible output when we try to
* print tokens.
*/
-at-Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(type);
switch(type) {
case INT:
case STR:
case SYM:
case OP:
// Half-hearted attempt to escape special chars
// (it's only for debugging output)
String escaped = text
.replace("\n", "\\n")
.replace("(", "\\(")
.replace(")", "\\)");
buf.append('(');
buf.append(escaped);
buf.append(')');
break;
}
if(line > 0) {
buf.append("-at-" + line + ":" + column);
}
return buf.toString();
}

/** Just a short program to illustrate some of the capabilities of Tokens.
*/
public static void main(String[] args) {
Token t1 = new Token(Type.SYM, "square");
showEqual(t1, "SYM(square)");

Token t2 = new Token(Type.INT, "298347509328760987");
showEqual(t2, "INT(298347509328760987)");

Token t3 = new Token(Type.LBRACE).setPosition(2,5);
showEqual(t3, "LBRACE-at-2:5");

Token t4 = new Token(Type.OP, "dup");
showEqual(t4, "OP(dup)");

Token t5 = new Token(Type.STR, "hello world!").setPosition(15,8);
showEqual(t5, "STR(hello world!)-at-15:8");
}

static void showEqual(Token t, String expected) {
String s = t.toString();
System.out.println(s);
Assert.assertEquals(expected, s);
}
}
--------------030007050405090704000103
Content-Type: text/x-java;
name="TokenListSource.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="TokenListSource.java"

package pico;

import java.util.ArrayList;

public class TokenListSource implements TokenSource {
ArrayList list;
int nextIndex = 0;

public TokenListSource(ArrayList list) {
this.list = list;
}

-at-Override
public Token nextToken() {
if(nextIndex < list.size()) {
return list.get(nextIndex++);
}
else {
return new Token(Token.Type.EOF);
}
}
}

--------------030007050405090704000103
Content-Type: text/x-java;
name="TokenSource.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="TokenSource.java"

package pico;

public interface TokenSource {
Token nextToken();
}

--------------030007050405090704000103
Content-Type: text/x-java;
name="Value.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Value.java"

package pico;

import java.math.BigInteger;
import java.util.ArrayList;

public class Value {

enum Type {
INT,
SYM,
STR,
BLOCK,
BOOL
};

Type type;
String text; // used for SYM, STR
BigInteger integer; // used for INT
ArrayList list; // used for BLOCK
boolean truth; //used for BOOL

public Value(BigInteger integer) {
type = Type.INT;
this.integer = integer;
}

public Value(boolean b){
type = Type.BOOL;
this.truth = new Boolean(b);
}

public Value(TokenSource tokens) {
type = Type.BLOCK;
list = new ArrayList<>();
int depth = 1;
while(true)
{
Token t = tokens.nextToken();
if(t.type == Token.Type.RBRACE) {
depth--;
if(depth == 0)
return;
}
else if(t.type == Token.Type.LBRACE) {
depth++;
}
list.add(t);
}
}

public Value(Token token) {
switch(token.type) {
case INT:
type = Type.INT;
integer = new BigInteger(token.text);
break;
case SYM:
type = Type.SYM;
text = token.text;
break;
case STR:
type = Type.STR;
text = token.text;
break;
default:
throw new RuntimeError("Token cannot become a value: "
+ token);
}
}

public BigInteger asInteger() {
if(type == Type.INT) {
return integer;
}
else {
throw new RuntimeError(
"Expected INT, found " + type
);
}
}

public TokenSource asTokenSource() {
if(type == Type.BLOCK) {
return new TokenListSource(list);
}
else {
throw new RuntimeError(
"Expected BLOCK, found " + type
);
}
}

public String asSymbol() {
if(type == Type.SYM) {
return text;
}
else {
throw new RuntimeError(
"Expected SYM, found " + type
);
}
}

-at-Override
public String toString()
{
switch(type) {
case INT:
return integer.toString();
case SYM:
case STR:
return text;
case BLOCK:
return list.toString();
case BOOL:
return Boolean.toString(truth);
default:
throw new RuntimeError("Unhandled type: "+type);
}
}


public static void main(String[] args) {

Token t1 = new Token(Token.Type.SYM, "foo");
Value v1 = new Value(t1);
System.out.println(t1);
System.out.println(v1);
}
}

--------------030007050405090704000103
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
hangout mailing list
hangout-at-nylxs.com
http://www.nylxs.com/
--------------030007050405090704000103--

  1. 2016-02-01 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] some insight
  2. 2016-02-01 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] getting out of the US
  3. 2016-02-01 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Fwd: [Perlweekly] #236 - Grants,
  4. 2016-02-02 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] [alleyboost1-at-gmail.com: AlleyBoost: Mixer TONIGHT,
  5. 2016-02-04 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] EOF
  6. 2016-02-05 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] the Power of Comic Books!
  7. 2016-02-08 Ruben Safir <ruben.safir-at-my.liu.edu> Subject: [Hangout-NYLXS] Fwd: This is Your LIU Brooklyn - February 8, 2016
  8. 2016-02-08 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] new free software businesses?
  9. 2016-02-09 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] [contact-at-ncfairs.com: Edison Career Fair- February
  10. 2016-02-10 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] [fgreco-at-crossroadstech.com: [wwwac] -at-NYJavaSIG -
  11. 2016-02-11 From: "ballantrae101 ." <ronny.coder-at-gmail.com> Subject: [Hangout-NYLXS] deactivate mailing list
  12. 2016-02-12 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] [jkeen-at-verizon.net: [YAPC::NA Announce] Call for
  13. 2016-02-12 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Advanced Linux Programming essentials
  14. 2016-02-17 Ruben Safir <ruben.safir-at-my.liu.edu> Subject: [Hangout-NYLXS] security with glibc and gethostbyname
  15. 2016-02-17 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Fwd: Register and Meet a Nerdy Dinosaur!
  16. 2016-02-17 Ruben Safir <ruben.safir-at-my.liu.edu> Subject: [Hangout-NYLXS] Fwd: Free presentation: New Ways to Deploy and
  17. 2016-02-18 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] glibc vernability
  18. 2016-02-18 From: "Chris Davis" <contact-at-ncfairs.com> Subject: [Hangout-NYLXS] Edison Career Fair- February 24,
  19. 2016-02-20 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] gcc graghics tools
  20. 2016-02-20 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Tech Learning in Israel
  21. 2016-02-20 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Programming tutorials - massive
  22. 2016-02-20 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Linux Mint security breach
  23. 2016-02-21 Ruben Safir <ruben.safir-at-my.liu.edu> Subject: [Hangout-NYLXS] Jim Henson - eat your heart out
  24. 2016-02-09 ruben safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Fighting bigoted and antisemitic editing on
  25. 2016-02-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] new free software businesses?
  26. 2016-02-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Fwd: Register and Meet a Nerdy Dinosaur!
  27. 2016-02-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] glibc vernability
  28. 2016-02-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] gcc graghics tools
  29. 2016-02-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Tech Learning in Israel
  30. 2016-02-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Programming tutorials - massive
  31. 2016-02-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Linux Mint security breach
  32. 2016-02-21 Rick Moen <rick-at-linuxmafia.com> Re: [Hangout-NYLXS] security with glibc and gethostbyname
  33. 2016-02-21 Rick Moen <rick-at-linuxmafia.com> Re: [Hangout-NYLXS] Linux Mint security breach
  34. 2016-02-21 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] security with glibc and gethostbyname
  35. 2016-02-21 Ruben Safir <ruben.safir-at-my.liu.edu> Re: [Hangout-NYLXS] security with glibc and gethostbyname
  36. 2016-02-21 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] security with glibc and gethostbyname
  37. 2016-02-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Antlr
  38. 2016-02-21 Rick Moen <rick-at-linuxmafia.com> Re: [Hangout-NYLXS] security with glibc and gethostbyname
  39. 2016-02-22 Rick Moen <rick-at-linuxmafia.com> Subject: [Hangout-NYLXS] (forw) [luv-talk] Halt efforts that compel Apple
  40. 2016-02-22 Ruben Safir <ruben.safir-at-my.liu.edu> Subject: [Hangout-NYLXS] 200 dollar ethernet cards
  41. 2016-02-23 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Inflation Rate and the price of an Orange
  42. 2016-02-23 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Time for a Field Trip to Boston
  43. 2016-02-24 ruben safir <ruben.safir-at-my.liu.edu> Subject: [Hangout-NYLXS] cant believe my eyes...
  44. 2016-02-25 eminker-at-gmail.com Re: [Hangout-NYLXS] cant believe my eyes...
  45. 2016-02-26 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] encrypted and signed mail
  46. 2016-02-26 Rick Moen <rick-at-linuxmafia.com> Re: [Hangout-NYLXS] encrypted and signed mail
  47. 2016-02-26 From: "Free Software Foundation" <info-at-fsf.org> Subject: [Hangout-NYLXS] UPDATE: U.S. Copyright Office requiring proprietary
  48. 2016-02-26 Rick Moen <rick-at-linuxmafia.com> Re: [Hangout-NYLXS] UPDATE: U.S. Copyright Office requiring
  49. 2016-02-27 Rick Moen <rick-at-linuxmafia.com> Subject: [Hangout-NYLXS] (forw) Re: UPDATE: U.S. Copyright Office requiring
  50. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] C, C++ and Kernel Programming
  51. 2016-02-28 Asia Suarez <as9795-at-nyu.edu> Re: [Hangout-NYLXS] C, C++ and Kernel Programming
  52. 2016-02-28 Maneesh Kongara <maneeshkongara-at-gmail.com> Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  53. 2016-02-28 Maneesh Kongara <maneeshkongara-at-gmail.com> Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  54. 2016-02-28 Maneesh Kongara <maneeshkongara-at-gmail.com> Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  55. 2016-02-28 as9795-at-nyu.edu Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  56. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] C, C++ and Kernel Programming
  57. 2016-02-28 as9795-at-nyu.edu Re: [Hangout-NYLXS] C, C++ and Kernel Programming
  58. 2016-02-28 Ruben Safir <ruben.safir-at-my.liu.edu> Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  59. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] Signing up for classes.
  60. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] Hi
  61. 2016-02-28 Ruben Safir <ruben.safir-at-my.liu.edu> Re: [Hangout-NYLXS] C, C++ and Kernel Programming
  62. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  63. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] date
  64. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  65. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] little sunshine when your down
  66. 2016-02-28 Trevor Ashley <trevor.ashley-at-my.liu.edu> Re: [Hangout-NYLXS] Networking HW
  67. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] C, C++ and Kernel Programming
  68. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] Networking HW
  69. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  70. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] Networking HW
  71. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] Networking HW
  72. 2016-02-28 Frank Greco <fgreco-at-crossroadstech.com> Subject: [Hangout-NYLXS] [wwwac] [#NYJavaSIG] - Mar 7 - Blockchain for Java
  73. 2016-02-28 James E Keenan <jkeen-at-verizon.net> Subject: [Hangout-NYLXS] NYC Perl 6 Beginners Study Group Session 2: Sat Mar
  74. 2016-02-22 ISOC-NY announcements <announce-at-lists.isoc-ny.org> Subject: [Hangout-NYLXS] [isoc-ny] NYC Don't Break Our Phones Rally -
  75. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] [mailman-at-nylxs.com: Bounce action notification]
  76. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] Networking HW
  77. 2016-02-22 Gabor Szabo <gabor-at-szabgab.com> Subject: [Hangout-NYLXS] [Perlweekly] #239 - Of Tabletop and Desktop Games
  78. 2016-02-28 James E Keenan <jkeen-at-verizon.net> Re: [Hangout-NYLXS] NYC Perl 6 Beginners Study Group Session 2: Sat
  79. 2016-02-28 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  80. 2016-02-28 as9795-at-nyu.edu Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  81. 2016-02-29 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  82. 2016-02-29 as9795-at-nyu.edu Re: [Hangout-NYLXS] [Learn] C++ and C workshop
  83. 2016-02-29 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Hangout-NYLXS] Fwd: Re: [Mailman-Users] speed up mailman
  84. 2016-02-29 Gabor Szabo <gabor-at-szabgab.com> Subject: [Hangout-NYLXS] [Perlweekly] #240 - YAPC is coming!
  85. 2016-02-29 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Change to Tuesday at 7PM C++ and C workshop
  86. 2016-02-29 Gabor Szabo <gabor-at-szabgab.com> Subject: [Hangout-NYLXS] [Perlweekly] #240 - YAPC is coming!
  87. 2016-02-29 From: "soledad.esteban" <soledad.esteban-at-icp.cat> Subject: [Hangout-NYLXS] Course R Without Fear: Applied R for Biologists,
  88. 2016-02-29 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Hangout-NYLXS] Robotics in the popular press
  89. 2016-02-29 Ruben Safir <mrbrklyn-at-panix.com> Re: [Hangout-NYLXS] [Mailman-Users] Config dump? - WAS Re: speed up

NYLXS are Do'ers and the first step of Doing is Joining! Join NYLXS and make a difference in your community today!