// parses SIMPLE VALUES, NOT LISTS public static mysToken ParseLex( mysState state, string lex, object[] replaces ) { LexParser.state = state; LexParser.replaces = replaces; foreach( Func<string, mysToken> transform in actions ) { mysToken result = transform( lex ); if ( result != null ) { return result; } } if ( IsValidIdentifier( lex ) ) { // special case if ( lex == "new" ) { return new mysToken( new clrFunctionGroup( lex ) ); } else { return new mysToken( new mysSymbol( lex ) ); } } else { throw new FormatException(); } }
public static List<mysToken> Parse( mysState state, string expression, object[] replaces = null ) { ParseMachine pm = new ParseMachine( state, expression, replaces: replaces ); while ( pm.CanStep() ) { pm.Step(); } return pm.Tokens; }
ParseMachine( mysState state, string expression, Queue<string> inheritedStringQueue = null, object[] replaces = null ) { this.state = state; stringQueue = inheritedStringQueue ?? new Queue<string>(); this.expression = prepare( expression ) .Split(' ') .Where( sub => sub != " " && sub != "" ) .ToList() ; current = 0; Tokens = new List<mysToken>(); quote = false; this.replaces = replaces; }