NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import java.util.Scanner;



class G {
static int sCurrentToken = 0;

static int LEFT_PAREN = 11; // '('
static int RIGHT_PAREN = 12; // ')'
static int INT = 13; // e.g., '123', '+123', '-123'
static int STRING = 14; // "string's (example)." (strings do not extend
// across lines)
static int DOT = 15; // '.'
static int FLOAT = 16; // '123.567', '123.', '.567', '+123.4', '-.123'
static int NIL = 17; // 'nil' or '#f', but not 'NIL' nor 'nIL'
static int T = 18; // 't' or '#t', but not 'T' nor '#T'
static int QUOTE = 19; // '
static int SYMBOL = 20; // a consecutive sequence of printable characters
// that are
// not numbers, and do not contain '(', ')', single-quote,
// double-quote and white-spaces ;
// Symbols are case-sensitive
// (i.e., uppercase and lowercase are different);

static char sCurrentCh = '' ;

} // class G

class Main {

public static void main(String[] args) throws Throwable {
System.out.println("TEST!");
Tokenizer lex = new Tokenizer() ;
lex.run();

}

} // class Main

class Tokenizer {
StringBuffer mTokenString = new StringBuffer() ;
int mToken = 0;

int Get() throws Throwable {
int tok = mToken;
this.run();
return tok;
} // Get()

void GetCh() throws Throwable {

G.sCurrentCh = (char) System.in.read();
} // GetCh()

void run() throws Throwable {
int token = 0;
// Scanner s = new Scanner(System.in);
while (G.sCurrentCh != -1 ) {
ReadSpilt();
token = Recognize();
System.out.println("token:>" + token + " <" );
} // while not eof

System.out.println("over");
} // run()

void ReadSpilt() throws Throwable { // set "mTokenString" to each pattern
// like: ()' whitespace and strs
char inputCh = '';
GetCh() ;
inputCh = G.sCurrentCh ;
if (inputCh == '(' || inputCh == '}' || inputCh == ''') {
mTokenString.append(inputCh);
} // if ()' set mTokenString
else {
while (inputCh != '(' && inputCh != '}' && inputCh != '''
&& inputCh != ' ' && inputCh != -1 && inputCh != 'n' ) {
mTokenString.append(inputCh);
GetCh() ;
inputCh = G.sCurrentCh ;
} // while not delimiter
} // else
} // ReadSpilt()

int Recognize() throws Throwable {
int tokenType = 0;
if (mTokenString.equals("(")) {
tokenType = G.LEFT_PAREN;
} // if
else if (mTokenString.equals(")")) {
tokenType = G.RIGHT_PAREN;
} // else if
else if (isStrInt(mTokenString.toString())) {
tokenType = G.INT;
} // else if
else if (isStrString(mTokenString.toString())) {
tokenType = G.STRING;
} // else if
else if (isDot(mTokenString.toString())) {
tokenType = G.DOT;
} // else if
else if (isStrFloat(mTokenString.toString())) {
tokenType = G.FLOAT;
} // else if
else if (isStrNil(mTokenString.toString())) {
tokenType = G.NIL;
} // else if
else if (isStrT(mTokenString.toString())) {
tokenType = G.T;
} // else if
else if (isStrQuote(mTokenString.toString())) {
tokenType = G.QUOTE;
} // else if
else {
tokenType = G.SYMBOL;
} // else

return tokenType;
} // Recognize()

private boolean isStrQuote(String string) throws Throwable {
if (string.equals("'"))
return true;
return false;
} // isStrQuote(String string)

private boolean isStrT(String string) throws Throwable {
if (string.equals("t") || string.equals("#t"))
return true;
return false;
} // isStrT(String string)

private boolean isStrNil(String string) throws Throwable {
if (string.equals("nil") || string.equals("#f"))
return true;
return false;
} // isStrNil(String string)

private boolean isStrFloat(String string) throws Throwable {
if (Character.isDigit(string.charAt(0))) {
return isStrUnsignFloat(string);
} // if first char is digit
else if (string.charAt(0) == '+' || string.charAt(0) == '-') {
return isStrUnsignFloat(string.substring(1));
} // else if

else
return false;
} // isStrFloat(String string)

private boolean isStrUnsignFloat(String string) throws Throwable {
boolean hasDot = false;
if (Character.isDigit(string.charAt(0))) {
for (int i = 0; i < string.length(); i++) {
if (string.charAt(i) == '.' && hasDot)
return false; // already has '.' but see again
else if (string.charAt(i) == '.')
hasDot = true; // first see '.'
// if encounter '.'
else {
if (!Character.isDigit(string.charAt(i)))
return false;
} // else not '.'
} // for
} // if first is digit

return true;

} // isStrUnsignFloat( String string )

private boolean isDot(String string) throws Throwable {
// TODO Auto-generated method stub
return false;
} // isDot(String string)

private boolean isStrString(String string) throws Throwable {

return false;
} // isStrString(String string)

private boolean isStrInt(String string) throws Throwable {
return false ;
} // isStrInt( String string )

/*
* char ch = GetCh() ; mCurrentTok.append(ch) ;
*/

} // class Tokenizer

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.