Question:
How to create a parser?
anonymous
1970-01-01 00:00:00 UTC
How to create a parser?
Three answers:
Bill G
2007-07-02 07:25:57 UTC
If you are trying to do anything more than trivial, you should look into using a parser generator. There are a number of tools that convert regular expressions into LALR or LR parsers.



YACC and its variants (inc. BYACC and BISON) are commonly used. If you go that route you might want to get John Levine's YACC book from O'Reilly



These tend not to be trivial to use and some "languages" (e.g. C/C++) tend to be difficult to parse in context-free grammars.
easymf co in
2007-07-02 03:20:06 UTC
Please provide more details, else ask expert help for free at http://askexpert.info/
AnalProgrammer
2007-07-02 03:30:05 UTC
Your program or function will accept a string of data and possibly a string parse character (what to parse on) and possibly a starting position in the string of data.

The program will return an array of data.

If there is no parse character then the program will parse on a space.

Starting position will be 0 or the input starting position.

endLocation= first parse character position.

Loop until endLocation < 0

array(n)=substring(start, endLocation)

n++

start=endlocation+1

endlocation=next parse character position

EndLoop

return array



So why couldn't you do that?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...