|
From: vaib on 19 Jun 2008 17:29 hi all . i am trying to build a parser in ANSI C . I made a lexical analyser in the same language a while ago . It was a very simple lexer that tokenised a simple C source code text file - basically a very simple lexer . I had made use of hash tables for the data structure . Now i want to know how to build a parser . I'll let you know what i know about parser building - i'll need a grammar written in the form of regular expressions , i would need to implement something called a parse tree in a data structure of my choice and so on . The problem is that i know stuff here and there but i haven't got a full picture as to what approach is to be taken to attack the problem ,i.e, i do not know the steps involved in the learning curve for parser building . Can anyone out there kindly layout the steps to be taken in proper order ? i want to have a working parser in the next 15 days since thats the amount of time after which my college resumes . I have compiler construction in my next semester so i want to have atleast the front-end ready before the course starts . I do not want a very efficient , high-end or hi-tech parser - just a simple one that demonstrates the concept decently . Any language whose grammar (in the form of REs) is available would do , its not that i want to stick with C alone since i made my lexer for that . It would be very appreciative if anyone who's made a parser before in C could lend me the source code for studying purposes . Resorces that would not take much time are welcome - you see , since i have time constraints i'd like to get to the coding part as soon as possible (and please tell me where to get that grammar from too) . Thanking in anticipation . Vaib .
From: Jerry Coffin on 20 Jun 2008 01:17 In article <6349c591-c73b-4122-9b5d-76f2705754f3 @t12g2000prg.googlegroups.com>, vaibhavpanghal(a)gmail.com says... > hi all . i am trying to build a parser in ANSI C . I made a lexical > analyser in the same language a while ago . It was a very simple lexer > that tokenised a simple C source code text file - basically a very > simple lexer . I had made use of hash tables for the data structure . > Now i want to know how to build a parser . I'll let you know what i > know about parser building - i'll need a grammar written in the form > of regular expressions , i would need to implement something called a > parse tree in a data structure of my choice and so on . Not so. Lexers are typically written in terms of regular expression, but parsers usually are not. To write a parser you normally start by writing the grammar in something like Backus-Naur Form. From there, you can write the parser by hand, typically using recursive descent, or you can generate it with a compiler-compiler such as yacc, Bison, Byacc, Antlr, or any number of others. -- Later, Jerry. The universe is a figment of its own imagination.
|
Pages: 1 Prev: Saving a file from I`net URL Next: Initialize with Copy Constructor? |