| | |
New Parser Generator
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
•
•
Join Date: Dec 2008
Posts: 7
Reputation:
Solved Threads: 0
I have recently created a parser generator named the Lithium Parser Generator (LiPG). I also wrote a pretty readable documentation for it. I was wondering if anyone could give me some feedback - especially if you have experience with other parser generators like Bison/Flex, etc.
The Doc:http://www.uweb.ucsb.edu/~frenchenee...mentation.html
Thanks
The Doc:http://www.uweb.ucsb.edu/~frenchenee...mentation.html
Thanks
void getline(char* line)
{ int n=0;
while((line[n]=getchar()) != '\n')
{ n++; }
line[n]=0;
}You shouldn't use broken code examples.
parse ws
[ anychar[] Wo
anyindex an
-> Wo Wo[ Wo[an]==' ' || Wo[an]=='\t' || Wo[an]=='\n' ]
[ return true; ]
]This is _extremely_ verbose for something that just parses whitespace. I'm pretty sure that's simpler to do in other parser generators, and more readable. For example, with ANTLR (and I might be buggy here, I haven't seen ANTLR myself except on IRC channels), you would just see something like
WS : (' '|'\t'|'\f'|'\n'|'\r')+ { $channel=HIDDEN; };For a parser combinator library like Parsec, it would just be
ws = skipMany1 (satisfy isSpace)
Last edited by Rashakil Fol; Dec 14th, 2008 at 7:32 pm.
Also, I don't see the reason to have two mechanisms for concatenating parsers: successive choice blocks and wordforms. They do the same thing, so they add needless redundancy.
Your 'anychar[]' and 'anyindex' features seem unnecessary, almost silly. To say you want a string of characters that satisfy a given predicate, you already have that feature.
Your 'anychar[]' and 'anyindex' features seem unnecessary, almost silly. To say you want a string of characters that satisfy a given predicate, you already have that feature.
Last edited by Rashakil Fol; Dec 14th, 2008 at 7:53 pm.
•
•
Join Date: Dec 2008
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
You shouldn't use broken code examples.
•
•
•
•
This is _extremely_ verbose for something that just parses whitespace.
I was thinking it might be useful to have syntax like this:
parse ws
[-> " " || "\t" || "\t"
[ return true; ]
]
Do you think that would be worth while? In other words, do you think that is acceptable verbosity?
Last edited by frencheneesz; Dec 14th, 2008 at 8:10 pm. Reason: m
•
•
Join Date: Dec 2008
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
successive choice blocks and wordforms ... add needless redundancy.
•
•
•
•
you already have that feature
Btw, thanks for delving so deep into this - I appreciate the feedback.
Last edited by frencheneesz; Dec 14th, 2008 at 8:10 pm. Reason: minor
Note that I'm not saying any good things about your project not because they aren't there, but because it just doesn't suit my disposition.
Now, if you're going to continue with C++, you should spend some time learning C++. You write C++ like a C programmer. For starters, why are you using malloc? You're writing C++. Using "malloc" or "realloc" in C++ is a huge mistake. You can't just take any old array of type T and call realloc on it. Why not: Because realloc does a raw memory copy, instead of calling the objects' copy constructors. Your 'T' might be a datatype that looks like this:
This class's implementation depends on its location -- if you just copy its raw memory, your class will behave erratically.
The same goes for malloc:
These macros are unsafe and insane.
[[Edit:
They are unsafe because ITER1(f()) will call f() each time through -- and the user has no way of realizing this. They're insane because they're insane.
A slight, but incomplete, improvement, would be to use the following:
It would be better to let the user supply his own iterator variable name, and the ending variable name should be something completely unpredictable. But using EACH1 is still insane.
]]
Why do you have your own BDArr and BDFifo implementations anyway? There is
Now, if you're going to continue with C++, you should spend some time learning C++. You write C++ like a C programmer. For starters, why are you using malloc? You're writing C++. Using "malloc" or "realloc" in C++ is a huge mistake. You can't just take any old array of type T and call realloc on it. Why not: Because realloc does a raw memory copy, instead of calling the objects' copy constructors. Your 'T' might be a datatype that looks like this:
class foo {
int[10] nums;
int* current;
public:
foo() { current = nums; }
foo(const foo& other) {
for (int i = 0; i < 10; ++i)
nums[i] = other.nums[i];
current = nums + (other.current - other.nums);
}
void add(int n) {
if (current < nums + 10)
*current++ = n;
}
void get(int i) { return nums[i]; }
};This class's implementation depends on its location -- if you just copy its raw memory, your class will behave erratically.
The same goes for malloc:
a = (T*)malloc(n*sizeof(T)); is just horrible -- your T's will never get constructed!#define ITER1(x) for(int n1=0; n1<x; n1++) #define ITER2(x,y) for(int n1=0; n1<x; n1++) \ for(int n2=0; n2<y; n2++)
These macros are unsafe and insane.
[[Edit:
They are unsafe because ITER1(f()) will call f() each time through -- and the user has no way of realizing this. They're insane because they're insane.
A slight, but incomplete, improvement, would be to use the following:
#define ITER1(x) for(int n1 = 0, e1 = (x); n1 < e1; n1++) . There's still the problem that they introduce variables. If the user has a variable named n1 in play, or in my example, e1, they would get unexpected behavior.It would be better to let the user supply his own iterator variable name, and the ending variable name should be something completely unpredictable. But using EACH1 is still insane.
]]
Why do you have your own BDArr and BDFifo implementations anyway? There is
std::vector and std::queue for a reason... Last edited by Rashakil Fol; Dec 14th, 2008 at 8:20 pm.
Your code has no way of checking if it is overflowing the buffer which has been passed into it. You shouldn't use gets for the same reason. Paste an example where fgets is behaving buggily and I can take a look.
•
•
•
•
Thats a very good point. The problem is that wordforms currently don't have a good way to describe having multiple choices (which is why the whitespace example is so verbose). Choice blocks are verbose however. Do you have an idea of what better syntax would look like?
•
•
Join Date: Dec 2008
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
why are you using malloc?...Why do you have your own BDArr and BDFifo implementations anyway?
•
•
•
•
You shouldn't use gets for the same reason.
•
•
•
•
Paste an example where fgets is behaving buggily and I can take a look.
(make sure if you compile it, don't use optimizations)
![]() |
Similar Threads
- simple calculator using a scanner (re2c) and a parser generator (lemon) (C)
- xml to object and vice versa (Java)
- Visual C++ and Lex/Yacc (IT Professionals' Lounge)
- Why are there so many languages? (Computer Science)
- Oracle and PostreSQL grammar classes (Computer Science)
- XHTML Complient parser? (HTML and CSS)
Other Threads in the Computer Science Forum
- Previous Thread: flowchart done needs help ...take a look
- Next Thread: I need some tips on creating a flowchart.
| Thread Tools | Search this Thread |
ai algorithm algorithms amazon assignment assignmenthelp assignments automata battery bigbrother binary bittorrent bletchleypark bomb business cern codebreaker compiler computer computerscience computertrackingsoftware connect conversion csc dataanalysis dataintepretation development dfa dissertation dissertations dissertationthesis dissertationtopic ebook employment energy floatingpoint foreclosure foreclosuresoftware fuel gadgets geeks givemetehcodez government graphics hardware history homeowners homeworkassignment homeworkhelp humor ibm idea internet iphone ipod itcontracts jobs kindle laser laws lsmeans mainframes marketing mobileapplication msaccess nano netbeans networking news os p2p piracy piratebay principles rasterizer research sam-being-cute sas science software spying stephenfry study supercomputer sweden technology textfield turing turingtest two'scompliment uk virus ww2






