[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla ProgramTokenizer.java, 1.6, 1.7

Chien-Liang Fok chien-liang at users.sourceforge.net
Tue May 2 17:36:45 PDT 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8883/edu/wustl/mobilab/agilla

Modified Files:
	ProgramTokenizer.java 
Log Message:


Index: ProgramTokenizer.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla/ProgramTokenizer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ProgramTokenizer.java	10 Jan 2006 07:44:23 -0000	1.6
--- ProgramTokenizer.java	3 May 2006 00:36:42 -0000	1.7
***************
*** 69,72 ****
--- 69,77 ----
  	 */
  	private int currPos = 0;
+ 	
+ 	/**
+ 	 * A hashtable that maps #define macros to their values.
+ 	 */
+ 	private Hashtable<String, String> macros = new Hashtable<String, String>();
  
  	/**
***************
*** 98,101 ****
--- 103,107 ----
  		tokenizer.whitespaceChars(0, 32); // Unreadable chars and whitespace
  		tokenizer.whitespaceChars(127, 127); // DEL
+ 		tokenizer.wordChars('#', '#');
  		//tokenizer.parseNumbers();
  		tokenizer.eolIsSignificant(true);
***************
*** 112,119 ****
  		{
  			switch(ttype) {
! 			case StreamTokenizer.TT_WORD:		
  				if (assembler.isInstruction(tokenizer.sval))
  					parseInstruction(null, tokenizer);
! 				else {			
  					String label = tokenizer.sval;
  					tokenizer.nextToken();
--- 118,140 ----
  		{
  			switch(ttype) {
! 			case StreamTokenizer.TT_WORD:						
  				if (assembler.isInstruction(tokenizer.sval))
  					parseInstruction(null, tokenizer);
! 				else if (tokenizer.sval.toLowerCase().equals("#define")) {
! 					ttype = tokenizer.nextToken();
! 					if (ttype != StreamTokenizer.TT_WORD)
! 						throw new IOException("Invalid macro definition type.");
! 					String key = tokenizer.sval;
! 					ttype = tokenizer.nextToken();
! 					String value = "";
! 					if (ttype == StreamTokenizer.TT_WORD)
! 						value = tokenizer.sval;
! 					else if (ttype == StreamTokenizer.TT_NUMBER) 
! 						value += tokenizer.nval;
! 					else
! 						throw new IOException("Invalid macro replacement for " + key);
! 					System.out.println("Adding " + key + ", " + value + " to the macros table.");
! 					macros.put(key, value);
! 				} else {			
  					String label = tokenizer.sval;
  					tokenizer.nextToken();
***************
*** 158,163 ****
  					throw new IOException("Invalid argument type for instr " 
  							+ opcode + "(" + ttype + ")");
! 				else
! 					arg = new Argument(tokenizer.sval);
  			}
  			else {
--- 179,188 ----
  					throw new IOException("Invalid argument type for instr " 
  							+ opcode + "(" + ttype + ")");
! 				else {
! 					if (macros.containsKey(tokenizer.sval))
! 						arg = new Argument(macros.get(tokenizer.sval));
! 					else
! 						arg = new Argument(tokenizer.sval);
! 				}
  			}
  			else {
***************
*** 169,177 ****
  				else {
  					arg1 = tokenizer.sval;
  					if ((ttype = tokenizer.nextToken()) != StreamTokenizer.TT_WORD)				
  						throw new IOException("Invalid argument 2 type for instr " 
  								+ opcode + "(" + ttype + ")");
! 					else
! 						arg = new Argument(arg1, tokenizer.sval);
  				}
  			}
--- 194,207 ----
  				else {
  					arg1 = tokenizer.sval;
+ 					if (macros.containsKey(arg1)) arg1 = macros.get(arg1);
+ 					
  					if ((ttype = tokenizer.nextToken()) != StreamTokenizer.TT_WORD)				
  						throw new IOException("Invalid argument 2 type for instr " 
  								+ opcode + "(" + ttype + ")");
! 					else {
! 						arg2 = tokenizer.sval;
! 						if (macros.containsKey(arg2)) arg2 = macros.get(arg2);
! 						arg = new Argument(arg1, arg2);
! 					}
  				}
  			}



More information about the Tinyos-contrib-commits mailing list