[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/ustutt/ncunit/java/avrora/syntax/objdump ObjDumpParserTokenManager.java, NONE, 1.1 ObjDumpParser.jj, NONE, 1.1 Token.java, NONE, 1.1 ObjDumpParser.java, NONE, 1.1 ParseException.java, NONE, 1.1 ObjDumpParserConstants.java, NONE, 1.1 SimpleCharStream.java, NONE, 1.1 TokenMgrError.java, NONE, 1.1

Andreas Lachenmann lachenmann at users.sourceforge.net
Fri May 18 05:22:34 PDT 2007


Update of /cvsroot/tinyos/tinyos-1.x/contrib/ustutt/ncunit/java/avrora/syntax/objdump
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv16729/contrib/ustutt/ncunit/java/avrora/syntax/objdump

Added Files:
	ObjDumpParserTokenManager.java ObjDumpParser.jj Token.java 
	ObjDumpParser.java ParseException.java 
	ObjDumpParserConstants.java SimpleCharStream.java 
	TokenMgrError.java 
Log Message:
integrated some bug fixes for Avrora

--- NEW FILE: ObjDumpParserTokenManager.java ---
/* Generated By:JavaCC: Do not edit this line. ObjDumpParserTokenManager.java */
package avrora.syntax.objdump;
import avrora.*;
import avrora.syntax.*;

public class ObjDumpParserTokenManager implements ObjDumpParserConstants
{
  public  java.io.PrintStream debugStream = System.out;
  public  void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1, long active2)
{
   switch (pos)
   {
      case 0:
         if ((active0 & 0x7fae30000L) != 0L || (active1 & 0xfffffffff8000000L) != 0L || (active2 & 0x1fffffL) != 0L)
         {
            jjmatchedKind = 149;
            return 23;
         }
[...1531 lines suppressed...]
           error_column++;
     }
     if (!EOFSeen) {
        input_stream.backup(1);
        error_after = curPos <= 1 ? "" : input_stream.GetImage();
     }
     throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
   }
  }
}

void SkipLexicalActions(Token matchedToken)
{
   switch(jjmatchedKind)
   {
      default :
         break;
   }
}
}

--- NEW FILE: ObjDumpParser.jj ---
/**
 * Copyright (c) 2004-2005, Regents of the University of California
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * Neither the name of the University of California, Los Angeles nor the
 * names of its contributors may be used to endorse or promote products
 * derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * This is a modified version of AmtelParser.jj. It supports the
 * avr-object dump syntax
 *
 * @author Ben L. Titzer, Vids Samanta
 **/
options {
  LOOKAHEAD = 1;
  CHOICE_AMBIGUITY_CHECK = 2;
  OTHER_AMBIGUITY_CHECK = 1;
  STATIC = false;
  DEBUG_PARSER = false;
  DEBUG_LOOKAHEAD = false;
  DEBUG_TOKEN_MANAGER = false;
  ERROR_REPORTING = true;
  JAVA_UNICODE_ESCAPE = false;
  UNICODE_INPUT = false;
  IGNORE_CASE = true;
  USER_TOKEN_MANAGER = false;
  USER_CHAR_STREAM = false;
  BUILD_PARSER = true;
  BUILD_TOKEN_MANAGER = true;
  SANITY_CHECK = true;
  FORCE_LA_CHECK = false;
}


PARSER_BEGIN(ObjDumpParser)

package avrora.syntax.objdump;

import avrora.*;
import avrora.syntax.*;

public class ObjDumpParser extends AbstractParser  {

    protected RawModule rawModule;

    public ObjDumpParser(java.io.InputStream stream, RawModule m, String fname) {
        this(new FileMarkingTokenManager(new SimpleCharStream(stream, 1, 1), fname));

        module = m;
        rawModule = m;
    }

    public void ReInit(java.io.InputStream stream, RawModule m, String fname) {
        ReInit(new FileMarkingTokenManager(new SimpleCharStream(stream, 1, 1), fname));

        module = m;
        rawModule = m;
    }

    public ObjDumpParser(java.io.Reader stream, RawModule m, String fname) {
        this(new FileMarkingTokenManager(new SimpleCharStream(stream, 1, 1), fname));

        module = m;
        rawModule = m;
    }

    public void ReInit(java.io.Reader stream, RawModule m, String fname) {
        ReInit(new FileMarkingTokenManager(new SimpleCharStream(stream, 1, 1), fname));

        module = m;
        rawModule = m;
    }

}

PARSER_END(ObjDumpParser)

/* WHITE SPACE */

SKIP :
{
  " "
| "\t"
| "\n"
| "\r"
| "\f"
}

/* COMMENTS */

MORE :
{
  ";" : IN_SINGLE_LINE_COMMENT
}

<IN_SINGLE_LINE_COMMENT>
SPECIAL_TOKEN :
{
  <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : DEFAULT
}

<IN_SINGLE_LINE_COMMENT>
MORE :
{
  < ~[] >
}

/* RESERVED WORDS AND LITERALS */

TOKEN :
{
  < INTEGER_LITERAL:
       (<DECIMAL_LITERAL> | <HEX_LITERAL> | <BIN_LITERAL> | <OCTAL_LITERAL> )
  >
|
  < #DECIMAL_LITERAL: (["1"-"9"] (["0"-"9"])*) >
|
  < #HEX_LITERAL: (("0" ["x","X"])|"$") (["0"-"9","a"-"f","A"-"F"])+ >
|
  < #BIN_LITERAL: "0" ["b","B"] (["0", "1"])+ >
|
  < #OCTAL_LITERAL: "0" (["0"-"7"])* >
|
  < CHARACTER_LITERAL:
      "'"
      (   (~["'","\\","\n","\r"])
        | ("\\"
            ( ["n","t","b","r","f","\\","'","\""]
            | ["0"-"7"] ( ["0"-"7"] )?
            | ["0"-"3"] ["0"-"7"] ["0"-"7"]
            )
          )
      )
      "'"
  >
|
  < STRING_LITERAL:
      "\""
      (   (~["\"","\\","\n","\r"])
        | ("\\"
            ( ["n","t","b","r","f","\\","'","\""]
            | ["0"-"7"] ( ["0"-"7"] )?
            | ["0"-"3"] ["0"-"7"] ["0"-"7"]
            )
          )
      )*
      "\""
  >
}

/* Function names */
TOKEN :
{
    < LOW : "low" >
  | < HIGH: "high" >
  | < BYTE2: "byte2" >
  | < BYTE3: "byte3" >
  | < BYTE4: "byte4" >
  | < LWRD: "lwrd" >
  | < HWRD: "hwrd" >
  | < PAGE: "page" >
  | < EXP2: "exp2" >
  | < LOG2: "log2" >
}

/* reserved words */

TOKEN :
{
    < WORD   : ".word"  >
  | < START   : "start"  >
  | < SECTION   : "section"  >
  | < PROGRAM   : "program"  >
  | < LABEL   : "label"  >
  | < SIZE   : "size"  >
  | < VMA   : "vma"  >
  | < LMA   : "lma"  >
  | < OFFSET   : "offset"  >
}

/* Instruction MNEMONICS */

TOKEN :
{
    < ADD    : "add"   >
  | < ADC    : "adc"   >
  | < ADIW   : "adiw"  >
  | < AND    : "and"   >
  | < ANDI   : "andi"  >
  | < ASR    : "asr"   >
  | < BCLR   : "bclr"  >
  | < BLD    : "bld"   >
  | < BRBC   : "brbc"  >
  | < BRBS   : "brbs"  >
  | < BRCC   : "brcc"  >
  | < BRCS   : "brcs"  >
  | < BREAK  : "break" >
  | < BREQ   : "breq"  >
  | < BRGE   : "brge"  >
  | < BRHC   : "brhc"  >
  | < BRHS   : "brhs"  >
  | < BRID   : "brid"  >
  | < BRIE   : "brie"  >
  | < BRLO   : "brlo"  >
  | < BRLT   : "brlt"  >
  | < BRMI   : "brmi"  >
  | < BRNE   : "brne"  >
  | < BRPL   : "brpl"  >
  | < BRSH   : "brsh"  >
  | < BRTC   : "brtc"  >
  | < BRTS   : "brts"  >
  | < BRVC   : "brvc"  >
  | < BRVS   : "brvs"  >
  | < BSET   : "bset"  >
  | < BST    : "bst"   >
  | < CALL   : "call"  >
  | < CBI    : "cbi"   >
  | < CBR    : "cbr"   >
  | < CLC    : "clc"   >
  | < CLH    : "clh"   >
  | < CLI    : "cli"   >
  | < CLN    : "cln"   >
  | < CLR    : "clr"   >
  | < CLS    : "cls"   >
  | < CLT    : "clt"   >
  | < CLV    : "clv"   >
  | < CLZ    : "clz"   >
  | < COM    : "com"   >
  | < CP     : "cp"    >
  | < CPC    : "cpc"   >
  | < CPI    : "cpi"   >
  | < CPSE   : "cpse"  >
  | < DEC    : "dec"   >
  | < EICALL : "eicall" >
  | < EIJMP  : "eijmp"  >
  | < ELPM   : "elpm"  >
  | < EOR    : "eor"   >
  | < FMUL   : "fmul"  >
  | < FMULS  : "fmuls" >
  | < FMULSU : "fmulsu">
  | < ICALL  : "icall" >
  | < IJMP   : "ijmp"  >
  | < IN     : "in"    >
  | < INC    : "inc"   >
  | < JMP    : "jmp"   >
  | < LD     : "ld"    >
  | < LDD    : "ldd"   >
  | < LDI    : "ldi"   >
  | < LDS    : "lds"   >
  | < LPM    : "lpm"   >
  | < LSL    : "lsl"   >
  | < LSR    : "lsr"   >
  | < MOV    : "mov"   >
  | < MOVW   : "movw"  >
  | < MUL    : "mul"   >
  | < MULS   : "muls"  >
  | < MULSU  : "mulsu" >
  | < NEG    : "neg"   >
  | < NOP    : "nop"   >
  | < OR     : "or"    >
  | < ORI    : "ori"   >
  | < OUT    : "out"   >
  | < POP    : "pop"   >
  | < PUSH   : "push"  >
  | < RCALL  : "rcall" >
  | < RET    : "ret"   >
  | < RETI   : "reti"  >
  | < RJMP   : "rjmp"  >
  | < ROL    : "rol"   >
  | < ROR    : "ror"   >
  | < SBC    : "sbc"   >
  | < SBCI   : "sbci"  >
  | < SBI    : "sbi"   >
  | < SBIC   : "sbic"  >
  | < SBIS   : "sbis"  >
  | < SBIW   : "sbiw"  >
  | < SBR    : "sbr"   >
  | < SBRC   : "sbrc"  >
  | < SBRS   : "sbrs"  >
  | < SEC    : "sec"   >
  | < SEH    : "seh"   >
  | < SEI    : "sei"   >
  | < SEN    : "sen"   >
  | < SER    : "ser"   >
  | < SES    : "ses"   >
  | < SET    : "set"   >
  | < SEV    : "sev"   >
  | < SEZ    : "sez"   >
  | < SLEEP  : "sleep" >
  | < SPM    : "spm"   >
  | < ST     : "st"    >
  | < STD    : "std"   >
  | < STS    : "sts"   >
  | < SUB    : "sub"   >
  | < SUBI   : "subi"  >
  | < SWAP   : "swap"  >
  | < TST    : "tst"   >
  | < WDR    : "wdr"   >
}

/* IDENTIFIERS */

TOKEN :
{

  < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
|
  < #LETTER:
      [ "a"-"z", "A"-"Z", "_", "$", "/" ]
  >
|
  < #DIGIT:
      [ "0"-"9" ]
  >
|
  < DOT_IDENTIFIER: "." <IDENTIFIER> >
|
/*  Warning:  "adc" ,  "dec" and  "add"  will not be matched as  <ADDRESS>. */
  < ADDRESS: (["0"-"9","a"-"f","A"-"F"])+ >
}


/* Begin GRAMMAR */

void Module() : {}
{
  Header() (Section())+ <EOF>
}

void Header() : {}
{
    ["program" <STRING_LITERAL> ":"]
    (SectionDecl())+
}

void SectionDecl() : { Token name, vma, lma; }
{
    "section" name = <DOT_IDENTIFIER>
    "size" "=" <INTEGER_LITERAL>
    "vma" "=" vma = <INTEGER_LITERAL>
    "lma" "=" lma = <INTEGER_LITERAL>
    "offset" "=" <INTEGER_LITERAL>
    { rawModule.newSection(name, vma, lma); }
}

void Property() : {}
{
    <IDENTIFIER> "=" <INTEGER_LITERAL>
}

void Section() : { Token sect; }
{
   "start" sect = <DOT_IDENTIFIER> ":"
   { rawModule.enterSection(sect); }
   (Statement())*
}

void Statement() : {}
{
    Label()
  | Item()
}

void Item() : { Token addr; }
{
    addr = <INTEGER_LITERAL> ":"
    { rawModule.setAddress(addr); }
    RawData()
    { rawModule.setAddress(addr); }
    (Instruction() | Data())
}

void RawData() : {}
{
    LOOKAHEAD(3) Raw4() | Raw2()
}

void Raw2() : { Token b1, b2; }
{
    b1 = <INTEGER_LITERAL> b2 = <INTEGER_LITERAL>
    { rawModule.addBytes(b1, b2); }
}

void Raw4() : { Token b1, b2, b3, b4; }
{
    b1 = <INTEGER_LITERAL> b2 = <INTEGER_LITERAL>
    b3 = <INTEGER_LITERAL> b4 = <INTEGER_LITERAL>
    { rawModule.addBytes(b1, b2, b3, b4); }
}

void Instruction() : {}
{
    InstrGPRGPR()
  | InstrGPR()
  | InstrGPRIMM()
  | InstrInput()
  | InstrOutput()
  | InstrIMM()
  | InstrIMMIMM()
  | InstrBARE()
  | InstrLoad()
  | InstrStore()
}

void Data() : { Token b1, b2; }
{
    ".word" <INTEGER_LITERAL>
}

void InstrGPRGPR() : { Token t; SyntacticOperand.Register r1, r2; }
{
    (t = OpcodeGPRGPR() r1 = Register() "," r2 = Register())
    { module.addInstruction(t.image, t, r1, r2); }
}

Token OpcodeGPRGPR() : { Token t; }
{
   (t = "add" | t = "adc"  | t = "sub"   | t = "sbc"  | t = "and"   | t = "or"     | t = "eor"  |
    t = "mul" | t = "muls" | t = "mulsu" | t = "fmul" | t = "fmuls" | t = "fmulsu" | t = "cpse" |
    t = "cp"  | t = "cpc"  | t = "mov"   | t = "movw")
    { return t; }
}

void InstrGPR() : { Token t; SyntacticOperand.Register r1; }
{
    (t = OpcodeGPR() r1 = Register())
    { module.addInstruction(t.image, t, r1); }
}

Token OpcodeGPR() : { Token t; }
{
   (t = "com" | t = "neg" | t = "inc" | t = "dec" | t = "tst" | t = "clr" | t = "ser" | t = "push" |
    t = "pop" | t = "lsl" | t = "lsr" | t = "rol" | t = "ror" | t = "asr" | t = "swap")
    { return t; }
}

void InstrGPRIMM() : { Token t; SyntacticOperand.Register r1; SyntacticOperand.Expr c1; }
{
    (t = OpcodeGPRIMM() r1 = Register() "," c1 = Const())
    { module.addInstruction(t.image, t, r1, c1); }
}

Token OpcodeGPRIMM() : { Token t; }
{
   (t = "adiw" | t = "subi" | t = "sbci" | t = "sbiw" | t = "andi" | t = "ori" | t = "sbr" |
    t = "cbr"  | t = "cpi"  | t = "sbrc" | t = "sbrs" | t = "bst"  | t = "bld")
    { return t; }
}

void InstrIMM() : { Token t; SyntacticOperand.Expr c1; }
{
    (t = OpcodeIMM() c1 = Const())
    { module.addInstruction(t.image, t, c1); }
}

Token OpcodeIMM() : { Token t; }
{
   (t = "rjmp" | t = "jmp"  | t = "rcall" | t = "call" | t = "breq" | t = "brne" | t = "brcs" |
    t = "brcc" | t = "brsh" | t = "brlo"  | t = "brmi" | t = "brpl" | t = "brge" | t = "brlt" |
    t = "brhs" | t = "brhc" | t = "brts"  | t = "brtc" | t = "brvs" | t = "brvc" | t = "brie" |
    t = "brid" | t = "bset" | t = "bclr")
    { return t; }
}

void InstrIMMIMM() : { Token t; SyntacticOperand.Expr c1, c2; }
{
    (t = OpcodeIMMIMM() c1 = Const() "," c2 = Const())
    { module.addInstruction(t.image, t, c1, c2); }
}

Token OpcodeIMMIMM() : { Token t; }
{
    ( t = "sbic" | t = "sbis" | t = "brbs" | t = "brbc" | t = "sbi" | t = "cbi")
    { return t; }
}

void InstrLoad() : {}
{
    InstrLDI() |
    InstrLD_variant() |
    InstrLDD() |
    InstrLDS() |
    InstrLPM_variant()
}

void InstrLDI() : { Token t; SyntacticOperand.Register r1; SyntacticOperand.Expr c1; }
{
    (t = "ldi" r1 = Register() "," c1 = Const())
    { module.addInstruction(t.image, t, r1, c1); }
}

void InstrLD_variant() : { }
{
    LOOKAHEAD(5) InstrLDPI()
  | LOOKAHEAD(4) InstrLDPD()
  | InstrLD()

}

void InstrLD() : { Token t; SyntacticOperand.Register r1, r2; }
{
    (t = "ld" r1 = Register() "," r2 = Register())
    { module.addInstruction("ld", t, r1, r2); }
}

void InstrLDPI() : { Token t; SyntacticOperand.Register r1, r2; }
{
    (t = "ld" r1 = Register() "," r2 = Register() "+")
    { module.addInstruction("ldpi", t, r1, r2); }
}

void InstrLDPD() : { Token t; SyntacticOperand.Register r1, r2; }
{
    (t = "ld" r1 = Register() "," "-" r2 = Register())
    { module.addInstruction("ldpd", t, r1, r2); }
}

void InstrLDD() : { Token t; SyntacticOperand.Register r1, r2; SyntacticOperand.Expr c1; }
{
    (t = "ldd" r1 = Register() "," r2 = Register() "+" c1 = Const())
    { module.addInstruction(t.image, t, r1, r2, c1); }
}

void InstrLDS() : { Token t; SyntacticOperand.Register r1; SyntacticOperand.Expr c1; }
{
    (t = "lds" r1 = Register() "," c1 = Const())
    { module.addInstruction(t.image, t, r1, c1); }
}

void InstrLPM_variant() : {}
{

    LOOKAHEAD(5) InstrLPMGPRGPRP()
  | LOOKAHEAD(3) InstrLPMGPRGPR()
  | InstrLPMBARE()
}

void InstrLPMGPRGPR() : { Token t; SyntacticOperand.Register r1, r2; }
{
    (t = OpcodeLPM() r1 = Register() "," r2 = Register())
    { module.addInstruction(t.image+"d", t, r1, r2); }
}

void InstrLPMGPRGPRP() : { Token t; SyntacticOperand.Register r1, r2; }
{
    (t = OpcodeLPM() r1 = Register() "," r2 = Register() "+")
    { module.addInstruction(t.image+"pi", t, r1, r2); }
}

void InstrLPMBARE() : { Token t; }
{
    t = OpcodeLPM() { module.addInstruction(t.image, t); }
}

Token OpcodeLPM() : { Token t; }
{
    (t = "lpm" | t = "elpm") { return t; }
}

void InstrStore() : {}
{
    InstrST_variant() |
    InstrSTD() |
    InstrSTS()
}

void InstrST_variant() : { }
{
    LOOKAHEAD(3) InstrST()
  | LOOKAHEAD(3) InstrSTPI()
  | InstrSTPD()
}

void InstrST() : { Token t; SyntacticOperand.Register r1, r2; }
{
    (t = "st" r1 = Register() "," r2 = Register())
    { module.addInstruction("st", t, r1, r2); }
}

void InstrSTPI() : { Token t; SyntacticOperand.Register r1, r2; }
{
    (t = "st" r1 = Register() "+" "," r2 = Register())
    { module.addInstruction("stpi", t, r1, r2); }
}

void InstrSTPD() : { Token t; SyntacticOperand.Register r1, r2; }
{
    (t = "st" "-" r1 = Register() "," r2 = Register())
    { module.addInstruction("stpd", t, r1, r2); }
}

void InstrSTD() : { Token t; SyntacticOperand.Register r1, r2; SyntacticOperand.Expr c1; }
{
    (t = "std" r1 = Register() "+" c1 = Const() "," r2 = Register())
    { module.addInstruction(t.image, t, r1, c1, r2); }
}

void InstrSTS() : { Token t; SyntacticOperand.Register r1; SyntacticOperand.Expr c1; }
{
    (t = "sts" c1 = Const() "," r1 = Register())
    { module.addInstruction(t.image, t, c1, r1); }
}

void InstrBARE() : { Token t; }
{
   (t = "ijmp"  | t = "icall" | t = "ret"   | t = "reti" | t = "sec" | t = "clc" | t = "sen" |
    t = "cln"   | t = "sez"   | t = "clz"   | t = "sei"  | t = "cli" | t = "ses" | t = "cls" |
    t = "sev"   | t = "clv"   | t = "set"   | t = "clt"  | t = "seh" | t = "clh" | t = "nop" |
    t = "sleep" | t = "wdr"   | t = "break" | t = "spm"  | t = "eijmp"  | t = "eicall")
    { module.addInstruction(t.image, t); }
}

void InstrInput() : { Token t; SyntacticOperand.Register r1; SyntacticOperand.Expr c1; }
{
    (t = "in" r1 = Register() "," c1 = Const())
    { module.addInstruction(t.image, t, r1, c1); }
}

void InstrOutput() : { Token t; SyntacticOperand.Register r1; SyntacticOperand.Expr c1; }
{
    t = "out" c1 = Const() "," r1 = Register()
    { module.addInstruction(t.image, t, c1, r1); }
}

SyntacticOperand.Register Register() : { Token tok; }
{
    tok = <IDENTIFIER>
    { return module.newOperand(tok); }
}

void Label() : { Token addr, tok; }
{
    "label" addr = <INTEGER_LITERAL> tok = <STRING_LITERAL> ":"
    { rawModule.setAddress(addr);
      module.addQuotedLabel(tok); }
}

SyntacticOperand.Expr Const() : { Expr e; }
{
  (LOOKAHEAD(".") e = RelExpr() | e = Term() )
  { return module.newOperand(e); }
}

Expr Term() : { Token tok; Expr e; }
{
  (
    tok = <IDENTIFIER> { e = new Expr.Variable(tok); }
  | tok = <INTEGER_LITERAL> { e = new Expr.Constant(tok); }
  )

  { return e; }
}

Expr RelExpr() : { Token ltok; Token op; Token rtok; }
{
 (ltok = "." op = BinOp() rtok = <INTEGER_LITERAL>)
 { return new Expr.RelativeAddress(ltok, op, rtok); }
}

Token BinOp() : { Token tok; }
{
 (tok = "+" | tok = "-")
 { return tok; }
}

--- NEW FILE: Token.java ---
/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */
/**
 * Copyright (c) 2004-2005, Regents of the University of California
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * Neither the name of the University of California, Los Angeles nor the
 * names of its contributors may be used to endorse or promote products
 * derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package avrora.syntax.objdump;

import avrora.syntax.AbstractToken;

/**
 * Describes the input token stream.
 */

public class Token extends AbstractToken {

    /**
     * An integer that describes the kind of this token.  This numbering system is determined by JavaCCParser,
     * and a table of these numbers is stored in the file ...Constants.java.
     */
    public int kind;


    /**
     * A reference to the next regular (non-special) token from the input stream.  If this is the last token
     * from the input stream, or if the token manager has not read tokens beyond this one, this field is set
     * to null.  This is true only if this token is also a regular token.  Otherwise, see below for a
     * description of the contents of this field.
     */
    public Token next;

    /**
     * This field is used to access special tokens that occur prior to this token, but after the immediately
     * preceding regular (non-special) token. If there are no such special tokens, this field is set to null.
     * When there are more than one such special token, this field refers to the last of these special tokens,
     * which in turn refers to the next previous special token through its specialToken field, and so on until
     * the first special token (whose specialToken field is null). The next fields of special tokens refer to
     * other special tokens that immediately follow it (without an intervening regular token).  If there is no
     * such token, this field is null.
     */
    public Token specialToken;

    /**
     * Returns the image.
     */
    public String toString() {
        return image;
    }

    /**
     * Returns a new Token object, by default. However, if you want, you can create and return subclass
     * objects based on the value of ofKind. Simply add the cases to the switch for all those special cases.
     * For example, if you have a subclass of Token called IDToken that you want to create if ofKind is ID,
     * simlpy add something like :
     * <p/>
     * case MyParserConstants.ID : return new IDToken();
     * <p/>
     * to the following switch statement. Then you can cast matchedToken variable to the appropriate type and
     * use it in your lexical actions.
     */
    public static final Token newToken(int ofKind) {
        switch (ofKind) {
            default :
                return new Token();
        }
    }

    public AbstractToken getNextToken() {
        return next;
    }
}

--- NEW FILE: ObjDumpParser.java ---
/* Generated By:JavaCC: Do not edit this line. ObjDumpParser.java */
package avrora.syntax.objdump;

import avrora.*;
import avrora.syntax.*;

public class ObjDumpParser extends AbstractParser implements ObjDumpParserConstants {

    protected RawModule rawModule;

    public ObjDumpParser(java.io.InputStream stream, RawModule m, String fname) {
        this(new FileMarkingTokenManager(new SimpleCharStream(stream, 1, 1), fname));

        module = m;
        rawModule = m;
    }

    public void ReInit(java.io.InputStream stream, RawModule m, String fname) {
        ReInit(new FileMarkingTokenManager(new SimpleCharStream(stream, 1, 1), fname));
[...1661 lines suppressed...]
    jj_rescan = false;
  }

  final private void jj_save(int index, int xla) {
    JJCalls p = jj_2_rtns[index];
    while (p.gen > jj_gen) {
      if (p.next == null) { p = p.next = new JJCalls(); break; }
      p = p.next;
    }
    p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
  }

  static final class JJCalls {
    int gen;
    Token first;
    int arg;
    JJCalls next;
  }

}

--- NEW FILE: ParseException.java ---
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
package avrora.syntax.objdump;

import avrora.syntax.AbstractParseException;

/**
 * This exception is thrown when parse errors are encountered. You can explicitly create objects of this
 * exception type by calling the method generateParseException in the generated parser.
 * <p/>
 * You can modify this class to customize your error reporting mechanisms so long as you retain the public
 * fields.
 */
public class ParseException extends AbstractParseException {

    /**
     * This constructor is used by the method "generateParseException" in the generated parser.  Calling this
     * constructor generates a new object of this type with the fields "currentToken",
     * "expectedTokenSequences", and "tokenImage" set.  The boolean flag "specialConstructor" is also set to
     * true to indicate that this constructor was used to create this object. This constructor calls its super
     * class with the empty string to force the "toString" method of parent class "Throwable" to print the
     * error message in the form: ParseException: <result of getMessage>
     */
    public ParseException(Token currentTokenVal,
                          int[][] expectedTokenSequencesVal,
                          String[] tokenImageVal) {
        super("");
        specialConstructor = true;
        currentToken = currentTokenVal;
        expectedTokenSequences = expectedTokenSequencesVal;
        tokenImage = tokenImageVal;
    }

    /**
     * The following constructors are for use by you for whatever purpose you can think of.  Constructing the
     * exception in this manner makes the exception behave in the normal way - i.e., as documented in the
     * class "Throwable".  The fields "errorToken", "expectedTokenSequences", and "tokenImage" do not contain
     * relevant information.  The JavaCC generated code does not use these constructors.
     */

    public ParseException() {
        super();
        specialConstructor = false;
    }

    public ParseException(String message) {
        super(message);
        specialConstructor = false;
    }


    /**
     * This method has the standard behavior when this object has been created using the standard
     * constructors. Otherwise, it uses "currentToken" and "expectedTokenSequences" to generate a parse error
     * message and returns it. If this object has been created due to a parse error, and you do not catch it
     * (it gets thrown from the parser), then this method is called during the printing of the final stack
     * trace, and hence the correct error message gets displayed.
     */
    public String getMessage() {
        if (!specialConstructor) {
            return super.getMessage();
        }
        String expected = "";
        int maxSize = 0;
        for (int i = 0; i < expectedTokenSequences.length; i++) {
            if (maxSize < expectedTokenSequences[i].length) {
                maxSize = expectedTokenSequences[i].length;
            }
            for (int j = 0; j < expectedTokenSequences[i].length; j++) {
                expected += tokenImage[expectedTokenSequences[i][j]] + ' ';
            }
            if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
                expected += "...";
            }
            expected += eol + "    ";
        }
        String retval = "Encountered \"";
        Token tok = ((Token)currentToken).next;
        Token next = tok;
        for (int i = 0; i < maxSize; i++) {
            if (i != 0) retval += " ";
            if (tok.kind == 0) {
                retval += tokenImage[0];
                break;
            }
            retval += add_escapes(tok.image);
            tok = tok.next;
        }
        retval += "\" at line " + next.beginLine + ", column " + next.beginColumn;
        retval += '.' + eol;
        if (expectedTokenSequences.length == 1) {
            retval += "Was expecting:" + eol + "    ";
        } else {
            retval += "Was expecting one of:" + eol + "    ";
        }
        retval += expected;
        return retval;
    }

    /**
     * Used to convert raw characters to their escaped version when these raw version cannot be used as part
     * of an ASCII string literal.
     */
    protected String add_escapes(String str) {
        StringBuffer retval = new StringBuffer();
        char ch;
        for (int i = 0; i < str.length(); i++) {
            switch (str.charAt(i)) {
                case 0:
                    continue;
                case '\b':
                    retval.append("\\b");
                    continue;
                case '\t':
                    retval.append("\\t");
                    continue;
                case '\n':
                    retval.append("\\n");
                    continue;
                case '\f':
                    retval.append("\\f");
                    continue;
                case '\r':
                    retval.append("\\r");
                    continue;
                case '\"':
                    retval.append("\\\"");
                    continue;
                case '\'':
                    retval.append("\\\'");
                    continue;
                case '\\':
                    retval.append("\\\\");
                    continue;
                default:
                    if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
                        String s = "0000" + Integer.toString(ch, 16);
                        retval.append("\\u" + s.substring(s.length() - 4, s.length()));
                    } else {
                        retval.append(ch);
                    }
                    continue;
            }
        }
        return retval.toString();
    }

}

--- NEW FILE: ObjDumpParserConstants.java ---
/* Generated By:JavaCC: Do not edit this line. ObjDumpParserConstants.java */
package avrora.syntax.objdump;

public interface ObjDumpParserConstants {

  int EOF = 0;
  int SINGLE_LINE_COMMENT = 7;
  int INTEGER_LITERAL = 9;
  int DECIMAL_LITERAL = 10;
  int HEX_LITERAL = 11;
  int BIN_LITERAL = 12;
  int OCTAL_LITERAL = 13;
  int CHARACTER_LITERAL = 14;
  int STRING_LITERAL = 15;
  int LOW = 16;
  int HIGH = 17;
  int BYTE2 = 18;
  int BYTE3 = 19;
  int BYTE4 = 20;
  int LWRD = 21;
  int HWRD = 22;
  int PAGE = 23;
  int EXP2 = 24;
  int LOG2 = 25;
  int WORD = 26;
  int START = 27;
  int SECTION = 28;
  int PROGRAM = 29;
  int LABEL = 30;
  int SIZE = 31;
  int VMA = 32;
  int LMA = 33;
  int OFFSET = 34;
  int ADD = 35;
  int ADC = 36;
  int ADIW = 37;
  int AND = 38;
  int ANDI = 39;
  int ASR = 40;
  int BCLR = 41;
  int BLD = 42;
  int BRBC = 43;
  int BRBS = 44;
  int BRCC = 45;
  int BRCS = 46;
  int BREAK = 47;
  int BREQ = 48;
  int BRGE = 49;
  int BRHC = 50;
  int BRHS = 51;
  int BRID = 52;
  int BRIE = 53;
  int BRLO = 54;
  int BRLT = 55;
  int BRMI = 56;
  int BRNE = 57;
  int BRPL = 58;
  int BRSH = 59;
  int BRTC = 60;
  int BRTS = 61;
  int BRVC = 62;
  int BRVS = 63;
  int BSET = 64;
  int BST = 65;
  int CALL = 66;
  int CBI = 67;
  int CBR = 68;
  int CLC = 69;
  int CLH = 70;
  int CLI = 71;
  int CLN = 72;
  int CLR = 73;
  int CLS = 74;
  int CLT = 75;
  int CLV = 76;
  int CLZ = 77;
  int COM = 78;
  int CP = 79;
  int CPC = 80;
  int CPI = 81;
  int CPSE = 82;
  int DEC = 83;
  int EICALL = 84;
  int EIJMP = 85;
  int ELPM = 86;
  int EOR = 87;
  int FMUL = 88;
  int FMULS = 89;
  int FMULSU = 90;
  int ICALL = 91;
  int IJMP = 92;
  int IN = 93;
  int INC = 94;
  int JMP = 95;
  int LD = 96;
  int LDD = 97;
  int LDI = 98;
  int LDS = 99;
  int LPM = 100;
  int LSL = 101;
  int LSR = 102;
  int MOV = 103;
  int MOVW = 104;
  int MUL = 105;
  int MULS = 106;
  int MULSU = 107;
  int NEG = 108;
  int NOP = 109;
  int OR = 110;
  int ORI = 111;
  int OUT = 112;
  int POP = 113;
  int PUSH = 114;
  int RCALL = 115;
  int RET = 116;
  int RETI = 117;
  int RJMP = 118;
  int ROL = 119;
  int ROR = 120;
  int SBC = 121;
  int SBCI = 122;
  int SBI = 123;
  int SBIC = 124;
  int SBIS = 125;
  int SBIW = 126;
  int SBR = 127;
  int SBRC = 128;
  int SBRS = 129;
  int SEC = 130;
  int SEH = 131;
  int SEI = 132;
  int SEN = 133;
  int SER = 134;
  int SES = 135;
  int SET = 136;
  int SEV = 137;
  int SEZ = 138;
  int SLEEP = 139;
  int SPM = 140;
  int ST = 141;
  int STD = 142;
  int STS = 143;
  int SUB = 144;
  int SUBI = 145;
  int SWAP = 146;
  int TST = 147;
  int WDR = 148;
  int IDENTIFIER = 149;
  int LETTER = 150;
  int DIGIT = 151;
  int DOT_IDENTIFIER = 152;
  int ADDRESS = 153;

  int DEFAULT = 0;
  int IN_SINGLE_LINE_COMMENT = 1;

  String[] tokenImage = {
    "<EOF>",
    "\" \"",
    "\"\\t\"",
    "\"\\n\"",
    "\"\\r\"",
    "\"\\f\"",
    "\";\"",
    "<SINGLE_LINE_COMMENT>",
    "<token of kind 8>",
    "<INTEGER_LITERAL>",
    "<DECIMAL_LITERAL>",
    "<HEX_LITERAL>",
    "<BIN_LITERAL>",
    "<OCTAL_LITERAL>",
    "<CHARACTER_LITERAL>",
    "<STRING_LITERAL>",
    "\"low\"",
    "\"high\"",
    "\"byte2\"",
    "\"byte3\"",
    "\"byte4\"",
    "\"lwrd\"",
    "\"hwrd\"",
    "\"page\"",
    "\"exp2\"",
    "\"log2\"",
    "\".word\"",
    "\"start\"",
    "\"section\"",
    "\"program\"",
    "\"label\"",
    "\"size\"",
    "\"vma\"",
    "\"lma\"",
    "\"offset\"",
    "\"add\"",
    "\"adc\"",
    "\"adiw\"",
    "\"and\"",
    "\"andi\"",
    "\"asr\"",
    "\"bclr\"",
    "\"bld\"",
    "\"brbc\"",
    "\"brbs\"",
    "\"brcc\"",
    "\"brcs\"",
    "\"break\"",
    "\"breq\"",
    "\"brge\"",
    "\"brhc\"",
    "\"brhs\"",
    "\"brid\"",
    "\"brie\"",
    "\"brlo\"",
    "\"brlt\"",
    "\"brmi\"",
    "\"brne\"",
    "\"brpl\"",
    "\"brsh\"",
    "\"brtc\"",
    "\"brts\"",
    "\"brvc\"",
    "\"brvs\"",
    "\"bset\"",
    "\"bst\"",
    "\"call\"",
    "\"cbi\"",
    "\"cbr\"",
    "\"clc\"",
    "\"clh\"",
    "\"cli\"",
    "\"cln\"",
    "\"clr\"",
    "\"cls\"",
    "\"clt\"",
    "\"clv\"",
    "\"clz\"",
    "\"com\"",
    "\"cp\"",
    "\"cpc\"",
    "\"cpi\"",
    "\"cpse\"",
    "\"dec\"",
    "\"eicall\"",
    "\"eijmp\"",
    "\"elpm\"",
    "\"eor\"",
    "\"fmul\"",
    "\"fmuls\"",
    "\"fmulsu\"",
    "\"icall\"",
    "\"ijmp\"",
    "\"in\"",
    "\"inc\"",
    "\"jmp\"",
    "\"ld\"",
    "\"ldd\"",
    "\"ldi\"",
    "\"lds\"",
    "\"lpm\"",
    "\"lsl\"",
    "\"lsr\"",
    "\"mov\"",
    "\"movw\"",
    "\"mul\"",
    "\"muls\"",
    "\"mulsu\"",
    "\"neg\"",
    "\"nop\"",
    "\"or\"",
    "\"ori\"",
    "\"out\"",
    "\"pop\"",
    "\"push\"",
    "\"rcall\"",
    "\"ret\"",
    "\"reti\"",
    "\"rjmp\"",
    "\"rol\"",
    "\"ror\"",
    "\"sbc\"",
    "\"sbci\"",
    "\"sbi\"",
    "\"sbic\"",
    "\"sbis\"",
    "\"sbiw\"",
    "\"sbr\"",
    "\"sbrc\"",
    "\"sbrs\"",
    "\"sec\"",
    "\"seh\"",
    "\"sei\"",
    "\"sen\"",
    "\"ser\"",
    "\"ses\"",
    "\"set\"",
    "\"sev\"",
    "\"sez\"",
    "\"sleep\"",
    "\"spm\"",
    "\"st\"",
    "\"std\"",
    "\"sts\"",
    "\"sub\"",
    "\"subi\"",
    "\"swap\"",
    "\"tst\"",
    "\"wdr\"",
    "<IDENTIFIER>",
    "<LETTER>",
    "<DIGIT>",
    "<DOT_IDENTIFIER>",
    "<ADDRESS>",
    "\":\"",
    "\"=\"",
    "\",\"",
    "\"+\"",
    "\"-\"",
    "\".\"",
  };

}

--- NEW FILE: SimpleCharStream.java ---
/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */
package avrora.syntax.objdump;

/**
 * An implementation of interface CharStream, where the stream is assumed to
 * contain only ASCII characters (without unicode processing).
 */

public class SimpleCharStream
{
  public static final boolean staticFlag = false;
  int bufsize;
  int available;
  int tokenBegin;
  public int bufpos = -1;
  protected int bufline[];
  protected int bufcolumn[];

  protected int column = 0;
  protected int line = 1;

  protected boolean prevCharIsCR = false;
  protected boolean prevCharIsLF = false;

  protected java.io.Reader inputStream;

  protected char[] buffer;
  protected int maxNextCharInd = 0;
  protected int inBuf = 0;
  protected int tabSize = 8;

  protected void setTabSize(int i) { tabSize = i; }
  protected int getTabSize(int i) { return tabSize; }


  protected void ExpandBuff(boolean wrapAround)
  {
     char[] newbuffer = new char[bufsize + 2048];
     int newbufline[] = new int[bufsize + 2048];
     int newbufcolumn[] = new int[bufsize + 2048];

     try
     {
        if (wrapAround)
        {
           System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
           System.arraycopy(buffer, 0, newbuffer,
                                             bufsize - tokenBegin, bufpos);
           buffer = newbuffer;

           System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
           System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
           bufline = newbufline;

           System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
           System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
           bufcolumn = newbufcolumn;

           maxNextCharInd = (bufpos += (bufsize - tokenBegin));
        }
        else
        {
           System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
           buffer = newbuffer;

           System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
           bufline = newbufline;

           System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
           bufcolumn = newbufcolumn;

           maxNextCharInd = (bufpos -= tokenBegin);
        }
     }
     catch (Throwable t)
     {
        throw new Error(t.getMessage());
     }


     bufsize += 2048;
     available = bufsize;
     tokenBegin = 0;
  }

  protected void FillBuff() throws java.io.IOException
  {
     if (maxNextCharInd == available)
     {
        if (available == bufsize)
        {
           if (tokenBegin > 2048)
           {
              bufpos = maxNextCharInd = 0;
              available = tokenBegin;
           }
           else if (tokenBegin < 0)
              bufpos = maxNextCharInd = 0;
           else
              ExpandBuff(false);
        }
        else if (available > tokenBegin)
           available = bufsize;
        else if ((tokenBegin - available) < 2048)
           ExpandBuff(true);
        else
           available = tokenBegin;
     }

     int i;
     try {
        if ((i = inputStream.read(buffer, maxNextCharInd,
                                    available - maxNextCharInd)) == -1)
        {
           inputStream.close();
           throw new java.io.IOException();
        }
        else
           maxNextCharInd += i;
        return;
     }
     catch(java.io.IOException e) {
        --bufpos;
        backup(0);
        if (tokenBegin == -1)
           tokenBegin = bufpos;
        throw e;
     }
  }

  public char BeginToken() throws java.io.IOException
  {
     tokenBegin = -1;
     char c = readChar();
     tokenBegin = bufpos;

     return c;
  }

  protected void UpdateLineColumn(char c)
  {
     column++;

     if (prevCharIsLF)
     {
        prevCharIsLF = false;
        line += (column = 1);
     }
     else if (prevCharIsCR)
     {
        prevCharIsCR = false;
        if (c == '\n')
        {
           prevCharIsLF = true;
        }
        else
           line += (column = 1);
     }

     switch (c)
     {
        case '\r' :
           prevCharIsCR = true;
           break;
        case '\n' :
           prevCharIsLF = true;
           break;
        case '\t' :
           column--;
           column += (tabSize - (column % tabSize));
           break;
        default :
           break;
     }

     bufline[bufpos] = line;
     bufcolumn[bufpos] = column;
  }

  public char readChar() throws java.io.IOException
  {
     if (inBuf > 0)
     {
        --inBuf;

        if (++bufpos == bufsize)
           bufpos = 0;

        return buffer[bufpos];
     }

     if (++bufpos >= maxNextCharInd)
        FillBuff();

     char c = buffer[bufpos];

     UpdateLineColumn(c);
     return (c);
  }

  /**
   * @deprecated 
   * @see #getEndColumn
   */

  public int getColumn() {
     return bufcolumn[bufpos];
  }

  /**
   * @deprecated 
   * @see #getEndLine
   */

  public int getLine() {
     return bufline[bufpos];
  }

  public int getEndColumn() {
     return bufcolumn[bufpos];
  }

  public int getEndLine() {
     return bufline[bufpos];
  }

  public int getBeginColumn() {
     return bufcolumn[tokenBegin];
  }

  public int getBeginLine() {
     return bufline[tokenBegin];
  }

  public void backup(int amount) {

    inBuf += amount;
    if ((bufpos -= amount) < 0)
       bufpos += bufsize;
  }

  public SimpleCharStream(java.io.Reader dstream, int startline,
  int startcolumn, int buffersize)
  {
    inputStream = dstream;
    line = startline;
    column = startcolumn - 1;

    available = bufsize = buffersize;
    buffer = new char[buffersize];
    bufline = new int[buffersize];
    bufcolumn = new int[buffersize];
  }

  public SimpleCharStream(java.io.Reader dstream, int startline,
                          int startcolumn)
  {
     this(dstream, startline, startcolumn, 4096);
  }

  public SimpleCharStream(java.io.Reader dstream)
  {
     this(dstream, 1, 1, 4096);
  }
  public void ReInit(java.io.Reader dstream, int startline,
  int startcolumn, int buffersize)
  {
    inputStream = dstream;
    line = startline;
    column = startcolumn - 1;

    if (buffer == null || buffersize != buffer.length)
    {
      available = bufsize = buffersize;
      buffer = new char[buffersize];
      bufline = new int[buffersize];
      bufcolumn = new int[buffersize];
    }
    prevCharIsLF = prevCharIsCR = false;
    tokenBegin = inBuf = maxNextCharInd = 0;
    bufpos = -1;
  }

  public void ReInit(java.io.Reader dstream, int startline,
                     int startcolumn)
  {
     ReInit(dstream, startline, startcolumn, 4096);
  }

  public void ReInit(java.io.Reader dstream)
  {
     ReInit(dstream, 1, 1, 4096);
  }
  public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
  int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
  {
     this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
  }

  public SimpleCharStream(java.io.InputStream dstream, int startline,
  int startcolumn, int buffersize)
  {
     this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
  }

  public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
                          int startcolumn) throws java.io.UnsupportedEncodingException
  {
     this(dstream, encoding, startline, startcolumn, 4096);
  }

  public SimpleCharStream(java.io.InputStream dstream, int startline,
                          int startcolumn)
  {
     this(dstream, startline, startcolumn, 4096);
  }

  public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
  {
     this(dstream, encoding, 1, 1, 4096);
  }

  public SimpleCharStream(java.io.InputStream dstream)
  {
     this(dstream, 1, 1, 4096);
  }

  public void ReInit(java.io.InputStream dstream, String encoding, int startline,
                          int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
  {
     ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
  }

  public void ReInit(java.io.InputStream dstream, int startline,
                          int startcolumn, int buffersize)
  {
     ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
  }

  public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
  {
     ReInit(dstream, encoding, 1, 1, 4096);
  }

  public void ReInit(java.io.InputStream dstream)
  {
     ReInit(dstream, 1, 1, 4096);
  }
  public void ReInit(java.io.InputStream dstream, String encoding, int startline,
                     int startcolumn) throws java.io.UnsupportedEncodingException
  {
     ReInit(dstream, encoding, startline, startcolumn, 4096);
  }
  public void ReInit(java.io.InputStream dstream, int startline,
                     int startcolumn)
  {
     ReInit(dstream, startline, startcolumn, 4096);
  }
  public String GetImage()
  {
     if (bufpos >= tokenBegin)
        return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
     else
        return new String(buffer, tokenBegin, bufsize - tokenBegin) +
                              new String(buffer, 0, bufpos + 1);
  }

  public char[] GetSuffix(int len)
  {
     char[] ret = new char[len];

     if ((bufpos + 1) >= len)
        System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
     else
     {
        System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
                                                          len - bufpos - 1);
        System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
     }

     return ret;
  }

  public void Done()
  {
     buffer = null;
     bufline = null;
     bufcolumn = null;
  }

  /**
   * Method to adjust line and column numbers for the start of a token.
   */
  public void adjustBeginLineColumn(int newLine, int newCol)
  {
     int start = tokenBegin;
     int len;

     if (bufpos >= tokenBegin)
     {
        len = bufpos - tokenBegin + inBuf + 1;
     }
     else
     {
        len = bufsize - tokenBegin + bufpos + 1 + inBuf;
     }

     int i = 0, j = 0, k = 0;
     int nextColDiff = 0, columnDiff = 0;

     while (i < len &&
            bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
     {
        bufline[j] = newLine;
        nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
        bufcolumn[j] = newCol + columnDiff;
        columnDiff = nextColDiff;
        i++;
     } 

     if (i < len)
     {
        bufline[j] = newLine++;
        bufcolumn[j] = newCol + columnDiff;

        while (i++ < len)
        {
           if (bufline[j = start % bufsize] != bufline[++start % bufsize])
              bufline[j] = newLine++;
           else
              bufline[j] = newLine;
        }
     }

     line = bufline[j];
     column = bufcolumn[j];
  }

}

--- NEW FILE: TokenMgrError.java ---
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
package avrora.syntax.objdump;

public class TokenMgrError extends Error {
    /*
     * Ordinals for various reasons why an Error of this type can be thrown.
     */

    /**
     * Lexical error occured.
     */
    static final int LEXICAL_ERROR = 0;

    /**
     * An attempt wass made to create a second instance of a static token manager.
     */
    static final int STATIC_LEXER_ERROR = 1;

    /**
     * Tried to change to an invalid lexical state.
     */
    static final int INVALID_LEXICAL_STATE = 2;

    /**
     * Detected (and bailed out of) an infinite loop in the token manager.
     */
    static final int LOOP_DETECTED = 3;

    /**
     * Indicates the reason why the exception is thrown. It will have one of the above 4 values.
     */
    int errorCode;

    /**
     * Replaces unprintable characters by their espaced (or unicode escaped) equivalents in the given string
     */
    protected static final String addEscapes(String str) {
        StringBuffer retval = new StringBuffer();
        char ch;
        for (int i = 0; i < str.length(); i++) {
            switch (str.charAt(i)) {
                case 0:
                    continue;
                case '\b':
                    retval.append("\\b");
                    continue;
                case '\t':
                    retval.append("\\t");
                    continue;
                case '\n':
                    retval.append("\\n");
                    continue;
                case '\f':
                    retval.append("\\f");
                    continue;
                case '\r':
                    retval.append("\\r");
                    continue;
                case '\"':
                    retval.append("\\\"");
                    continue;
                case '\'':
                    retval.append("\\\'");
                    continue;
                case '\\':
                    retval.append("\\\\");
                    continue;
                default:
                    if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
                        String s = "0000" + Integer.toString(ch, 16);
                        retval.append("\\u" + s.substring(s.length() - 4, s.length()));
                    } else {
                        retval.append(ch);
                    }
                    continue;
            }
        }
        return retval.toString();
    }

    /**
     * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical
     * error. Parameters : EOFSeen     : indicates if EOF caused the lexicl error curLexState : lexical state
     * in which this error occured errorLine   : line number when the error occured errorColumn : column
     * number when the error occured errorAfter  : prefix that was seen before this error occured curchar :
     * the offending character Note: You can customize the lexical error message by modifying this method.
     */
    protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
        return ("Lexical error at line " +
                errorLine + ", column " +
                errorColumn + ".  Encountered: " +
                (EOFSeen ? "<EOF> " : ('\"' + addEscapes(String.valueOf(curChar)) + '\"') + " (" + (int)curChar + "), ") +
                "after : \"" + addEscapes(errorAfter) + '\"');
    }

    /**
     * You can also modify the body of this method to customize your error messages. For example, cases like
     * LOOP_DETECTED and INVALID_LEXICAL_STATE are not of end-users concern, so you can return something like
     * :
     * <p/>
     * "Internal Error : Please file a bug report .... "
     * <p/>
     * from this method for such cases in the release version of your parser.
     */
    public String getMessage() {
        return super.getMessage();
    }

    /*
     * Constructors of various flavors follow.
     */

    public TokenMgrError() {
    }

    public TokenMgrError(String message, int reason) {
        super(message);
        errorCode = reason;
    }

    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
        this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
    }
}



More information about the Tinyos-contrib-commits mailing list