|
Archives
D Programming
digitalmars.Ddigitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger D.gnu D C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
D - D grammar?
Is it LL(1)? Can it be converted to LL(1)? Thanks Aug 05 2003
"Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:bgntfi$qhg$1 digitaldaemon.com...Is it LL(1)? Can it be converted to LL(1)? Aug 05 2003
I know I'm asking stupid questions: I like D very much and i would like to write a parser for it (for fun). Does arbitrary lookahead mean LR(1) grammar/parser? Im writing a program that creates a LR(1) parser table from the grammar but i would like to know is LR(1) the right parser? "Walter" <walter digitalmars.com> wrote in message news:bgon6j$1kfd$2 digitaldaemon.com..."Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:bgntfi$qhg$1 digitaldaemon.com...Is it LL(1)? Can it be converted to LL(1)? Aug 08 2003
"Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:bgvq53$28sd$1 digitaldaemon.com...I know I'm asking stupid questions: I like D very much and i would like to write a parser for it (for fun). Does arbitrary lookahead mean LR(1) grammar/parser? Im writing a program that creates a LR(1) parser table from the grammar but i would like to know is LR(1) the right parser? Aug 08 2003
Walter wrote:"Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:bgvq53$28sd$1 digitaldaemon.com...I know I'm asking stupid questions: I like D very much and i would like to write a parser for it (for fun). Does arbitrary lookahead mean LR(1) grammar/parser? Im writing a program that creates a LR(1) parser table from the grammar but i would like to know is LR(1) the right parser? Aug 08 2003
YACC (and Bison) is LALR(1). LALR(1) cannot parse C, D, or other similar languages without some nasty hacks. LALR(1) is LookAhead Left Right (1 symbol of lookahead). It means that it reads the tokens starting at the left, but interprets them starting from the right. Basically, it means that it can only evaluate the topmost token(s) on the stack. The 1 symbol of lookahead means that you can read one additional symbol before deciding how to evaluate the topmost tokens. As Burton said, the classic problem that YACC has is parsing the difference between expressions and type declarations. A grammar to parse a statment might include the following rules: statement: declaration ';' | expression ';' ; declaration: type IDENT ; type: IDENT | type '*' ; expression: IDENT | expression '*' expression ; Now, as an LALR(1) parser, how do you parse this series of tokens: IDENT '*' IDENT ';' This could be either a declaration of a pointer, or an expression where two variables are multiplied together. An LALR(1) parser MUST be able to parse the top tokens on the stack with only 1 symbol of lookahead. The grammar requires that the parser make a reduction of the first IDENT token, either IDENT->type or IDENT->expression. However, the parser cannot tell from the single token of lookahead which is valid - either could work! Thus, the grammar given above CANNOT be parsed by an LALR(1) parser. You can try to hack around things, if you want: statement: IDENT stars IDENT ';' ; stars: '*' | stars '*' ; This grammar is parsable by an LALR(1) parser. But it isn't really readable! Right when D first came out, I decided to write a parser for it. I started with bison (GNU's yacc alternative). I never had any success parsing D because of problems like this. The grammar eventually gets too ugly to maintain, and even with all the ugliness, my grammar still had ambiguities. In my mind, it's an open question whether it is even possible to devicse an LALR(1) grammar that parses C or D. So I wrote my own parser generator :) Bill Cox wrote:Walter wrote:"Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:bgvq53$28sd$1 digitaldaemon.com...I know I'm asking stupid questions: I like D very much and i would like to write a parser for it (for fun). Does arbitrary lookahead mean LR(1) grammar/parser? Im writing a program that creates a LR(1) parser table from the grammar but i would like to know is LR(1) the right parser? Aug 08 2003
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:bh15g0$gq9$1 digitaldaemon.com...So I wrote my own parser generator :) Aug 08 2003
Russ Lewis wrote: Aug 11 2003
Bill Cox wrote:Can the latest bison parse your D grammer? I think an official machine readable grammer is a good thing, even if no one uses it to create an actual parser. If you have a D grammer, could you post it? Also, if I remember, you couldn't share your new parser generator due to issues at work. Is that right? Bill Aug 11 2003
"Walter" <walter digitalmars.com> wrote in message news:bh0tjn$9cu$1 digitaldaemon.com..."Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:bgvq53$28sd$1 digitaldaemon.com...I know I'm asking stupid questions: I like D very much and i would like to write a parser for it (for fun). Does arbitrary lookahead mean LR(1) grammar/parser? Im writing a program that creates a LR(1) parser table from the grammar but i would like to know is LR(1) the right parser? Aug 08 2003
"Mike Wynn" <mike.wynn l8night.co.uk> wrote in message news:bh13pd$f5f$1 digitaldaemon.com...I think you'll just have to try it out, a D parser generator would be a Aug 08 2003
"Walter" <walter digitalmars.com> wrote in message news:bh1kt5$uua$2 digitaldaemon.com..."Mike Wynn" <mike.wynn l8night.co.uk> wrote in message news:bh13pd$f5f$1 digitaldaemon.com...I think you'll just have to try it out, a D parser generator would be a Aug 09 2003
The biggest improvement the D grammar has over C/C++ is that it does not require semantic information in order to lex or to parse. This makes it a *lot* easier to build syntax sensitive editors and other types of code analysis tools. Aug 10 2003
"Helium" <Helium_member pathlink.com> wrote in message news:bh5489$15nn$1 digitaldaemon.com...The biggest improvement the D grammar has over C/C++ is that it does not require semantic information in order to lex or to parse. This makes it a *lot* easier to build syntax sensitive editors and other types of code analysis tools. Aug 11 2003
I can never remember the difference between LL, LR, LALR, etc., probably because I never use parser generators. But it is not (1) because it requires arbitrary lookahead, mostly in trying to figure out if a sequence of tokens is a type or an expression, declaration or statement. Aug 09 2003
Hi Ivan, It would be great if you (or anybody) would create D grammar in BNF or EBNF. I tried it myself a few month ago from the web documentation, but the grammar (on the web) had tons of trivial errors and was not complete. I tried to get it from sources, but found out that the parser is hand writen. Uff, I have given up. I did not feel like courageous enough to reverse engineer the souce code to create BNF grammar :o( Shame on me, but to reverse engineer the souce code was too much. I attached the BNF grammar, I was able to extract from the web. Anyway, it is few months old. If you (or anybody) can update the file, I would like to play with is and generate a *nice* html grammar for D. (I should be able to generate antlr grammar description from it too, but I do not have this implemented.) I created some XML schema for grammar description and XSLT template to generate the html file; it was my fun project to learn what it is XSLT. To have idea how the hyperlinked grammar would look like check out this C# grammar (there was no source code reverse engineering there :o) ) http://peter.hercek.sk/c-sharp-grammar.html It contains both forward and backward links (ie "show me all the rules, which do use this symbol" can be achieved by clicking on the rule head). Tested only for IE. So, if somebody wants to move D grammar on, please respond to this message (to group of course). But it requires a lot of source code studying unfortunately! I would tell that D grammar is protected through obcurity :o). Seriously now, I may be helpfull with some tools to look up trivial problems etc. Peter. "Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:bgvq53$28sd$1 digitaldaemon.com...I know I'm asking stupid questions: I like D very much and i would like to write a parser for it (for fun). Does arbitrary lookahead mean LR(1) grammar/parser? Im writing a program that creates a LR(1) parser table from the grammar but i would like to know is LR(1) the right parser? "Walter" <walter digitalmars.com> wrote in message news:bgon6j$1kfd$2 digitaldaemon.com..."Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:bgntfi$qhg$1 digitaldaemon.com...Is it LL(1)? Can it be converted to LL(1)? Aug 10 2003
If you're interested in critiquing the grammar in the D documentation, I can work on improving it. Aug 11 2003
I would like to do so, but not from the current state of the web site. I think the grammar must be hard to maintain ... it is distribueted to a lot of pages. Do you generate them somehow? How you keep it up to date? I prefer to critique one file with the grammar, preferably in the format attached in my previous message. The file can have sections, like the C# [http://peter.hercek.sk/c-sharp-grammar.html], actually it already has eg ``0Lexical` (the number zero is the nest level). We can include some remarks etc. For me this was a way to check posibilities of XSLT. I can generate more files (may be a file for each section) to include it into different pages. But then cross-links between different pages would not work, or we need some good naming convention derived from section names or something similar. It is a pain to extract grammar from the webpages and transform it into something usable for automatic processing. I'm lazy to do it manually and it is error prone too. Check also my response to Bil Cox. If he finaly decides to analyze your code, you can get a good grammar for free :) Then we can cut off sections for you to replace in your pages? I believe we can figure it out somehow together. "Walter" <walter digitalmars.com> wrote in message news:bha72n$b1f$1 digitaldaemon.com...If you're interested in critiquing the grammar in the D documentation, I can work on improving it. Aug 12 2003
All the web pages are html pages written by hand. "Peter Hercek" <vvp no.post.spam.sk> wrote in message news:bhce0l$2g97$1 digitaldaemon.com...I would like to do so, but not from the current state of the web site. I think the grammar must be hard to maintain ... it is distribueted to a lot of pages. Do you generate them somehow? How you keep it up to date? I prefer to critique one file with the grammar, preferably in the format attached in my previous message. The file can have sections, like the C# [http://peter.hercek.sk/c-sharp-grammar.html], actually it already has eg ``0Lexical` (the number zero is the nest level). We can include some remarks etc. For me this was a way to check posibilities of XSLT. I can generate more files (may be a file for each section) to include it into different pages. But then cross-links between different pages would not work, or we need some good naming convention derived from section names or something similar. It is a pain to extract grammar from the webpages and transform it into something usable for automatic processing. I'm lazy to do it manually and it is error prone too. Check also my response to Bil Cox. If he finaly decides to analyze your code, you can get a good grammar for free :) Then we can cut off sections for you to replace in your pages? I believe we can figure it out somehow together. "Walter" <walter digitalmars.com> wrote in message Aug 15 2003
Peter Hercek wrote:So, if somebody wants to move D grammar on, please respond to this message (to group of course). But it requires a lot of source code studying unfortunately! I would tell that D grammar is protected through obcurity :o). Seriously now, I may be helpfull with some tools to look up trivial problems etc. Aug 12 2003
Cool, I did it this way last time. Pulled out the grammar from web pages and created the text file (this was pain, because I was not able to automate this completely!) Generated an XML description of the grammar from the text file using antlr. The XML file was transormed to HTML using XSLT. If you would create directly a bison grammar description (this may be easier finaly), I should be able to process the bison file (I hope its grammar is not too complicated without C code) and get the final HTML. Till now I only thought to genereate antlr grammar description to check the grammar for more complicated errors. Simple errors (like multiple definitions for a symbol, no definition for a symbol) can be detected during translation to HTML. I can get you these errors for the file I attached previously, if you think this can help you. I guess bison/LARL(1) and antlr/LL(k) are not the same, but who cares provideded that at least one of them is available. "Bill Cox" <bill viasic.com> wrote in message news:bhas3p$vtm$1 digitaldaemon.com...Peter Hercek wrote:So, if somebody wants to move D grammar on, please respond to this message (to group of course). But it requires a lot of source code studying unfortunately! I would tell that D grammar is protected through obcurity :o). Seriously now, I may be helpfull with some tools to look up trivial problems etc. Aug 12 2003
Hi, Peter. I'll give it a try. I'll start with your grammar file. Bill Peter Hercek wrote:Cool, I did it this way last time. Pulled out the grammar from web pages and created the text file (this was pain, because I was not able to automate this completely!) Generated an XML description of the grammar from the text file using antlr. The XML file was transormed to HTML using XSLT. If you would create directly a bison grammar description (this may be easier finaly), I should be able to process the bison file (I hope its grammar is not too complicated without C code) and get the final HTML. Till now I only thought to genereate antlr grammar description to check the grammar for more complicated errors. Simple errors (like multiple definitions for a symbol, no definition for a symbol) can be detected during translation to HTML. I can get you these errors for the file I attached previously, if you think this can help you. I guess bison/LARL(1) and antlr/LL(k) are not the same, but who cares provideded that at least one of them is available. "Bill Cox" <bill viasic.com> wrote in message news:bhas3p$vtm$1 digitaldaemon.com...Peter Hercek wrote:So, if somebody wants to move D grammar on, please respond to this message (to group of course). But it requires a lot of source code studying unfortunately! I would tell that D grammar is protected through obcurity :o). Seriously now, I may be helpfull with some tools to look up trivial problems etc. Aug 13 2003
In article <bhdv9c$vum$1 digitaldaemon.com>, Bill Cox says...Hi, Peter. I'll give it a try. I'll start with your grammar file. Bill Aug 14 2003
Walter wrote:"Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:bgntfi$qhg$1 digitaldaemon.com...Is it LL(1)? Can it be converted to LL(1)? Aug 08 2003
Bill Cox wrote:Walter wrote:"Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:bgntfi$qhg$1 digitaldaemon.com...Is it LL(1)? Can it be converted to LL(1)? Aug 08 2003
Bill Cox wrote:Being able to YACC D seems a worthy goal. Aug 08 2003
Ilya Minkov wrote:Bill Cox wrote:Being able to YACC D seems a worthy goal. Aug 08 2003
"Ilya Minkov" <midiclub 8ung.at> wrote in message news:bh0jct$30ml$1 digitaldaemon.com...Bill Cox wrote:Being able to YACC D seems a worthy goal. Aug 08 2003
|