The Features of Caper
Generates modern C++ code!
- The parser is a template class.
- The template parameter is a type of node values and semantic action definition class (see Tutorial).
- Semantic action code is separate, so one grammar is reusable for another purpose.
- Semantic action is type safe because symbol type is provided at input grammar file.
- The parser class is simple and do nothing but analysis only.
- There are only 4 public member functions (
reset
,post
,accept
,error
).
Push-type parser similar to Lemon
- Does nothing until a token is
post
to the parser instance. - So, there is no concept of scanner (nor scanner cooperation).
- Cancellable halfway. There is no side effect on destruction when it became unnecessary.
- The allocation of parser instance can be on heap or on stack.
- Suspending/Resuming is unrestrained (it doesn't move if you don't post).
Output file is only one .hpp file.
- No other file required.
- No links to any libraries required.
- No include of headers (caper doesn't provide any headers).
- The generated parser is license free.
- You can say ``it's a handwritten code''.
- That includes only 3 headers (
<cassert>, <cstdlib>, <vector>
).
No global variables. No static variables. Clean design.
- Thread safe in the instance unit of parser.
- To use one instance from multiple threads, do exclusive control by yourself.
- Multiple parser instances are usable for one thread.
- There is no problem that multiple parsers different in grammar are usable for one thread.
- Multiple grammars are stored in each separate (user-defined) namespace, so usable in one executable file at ease.
- The parser doesn't do dynamic memory allocation basically.
- However there is an exception if STL is used for stack (used on default; changeable by option).
Strong against exception. You can raise exceptions in SemanticAction.
- It is easy to handle errors if you let exceptions raised in catchy grammar.
- We will discuss details later.
- The parser doesn't raise any exception.
- No exception required.
- If STL is used for stack, that may raise exceptions.
- The parser doesn't use RTTF.
- No RTTI required.
Performance is so-so (I think so).
No responsibility. No guarantee.
Advantages of Capar
Input File Is Simple
- The target grammar file is almost grammar only because semantic action is externally described.
Type Safe
- You can give type for token.
- You must set type to non-terminal symbol (the left side symbol of a grammar rule).
- You can check every type by above rules, that is used for semantic action at the right side of a grammar rule.
Warning!
This version is still beta. We didn't verify its stability yet. The specification may be changed (especially by demands). Treat as a toy.
The implementation of Stack<T> is very anxious when STL is off (especially T is complicated type).
Remove %dont_use_stl;
if it didn't work well when you specified it.
We want fix by C++ experts.