Posts

Showing posts with the label Parsing

Are There Such A Thing As LL(0) Parsers?

Answer : LL(0) parsers do look at the tokens, but they don't decide which productions to apply upon them. They just determine if the sequence belongs to the language or not. This means that every non-terminal symbol must have a single right-hand side and that there may be no recursion. G == ID name lastname name == STRING lastname == STRING # lexer rules # ----------- ID == [0-9]+ STRING == <unicode>+ Note that, as mentioned by @280Z28, a separate lexer is needed to deal with the variable length parts ( ID and STRING ), or the grammar will not be LL(0) . The sequence of productions to apply to parse an input with that grammar requires zero lookahead. A lookahead is required for determinism when there's more than one production that could be applied after part of the given input sequence has been parsed. In theory, a grammar generates a language, and, in that, ambiguity (having more than one way to derive a given phrase) is fine. In parsing, having one-and-...

Best Way To Parse Float?

Answer : I agree with leppie's reply; to put that in terms of code: string s = "123,456.789"; float f = float.Parse(s, CultureInfo.InvariantCulture); Depends where the input is coming from. If your input comes from the user, you should use the CultureInfo the user/page is using (Thread.CurrentThread.CurrentUICulture). You can get and indication of the culture of the user, by looking at the HttpRequest.UserLanguages property. (Not correct 100%, but I've found it a very good first guess) With that information, you can set the Thread.CurrentThread.CurrentUICulture at the start of the page. If your input comes from an internal source, you can use the InvariantCulture to parse the string. The Parse method is somewhat easier to use, if your input is from a controlled source. That is, you have already validated the string. Parse throws a (slow) exception if its fails. If the input is uncontrolled, (from the user, or other Internet source) the TryParse looks b...