Ejemplo n.º 1
0
		public int Add (Token token) {
			return List.Add (token);
		}
Ejemplo n.º 2
0
		private Token ParseTo (IEnumerator iterator) {
			ParseToState state = ParseToState.FunctionName;
			Token name = new Token (TokenType.Word, null);
			TokenList args = new TokenList (); 
			TokenList def = new TokenList ();
			
			bool reading = true;
			bool prev_newline = false;
			while (reading && iterator.MoveNext ()) {
				Token token = (Token) iterator.Current;

				if (state != ParseToState.Content && token.Type == TokenType.Newline) {
					state = ParseToState.Content;
					prev_newline = true;
					continue;
				}
				
				switch (state) {
				case ParseToState.FunctionName:
					name = token;
					state = AdvanceState (state);
					break;
				case ParseToState.Argument:
				case ParseToState.ArgumentWithValue:
				case ParseToState.ArgumentCollector:
					if (token.Type == TokenType.OpenBracket) {
						TokenList arg = ParseBrackets (iterator);
						if (state == ParseToState.Argument || (state == ParseToState.ArgumentWithValue && arg.Count == 1)) {
							state = AdvanceState (state);
						}
						args.Add (new Token (TokenType.PlaceholderElement, new Element (ElementType.List, arg)));
					} else {
						args.Add (token);
					}
					break;
				case ParseToState.Content:
					if (prev_newline && token.Type == TokenType.Word && String.Compare ((string) token.Val, "end", true) == 0) {
						reading = false;
					} else {
						def.Add (token);
						prev_newline = (token.Type == TokenType.Newline); 
					}
					break;
				}
			}

			TokenList func = new TokenList ();
			func.Add (name);
			func.Add (new Token (TokenType.PlaceholderGroup, args));
			func.Add (new Token (TokenType.PlaceholderGroup, def));

			Function func_obj = CreateFunction (func);
			funcs.AddMessage (func_obj);

			if (to_parse == null)
				to_parse = new ArrayList ();
			to_parse.Add (func_obj);

			return new Token (TokenType.PlaceholderElement, new Element (ElementType.Function, func_obj));
		}
Ejemplo n.º 3
0
		private int Weight (Token token) {
			char c = (char) token.Val;
			if (c == '^') {
				return 4;
			} else if (c == '*' || c == '/' || c == '\\') {
				return 3;
			} else if (c == '+' || c == '-') {
				return 2;
			} else if (c == '=' || c == '<' || c == '>') {
				return 1;
			} else {
				return 0;
			}
		}
Ejemplo n.º 4
0
		private StringBuilder AddTokens (TokenList tokens, StringBuilder builder, int c_prev_int, int c_peek_int) {
			StringBuilder ret;
			string val = builder.ToString ();
			
			if (val.Length > 0) {
				ret = new StringBuilder ();
			} else {
				ret = builder;
			}

			double as_num;
			if (IsNumber (val, out as_num)) {
				Token token = new Token (TokenType.Number, as_num);
				if (tokens[tokens.Count - 1].Type == TokenType.Minus) {
					token.Val = -((double) token.Val);
					tokens[tokens.Count - 1] = token;
				} else {
					tokens.Add (token);
				}
			} else if (val.Length > 1) {
				Token token;
				
				string var_name, str_val;
				if (IsVariable (val, out var_name)) 
					token = new Token (TokenType.Variable, var_name);
				else if (IsString (val, out str_val)) 
					token = new Token (TokenType.String, str_val);
				else
					token = new Token (TokenType.Word, val);

				tokens.Add (token);
			} else if (val.Length == 1) {
				tokens.Add (TokenForChar (c_prev_int, c_peek_int, val[0]));
			}

			return ret;
		}