/* ChordsParser.java */
/* Generated By:JavaCC: Do not edit this line. ChordsParser.java */
package chords.parser;
import chords.Programa;
import chords.expression.*;
public class ChordsParser implements ChordsParserConstants {
public static void main(String[] args) {
ChordsParser parser = new ChordsParser(System.in);
try {
Programa programa = parser.Input();
if (!programa.isValid()) {
System.out.println("Acorde inv\u00e1lido!");
} else {
programa.executar();
}
} catch (ParseException e) {
System.out.println("Chords Parser Version 0.0.1: Encountered errors during parse.");
}
}
static final public Programa Input() throws ParseException {
trace_call("Input");
try {
Programa retorno;
retorno = PPrograma();
jj_consume_token(0);
{if ("" != null) return retorno;}
throw new Error("Missing return statement in function");
} finally {
trace_return("Input");
}
}
static final public Programa PPrograma() throws ParseException {
trace_call("PPrograma");
try {
Nota retorno;
retorno = PAcorde();
{if ("" != null) return new Programa(retorno);}
throw new Error("Missing return statement in function");
} finally {
trace_return("PPrograma");
}
}
static final public Nota PAcorde() throws ParseException {
trace_call("PAcorde");
try {
Nota nota;
Token token;
nota = PVariacao();
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case SETIMAMAIOR:
case SETIMAMENOR:
case SETIMADIM:{
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case SETIMAMENOR:{
token = jj_consume_token(SETIMAMENOR);
nota = new Exp7Menor(nota, token.toString());
break;
}
case SETIMAMAIOR:{
token = jj_consume_token(SETIMAMAIOR);
nota = new Exp7Maior(nota, token.toString());
break;
}
case SETIMADIM:{
token = jj_consume_token(SETIMADIM);
nota = new Exp7Dim(nota, token.toString());
break;
}
default:
jj_la1[0] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
}
default:
jj_la1[1] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case NTH:{
token = jj_consume_token(NTH);
nota = new ExpNth(nota, token.toString());
break;
}
default:
jj_la1[2] = jj_gen;
;
}
{if ("" != null) return nota;}
throw new Error("Missing return statement in function");
} finally {
trace_return("PAcorde");
}
}
static final public Nota PVariacao() throws ParseException {
trace_call("PVariacao");
try {
Nota nota;
nota = PExpAcidente();
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case MENOR:
case DIM:
case AUMENTADA:{
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case MENOR:{
jj_consume_token(MENOR);
nota = new ExpMenor(nota);
break;
}
case DIM:{
jj_consume_token(DIM);
nota = new ExpDim(nota);
break;
}
case AUMENTADA:{
jj_consume_token(AUMENTADA);
nota = new ExpAumentada(nota);
break;
}
default:
jj_la1[3] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
}
default:
jj_la1[4] = jj_gen;
;
}
{if ("" != null) return nota;}
throw new Error("Missing return statement in function");
} finally {
trace_return("PVariacao");
}
}
static final public Nota PExpAcidente() throws ParseException {
trace_call("PExpAcidente");
try {
Nota nota;
nota = PExpNota();
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case SUSTENIDO:
case BEMOL:{
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case SUSTENIDO:{
jj_consume_token(SUSTENIDO);
nota = new ExpSustenido(nota);
break;
}
case BEMOL:{
jj_consume_token(BEMOL);
nota = new ExpBemol(nota);
break;
}
default:
jj_la1[5] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
}
default:
jj_la1[6] = jj_gen;
;
}
{if ("" != null) return nota;}
throw new Error("Missing return statement in function");
} finally {
trace_return("PExpAcidente");
}
}
static final public Nota PExpNota() throws ParseException {
trace_call("PExpNota");
try {
Token token;
token = jj_consume_token(NOTA);
{if ("" != null) return new ExpNota(token.toString());}
throw new Error("Missing return statement in function");
} finally {
trace_return("PExpNota");
}
}
static private boolean jj_initialized_once = false;
/** Generated Token Manager. */
static public ChordsParserTokenManager token_source;
static SimpleCharStream jj_input_stream;
/** Current token. */
static public Token token;
/** Next token. */
static public Token jj_nt;
static private int jj_ntk;
static private int jj_gen;
static final private int[] jj_la1 = new int[7];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
}
private static void jj_la1_init_0() {
jj_la1_0 = new int[] {0xe000,0xe000,0x200,0x1c00,0x1c00,0x180,0x180,};
}
{
enable_tracing();
}
/** Constructor with InputStream. */
public ChordsParser(java.io.InputStream stream) {
this(stream, null);
}
/** Constructor with InputStream and supplied encoding */
public ChordsParser(java.io.InputStream stream, String encoding) {
if (jj_initialized_once) {
System.out.println("ERROR: Second call to constructor of static parser. ");
System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
}
jj_initialized_once = true;
try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source = new ChordsParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
static public void ReInit(java.io.InputStream stream) {
ReInit(stream, null);
}
/** Reinitialise. */
static public void ReInit(java.io.InputStream stream, String encoding) {
try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Constructor. */
public ChordsParser(java.io.Reader stream) {
if (jj_initialized_once) {
System.out.println("ERROR: Second call to constructor of static parser. ");
System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
}
jj_initialized_once = true;
jj_input_stream = new SimpleCharStream(stream, 1, 1);
token_source = new ChordsParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
static public void ReInit(java.io.Reader stream) {
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
} else {
jj_input_stream.ReInit(stream, 1, 1);
}
if (token_source == null) {
token_source = new ChordsParserTokenManager(jj_input_stream);
}
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Constructor with generated Token Manager. */
public ChordsParser(ChordsParserTokenManager tm) {
if (jj_initialized_once) {
System.out.println("ERROR: Second call to constructor of static parser. ");
System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
}
jj_initialized_once = true;
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
public void ReInit(ChordsParserTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
static private Token jj_consume_token(int kind) throws ParseException {
Token oldToken;
if ((oldToken = token).next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
if (token.kind == kind) {
jj_gen++;
trace_token(token, "");
return token;
}
token = oldToken;
jj_kind = kind;
throw generateParseException();
}
/** Get the next Token. */
static final public Token getNextToken() {
if (token.next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
jj_gen++;
trace_token(token, " (in getNextToken)");
return token;
}
/** Get the specific Token. */
static final public Token getToken(int index) {
Token t = token;
for (int i = 0; i < index; i++) {
if (t.next != null) t = t.next;
else t = t.next = token_source.getNextToken();
}
return t;
}
static private int jj_ntk_f() {
if ((jj_nt=token.next) == null)
return (jj_ntk = (token.next=token_source.getNextToken()).kind);
else
return (jj_ntk = jj_nt.kind);
}
static private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
static private int[] jj_expentry;
static private int jj_kind = -1;
/** Generate ParseException. */
static public ParseException generateParseException() {
jj_expentries.clear();
boolean[] la1tokens = new boolean[16];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 7; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
la1tokens[j] = true;
}
}
}
}
for (int i = 0; i < 16; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
jj_expentries.add(jj_expentry);
}
}
int[][] exptokseq = new int[jj_expentries.size()][];
for (int i = 0; i < jj_expentries.size(); i++) {
exptokseq[i] = jj_expentries.get(i);
}
return new ParseException(token, exptokseq, tokenImage);
}
static private boolean trace_enabled;
/** Trace enabled. */
static final public boolean trace_enabled() {
return trace_enabled;
}
static private int trace_indent = 0;
/** Enable tracing. */
static final public void enable_tracing() {
trace_enabled = true;
}
/** Disable tracing. */
static final public void disable_tracing() {
trace_enabled = false;
}
static protected void trace_call(String s) {
if (trace_enabled) {
for (int i = 0; i < trace_indent; i++) { System.out.print(" "); }
System.out.println("Call: " + s);
}
trace_indent = trace_indent + 2;
}
static protected void trace_return(String s) {
trace_indent = trace_indent - 2;
if (trace_enabled) {
for (int i = 0; i < trace_indent; i++) { System.out.print(" "); }
System.out.println("Return: " + s);
}
}
static protected void trace_token(Token t, String where) {
if (trace_enabled) {
for (int i = 0; i < trace_indent; i++) { System.out.print(" "); }
System.out.print("Consumed token: <" + tokenImage[t.kind]);
if (t.kind != 0 && !tokenImage[t.kind].equals("\"" + t.image + "\"")) {
System.out.print(": \"" + TokenMgrError.addEscapes(t.image) + "\"");
}
System.out.println(" at line " + t.beginLine + " column " + t.beginColumn + ">" + where);
}
}
static protected void trace_scan(Token t1, int t2) {
if (trace_enabled) {
for (int i = 0; i < trace_indent; i++) { System.out.print(" "); }
System.out.print("Visited token: <" + tokenImage[t1.kind]);
if (t1.kind != 0 && !tokenImage[t1.kind].equals("\"" + t1.image + "\"")) {
System.out.print(": \"" + TokenMgrError.addEscapes(t1.image) + "\"");
}
System.out.println(" at line " + t1.beginLine + " column " + t1.beginColumn + ">; Expected token: <" + tokenImage[t2] + ">");
}
}
}
/* ChordsParser.java */
/* Generated By:JavaCC: Do not edit this line. ChordsParser.java */
package chords.parser;
import chords.Programa;
import chords.expression.*;
public class ChordsParser implements ChordsParserConstants {
public static void main(String[] args) {
ChordsParser parser = new ChordsParser(System.in);
try {
Programa programa = parser.Input();
if (!programa.isValid()) {
System.out.println("Acorde inv\u00e1lido!");
} else {
programa.executar();
}
} catch (ParseException e) {
System.out.println("Chords Parser Version 0.0.1: Encountered errors during parse.");
}
}
static final public Programa Input() throws ParseException {
trace_call("Input");
try {
Programa retorno;
retorno = PPrograma();
jj_consume_token(0);
{if ("" != null) return retorno;}
throw new Error("Missing return statement in function");
} finally {
trace_return("Input");
}
}
static final public Programa PPrograma() throws ParseException {
trace_call("PPrograma");
try {
Nota retorno;
retorno = PAcorde();
{if ("" != null) return new Programa(retorno);}
throw new Error("Missing return statement in function");
} finally {
trace_return("PPrograma");
}
}
static final public Nota PAcorde() throws ParseException {
trace_call("PAcorde");
try {
Nota nota;
Token token;
nota = PVariacao();
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case SETIMAMAIOR:
case SETIMAMENOR:
case SETIMADIM:{
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case SETIMAMENOR:{
token = jj_consume_token(SETIMAMENOR);
nota = new Exp7Menor(nota, token.toString());
break;
}
case SETIMAMAIOR:{
token = jj_consume_token(SETIMAMAIOR);
nota = new Exp7Maior(nota, token.toString());
break;
}
case SETIMADIM:{
token = jj_consume_token(SETIMADIM);
nota = new Exp7Dim(nota, token.toString());
break;
}
default:
jj_la1[0] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
}
default:
jj_la1[1] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case NTH:{
token = jj_consume_token(NTH);
nota = new ExpNth(nota, token.toString());
break;
}
default:
jj_la1[2] = jj_gen;
;
}
{if ("" != null) return nota;}
throw new Error("Missing return statement in function");
} finally {
trace_return("PAcorde");
}
}
static final public Nota PVariacao() throws ParseException {
trace_call("PVariacao");
try {
Nota nota;
nota = PExpAcidente();
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case MENOR:
case DIM:
case AUMENTADA:{
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case MENOR:{
jj_consume_token(MENOR);
nota = new ExpMenor(nota);
break;
}
case DIM:{
jj_consume_token(DIM);
nota = new ExpDim(nota);
break;
}
case AUMENTADA:{
jj_consume_token(AUMENTADA);
nota = new ExpAumentada(nota);
break;
}
default:
jj_la1[3] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
}
default:
jj_la1[4] = jj_gen;
;
}
{if ("" != null) return nota;}
throw new Error("Missing return statement in function");
} finally {
trace_return("PVariacao");
}
}
static final public Nota PExpAcidente() throws ParseException {
trace_call("PExpAcidente");
try {
Nota nota;
nota = PExpNota();
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case SUSTENIDO:
case BEMOL:{
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case SUSTENIDO:{
jj_consume_token(SUSTENIDO);
nota = new ExpSustenido(nota);
break;
}
case BEMOL:{
jj_consume_token(BEMOL);
nota = new ExpBemol(nota);
break;
}
default:
jj_la1[5] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
}
default:
jj_la1[6] = jj_gen;
;
}
{if ("" != null) return nota;}
throw new Error("Missing return statement in function");
} finally {
trace_return("PExpAcidente");
}
}
static final public Nota PExpNota() throws ParseException {
trace_call("PExpNota");
try {
Token token;
token = jj_consume_token(NOTA);
{if ("" != null) return new ExpNota(token.toString());}
throw new Error("Missing return statement in function");
} finally {
trace_return("PExpNota");
}
}
static private boolean jj_initialized_once = false;
/** Generated Token Manager. */
static public ChordsParserTokenManager token_source;
static SimpleCharStream jj_input_stream;
/** Current token. */
static public Token token;
/** Next token. */
static public Token jj_nt;
static private int jj_ntk;
static private int jj_gen;
static final private int[] jj_la1 = new int[7];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
}
private static void jj_la1_init_0() {
jj_la1_0 = new int[] {0xe000,0xe000,0x200,0x1c00,0x1c00,0x180,0x180,};
}
{
enable_tracing();
}
/** Constructor with InputStream. */
public ChordsParser(java.io.InputStream stream) {
this(stream, null);
}
/** Constructor with InputStream and supplied encoding */
public ChordsParser(java.io.InputStream stream, String encoding) {
if (jj_initialized_once) {
System.out.println("ERROR: Second call to constructor of static parser. ");
System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
}
jj_initialized_once = true;
try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source = new ChordsParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
static public void ReInit(java.io.InputStream stream) {
ReInit(stream, null);
}
/** Reinitialise. */
static public void ReInit(java.io.InputStream stream, String encoding) {
try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Constructor. */
public ChordsParser(java.io.Reader stream) {
if (jj_initialized_once) {
System.out.println("ERROR: Second call to constructor of static parser. ");
System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
}
jj_initialized_once = true;
jj_input_stream = new SimpleCharStream(stream, 1, 1);
token_source = new ChordsParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
static public void ReInit(java.io.Reader stream) {
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
} else {
jj_input_stream.ReInit(stream, 1, 1);
}
if (token_source == null) {
token_source = new ChordsParserTokenManager(jj_input_stream);
}
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Constructor with generated Token Manager. */
public ChordsParser(ChordsParserTokenManager tm) {
if (jj_initialized_once) {
System.out.println("ERROR: Second call to constructor of static parser. ");
System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
}
jj_initialized_once = true;
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
public void ReInit(ChordsParserTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
static private Token jj_consume_token(int kind) throws ParseException {
Token oldToken;
if ((oldToken = token).next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
if (token.kind == kind) {
jj_gen++;
trace_token(token, "");
return token;
}
token = oldToken;
jj_kind = kind;
throw generateParseException();
}
/** Get the next Token. */
static final public Token getNextToken() {
if (token.next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
jj_gen++;
trace_token(token, " (in getNextToken)");
return token;
}
/** Get the specific Token. */
static final public Token getToken(int index) {
Token t = token;
for (int i = 0; i < index; i++) {
if (t.next != null) t = t.next;
else t = t.next = token_source.getNextToken();
}
return t;
}
static private int jj_ntk_f() {
if ((jj_nt=token.next) == null)
return (jj_ntk = (token.next=token_source.getNextToken()).kind);
else
return (jj_ntk = jj_nt.kind);
}
static private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
static private int[] jj_expentry;
static private int jj_kind = -1;
/** Generate ParseException. */
static public ParseException generateParseException() {
jj_expentries.clear();
boolean[] la1tokens = new boolean[16];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 7; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
la1tokens[j] = true;
}
}
}
}
for (int i = 0; i < 16; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
jj_expentries.add(jj_expentry);
}
}
int[][] exptokseq = new int[jj_expentries.size()][];
for (int i = 0; i < jj_expentries.size(); i++) {
exptokseq[i] = jj_expentries.get(i);
}
return new ParseException(token, exptokseq, tokenImage);
}
static private boolean trace_enabled;
/** Trace enabled. */
static final public boolean trace_enabled() {
return trace_enabled;
}
static private int trace_indent = 0;
/** Enable tracing. */
static final public void enable_tracing() {
trace_enabled = true;
}
/** Disable tracing. */
static final public void disable_tracing() {
trace_enabled = false;
}
static protected void trace_call(String s) {
if (trace_enabled) {
for (int i = 0; i < trace_indent; i++) { System.out.print(" "); }
System.out.println("Call: " + s);
}
trace_indent = trace_indent + 2;
}
static protected void trace_return(String s) {
trace_indent = trace_indent - 2;
if (trace_enabled) {
for (int i = 0; i < trace_indent; i++) { System.out.print(" "); }
System.out.println("Return: " + s);
}
}
static protected void trace_token(Token t, String where) {
if (trace_enabled) {
for (int i = 0; i < trace_indent; i++) { System.out.print(" "); }
System.out.print("Consumed token: <" + tokenImage[t.kind]);
if (t.kind != 0 && !tokenImage[t.kind].equals("\"" + t.image + "\"")) {
System.out.print(": \"" + TokenMgrError.addEscapes(t.image) + "\"");
}
System.out.println(" at line " + t.beginLine + " column " + t.beginColumn + ">" + where);
}
}
static protected void trace_scan(Token t1, int t2) {
if (trace_enabled) {
for (int i = 0; i < trace_indent; i++) { System.out.print(" "); }
System.out.print("Visited token: <" + tokenImage[t1.kind]);
if (t1.kind != 0 && !tokenImage[t1.kind].equals("\"" + t1.image + "\"")) {
System.out.print(": \"" + TokenMgrError.addEscapes(t1.image) + "\"");
}
System.out.println(" at line " + t1.beginLine + " column " + t1.beginColumn + ">; Expected token: <" + tokenImage[t2] + ">");
}
}
}