Visual C++ compiling error - c++

When compiling these two files I am getting numerous errors. Please help me out.
stchart.cpp
# include "peg.hpp"
# include "stchart.hpp"
# include "stchart_res.hpp"
external PegResourceTable stchart_ResourceTable;
PEGINT gChartData [] = (100, 100, 100, 100, 100, 100, 125, 150, 175, 200,
150, 100, 50, 100, 125, 100, 100, 100);
PEGINT gBukData [] = (100, 100, 100, 100, 100, 100, 100, 100, 125, 100,
100, 120, 140, 160, 180, 200, 150, 100, 50, 125, 100,
100, 125, 150, 125, 100, 100, 100, 100);
/*------------------------------------------------ --------------------------*/
/*------------------------------------------------ --------------------------*/
Strip Chart Window:: Window Strip Chart (PegRect const Rect &,
const PEGUINT titleid):
PegDecoratedWindow (Rect)
(
PEGCOLOR tempColor1, tempColor2, tempColor3;
if (titleid)
(
Add (new PegTitle (titleid));
)
PegRect Chart mClient = Rect;
ChartRect.Bottom = mClient.Height () / 2 to 2;
mpChart = new PegStripChart (Chart Rect, 130, -100, 700, 10, 100);
mpChart-> SetExStyle (mpChart-> GetExStyle () | CS_DRAWYGRID |
CS_DRAWXGRID | CS_DRAWXTICS | CS_DRAWYLABELS |
CS_SCROLLED | / / CS_DUALYTICS | CS_DRAWLINEFILL |
CS_DRAWXLABELS | CS_DUALYTICS | CS_DRAWXLABELS |
CS_DUALYLABELS);
mpChart-> SetExStyle (mpChart-> GetExStyle () & ~ CS_PAGED);
Add (mpChart);
tempColor1 = PegResourceManager:: GetColor (CID_CYAN);
tempColor2 = PegResourceManager:: GetColor (CID_BLUE);
tempColor3 = PegResourceManager:: GetColor (CID_MAGENTA);
mSin = mpChart-> AddLine (tempColor1, tempColor1, tempColor3);
tempColor1 = PegResourceManager:: GetColor (CID_LIGHTGREEN);
tempColor2 = PegResourceManager:: GetColor (CID_GREEN);
tempColor3 = PegResourceManager:: GetColor (CID_RED);
MID-mpChart => AddLine (tempColor1, tempColor1, tempColor3);
mpChart-> SetYLabelScale (200);
ChartRect.Top = ChartRect.Bottom + 4;
ChartRect.Bottom = mClient.Bottom;
mpChart2 = new PegStripChart (Chart Rect, 130, -200, 600, 10, 100);
mpChart2-> SetExStyle (mpChart2-> GetExStyle () | CS_DRAWAGED |
CS_XAXISONZEROY | CS_DRAWXTICS | CS_DRAWXLABELS);
/ / CS_DRAWLINEFILL);
Add (mpChart2);
tempColor1 = PegResourceManager:: GetColor (CID_LIGHTBLUE);
tempColor2 = PegResourceManager:: GetColor (CID_BLUE);
tempColor3 = PegResourceManager:: GetColor (CID_CYAN);
mSin2 = mpChart2-> AddLine (tempColor1, tempColor1, tempColor3);
tempColor1 = PegResourceManager:: GetColor (CID_LIGHTGREEN);
tempColor2 = PegResourceManager:: GetColor (CID_GREEN);
tempColor3 = PegResourceManager:: GetColor (CID_GREEN);
mID2 = mpChart2-> AddLine (tempColor1, tempColor1, tempColor3);
)
/*------------------------------------------------ --------------------------*/
/*------------------------------------------------ --------------------------*/
PEGINT Strip Chart Window:: Message (const PegMessage & mesg)
(
static PEGINT Index = 0, j = 0;
static PEGINT Angle = 0;
switch (Mesg.Type)
(
PM_SHOW case:
PegWindow:: Message (mesg);
SetTimer (1, PEG_ONE_SECOND, 1);
break;
PM_HIDE case:
PegWindow:: Message (mesg);
Kill Timer (1);
break;
PM_TIMER case:
(
if (+ + index> 17)
(
Index = 0;
)
mpChart-> AddData (MID, gChartData [Index]);
if (+ + j> 28)
(
j = 0;
)
mpChart2-> AddData (mID2, gBukData [j]);
if ((Angle + = 10)> 350)
(
Angle = 0;
)
PEGINT Sin, Cos;
PegLookupSinCos (Angle, & Sin, Cos &);
mpChart-> AddData (mSin, (PEGLONG) ((Sin * 125)>> 10) + 400);
mpChart2-> AddData (mSin2, (PEGLONG) ((125 * Cos)>> 10) + 400);
)
default:
(
return (PegWindow:: Message (mesg));
)
)
return 0;
)
/*------------------------------------------------ --------------------------*/
/*------------------------------------------------ --------------------------*/
void PegAppInitialize (PegPresentationManager * pPresentation)
(
PegRect Rect;
Rect.Set (10, 10, 630, 470);
PegResourceManager:: Install Resources From Table (&
stchart_ResourceTable);
Strip Chart Window * pWindow = new Strip Chart Window (Rect, SID_TITLE);
pPresentation-> Add (pWindow);
)
stchart.hpp:
Strip Chart class Window: public PegDecoratedWindow
(
public:
Strip Chart Window (PegRect const Rect &, const PEGUINT titleid);
Strip Chart virtual ~ Window () ()
virtual PEGINT Message (const PegMessage & mesg);
public:
PegStripChart * mpChart;
PegStripChart * mpChart2;
PEGUBYTE mid;
PEGUBYTE mSin;
PEGUBYTE mID2;
PEGUBYTE mSin2;
);
ERRORS:
-------------------- Configuration: stchart - Win32 Debug --------------------
Compiling ...
stchart.cpp
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.hpp (29): error C2143: syntax error: missing ',' before '*'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.hpp (29): error C2501: 'PegStripChart': missing storage-class or type specifiers
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.hpp (29): error C2501: 'mpChart': missing storage-class or type specifiers
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.hpp (30): error C2143: syntax error: missing ',' before '*'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.hpp (30): error C2501: 'PegStripChart': missing storage-class or type specifiers
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.hpp (30): error C2501: 'mpChart2': missing storage-class or type specifiers
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (45): error C2065: 'mpChart': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (45): error C2061: syntax error: identifier 'PegStripChart'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (46): error C2227: left of '-> SetExStyle' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (46): error C2227: left of '-> GetExStyle' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (46): error C2065: 'CS_DRAWYGRID': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (46): error C2065: 'CS_DRAWXGRID': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (47): error C2065: 'CS_DRAWXTICS': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (47): error C2065: 'CS_DRAWYLABELS': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (47): error C2065: 'CS_SCROLLED': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (49): error C2065: 'CS_DUALYTICS': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (49): error C2065: 'CS_DRAWXLABELS': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (50): error C2065: 'CS_DUALYLABELS': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (51): error C2227: left of '-> SetExStyle' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (51): error C2227: left of '-> GetExStyle' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (51): error C2065: 'CS_PAGED': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (56): error C2227: left of '-> AddLine' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (61): error C2227: left of '-> AddLine' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (62): error C2227: left of '-> SetYLabelScale' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (66): error C2065: 'mpChart2': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (66): error C2061: syntax error: identifier 'PegStripChart'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (67): error C2227: left of '-> SetExStyle' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (67): error C2227: left of '-> GetExStyle' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (67): error C2065: 'CS_DRAWAGED': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (68): error C2065: 'CS_XAXISONZEROY': undeclared identifier
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (75): error C2227: left of '-> AddLine' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (80): error C2227: left of '-> AddLine' must point to class / struct / union
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): error C2143: syntax error: missing ',' before ')'
c: \ swellsoftware \ pegplus \ examples \ stchart \ plus \ stchart.cpp (82): fatal error C1003: error count exceeds 100; stopping compilation
Error executing cl.exe.
** stchart.obj - 102 error (s), 0 warning (s) **

It appears that PegStripChart is not declared in any of the files you've shown us and this seems tobe causing the first few errors at least.
Is it declared in peg.hpp?

Pay attention on your switch operator it should be:
switch (Mesg.Type)
(
case PM_SHOW:
PegWindow:: Message (mesg);
SetTimer (1, PEG_ONE_SECOND, 1);
break;
case PM_HIDE:
PegWindow:: Message (mesg);
Kill Timer (1);
break;
.............................
.............................
And you wrote:
switch (Mesg.Type)
(
PM_SHOW case :
PegWindow:: Message (mesg);
SetTimer (1, PEG_ONE_SECOND, 1);
break;
PM_HIDE case :
PegWindow:: Message (mesg);
Kill Timer (1);
break;
........................
.....................

You are using ()'s where you should be using {}'s
e.g, your if-blocks, switch statements, method declarations, etc.

Related

Repeat generation of macro

I would like to generate the following preprocessor pragmas
#pragma blabla column("0030")
#pragma blabla column("0130")
#pragma blabla column("0230")
...
#pragma blabla column("2330")
the hour changing from 0 to 23
Is that possible with BOOST_PP_LOCAL_LIMITS/ITERATE?
Yeah.
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/comparison/greater.hpp>
#define blabla(z, n, data) \
_Pragma(BOOST_PP_STRINGIZE( \
blabla column( \
BOOST_PP_STRINGIZE( \
BOOST_PP_CAT( \
BOOST_PP_CAT( \
BOOST_PP_IF( \
BOOST_PP_GREATER(n, 9), \
, \
0 \
), \
n \
), \
30 \
) \
) \
) \
))
BOOST_PP_REPEAT(24, blabla, ~)
_Pragma saved us there because there is no way to generate preprocessor directives such as #pragma, however it is very picky about what it accepts. In particular, it doesn't do string concatenation, so _Pragma("some" "thing") does not work, we have to concatenate everything in token-land then stringize as the last step.

Micro Parser Combinators (mpc) runs in endless loop

I am writing a compiler in C++ (using Visual Studio) for a small scripting language and I use this C parsing library.
So, I followed instructions from the documentation and I ended up on this peace of code:
int main()
{
mpc_parser_t* Int = mpc_new("int");
mpc_parser_t* Char = mpc_new("char");
mpc_parser_t* String = mpc_new("string");
mpc_parser_t* Id = mpc_new("id");
mpc_parser_t* Type = mpc_new("type");
mpc_parser_t* Formal = mpc_new("formal");
mpc_parser_t* Header = mpc_new("header");
mpc_parser_t* FuncDecl = mpc_new("funcdecl");
mpc_parser_t* VarDef = mpc_new("vardef");
mpc_parser_t* Expr = mpc_new("expr");
mpc_parser_t* Call = mpc_new("call");
mpc_parser_t* Atom = mpc_new("atom");
mpc_parser_t* Simple = mpc_new("simple");
mpc_parser_t* SimpleList = mpc_new("simplelist");
mpc_parser_t* Stmt = mpc_new("stmt");
mpc_parser_t* FuncDef = mpc_new("funcdef");
mpc_parser_t* Program = mpc_new("program");
/* Define them with the following Language */
mpca_lang(MPCA_LANG_DEFAULT,
" \
int : /-?[0-9]+/ ; \
char : /'[a-zA-Z0-9!##$%^&*()\\_+-,.\\/<>?;'|\"`~]'/ ; \
string : /\"(\\\\.|[^\"])*\"/ ; \
id : /[a-zA-Z][a-zA-Z0-9_-]*/ ; \
type : \"int\" | \"bool\" | \"char\" | <type> '[' ']' | \"list\" '[' <type> ']' ; \
formal : (\"ref\")? <type> <id> (',' <id>)* ; \
header : <type>? <id> '(' (<formal> (';' <formal>)*)? ')' ; \
funcdecl : \"decl\" <header> ; \
vardef : <type> <id> (',' <id>)* ; \
expr : <atom> | <int> | <char> | '(' <expr> ')' \
| ('+' | '-') <expr> | <expr> ('+' | '-' | '*' | '/' | \"mod\") <expr> \
| <expr> ('=' | \"<>\" | '<' | '>' | \"<=\" | \">=\") <expr> \
| \"true\" | \"false\" | \"not\" <expr> | <expr> (\"and\" | \"or\") <expr> \
| \"new\" <type> '[' <expr> ']' | \"nil\" | \"nil?\" '(' <expr> ')' \
| <expr> '#' <expr> | \"head\" '(' <expr> ')' | \"tail\" '(' <expr> ')' ; \
call : <id> '(' (<expr> (',' <expr>)*)? ')' ; \
atom : <id> | <string> | <atom> '[' <expr> ']' | <call> ; \
simple : \"skip\" | <atom> \":=\" <expr> | <call> ; \
simplelist : <simple> (',' <simple>)* ; \
stmt : <simple> | \"exit\" | \"return\" <expr> \
| \"if\" <expr> ':' <stmt>+ (\"elif\" <expr> ':' <stmt>+)* \
(\"else\" ':' <stmt>+)? \"end\" \
| \"for\" <simplelist> ';' <expr> ';' <simplelist> ':' <stmt>+ \"end\" ; \
funcdef : \"def\" <header> ':' (<funcdef> | <funcdecl> | <vardef>)* <stmt>+ \"end\" ; \
program : /^/ <funcdef> /$/ ; \
",
Int, Char, String, Id, Type, Formal, Header, FuncDecl, VarDef, Expr,
Call, Atom, Simple, SimpleList, Stmt, FuncDef, Program);
mpc_result_t r;
char* input = "def hey () : return 1 end";
if(mpc_parse("input", input, Program, &r))
{
mpc_ast_print((mpc_ast_t*)r.output);
mpc_ast_delete((mpc_ast_t*)r.output);
}
else
{
mpc_err_print(r.error);
mpc_err_delete(r.error);
}
PAUSE("Press any key to continue . . .");
/* Undefine and Delete our Parsers */
mpc_cleanup(17, Int, Char, String, Id, Type, Formal, Header, FuncDecl, VarDef, Expr,
Call, Atom, Simple, SimpleList, Stmt, FuncDef, Program);
return 0;
}
The problem is that I run into an huge loop in mpc_parse. That loop never actually reaches the end. After some time I get this exception:
Unhandled exception at 0x00CBBC9C in TonyCC.exe: 0xC0000005: Access violation reading location 0x0000000C.
I don't know why. I suspect there is something wrong with my grammar but I cannot figure out what.
If someone has used this library before, do you have any idea what the problem might be?
Note: I know it is difficult to read the grammar from C code so here is an image of the grammar:

Alternation in regular expression NOT working (use of pipe symbol | ) to zero in on value types

I did a little reading up and realized the pipe symbol | can be used like "or" logic when matching. I've tried to incorporate this in my following code but it doesn't work in doing some text processing that follows regexp (see snippet code below file format) . First here's my file type (.lib used in chip design)
pin (d) {
direction : input;
nextstate_type : data;
related_ground_pin : vss;
related_power_pin : vcc;
max_transition : 0.4;
capacitance : 0.000719782;
rise_capacitance : 0.000719782;
rise_capacitance_range (0.000462301, 0.000719782);
fall_capacitance : 0.000569233;
fall_capacitance_range (0.000459043, 0.000569233);
timing () {
related_pin : "clk";
timing_type : setup_rising;
rise_constraint (constraint_template_5X5) {
index_1 ("0.01, 0.05, 0.12, 0.2, 0.4");
index_2 ("0.005, 0.025, 0.06, 0.1, 0.3");
index_3 ("0.084, 0.84, 3.36, 8.4, 13.44") ;
values ( \
"5.1,1.2,1.3,1.4,1.5", \
"9.1,2.2,2.3,2.4,2.5", \
"3.1,3.2,3.3,3.4,3.5", \
"4.1,4.2,4.3,4.4,4.5", \
"5.1,5.2,5.3,5.4,5.5", \
"6.1,6.2,6.3,6.4,6.5", \
"7.1,7.2,7.3,7.4,7.5", \
"8.1,8.2,8.3,8.4,8.5", \
"9.1,9.2,9.3,9.4,9.5", \
"10.1,10.2,10.3,10.4,10.5", \
"11.1,11.2,11.3,11.4,11.5", \
"12.1,12.2,12.3,12.4,12.5", \
"13.1,13.2,13.3,13.4,13.5", \
"14.1,14.2,14.3,14.4,14.5", \
"15.1,15.2,15.3,15.4,15.5", \
"16.1,16.2,16.3,16.4,16.5", \
"17.1,17.2,17.3,17.4,17.5", \
"18.1,18.2,18.3,18.4,18.5", \
"19.1,19.2,19.3,19.4,19.5", \
"20.1,20.2,20.3,20.4,20.5", \
"21.1,21.2,21.3,21.4,21.5", \
"22.1,22.2,22.3,22.4,22.5", \
"23.1,23.2,23.3,23.4,23.5", \
"24.1,24.2,24.3,24.4,24.5", \
"25.1,25.2,25.3,25.4,25.5", \
);
}
fall_constraint (constraint_template_5X5) {
index_1 ("0.01, 0.05, 0.12, 0.2, 0.4");
index_2 ("0.005, 0.025, 0.06, 0.1, 0.3");
index_3 ("0.084, 0.84, 3.36, 8.4, 13.44") ;
values ( \
"1.1,1.2,1.3,1.4,1.5", \
"2.1,2.2,2.3,2.4,2.5", \
"3.1,3.2,3.3,3.4,3.5", \
"4.1,4.2,4.3,4.4,4.5", \
"5.1,5.2,5.3,5.4,5.5", \
"6.1,6.2,6.3,6.4,6.5", \
"7.1,7.2,7.3,7.4,7.5", \
"8.1,8.2,8.3,8.4,8.5", \
"9.1,9.2,9.3,9.4,9.5", \
"10.1,10.2,10.3,10.4,10.5", \
"11.1,11.2,11.3,11.4,11.5", \
"12.1,12.2,12.3,12.4,12.5", \
"13.1,13.2,13.3,13.4,13.5", \
"14.1,14.2,14.3,14.4,14.5", \
"15.1,15.2,15.3,15.4,15.5", \
"16.1,16.2,16.3,16.4,16.5", \
"17.1,17.2,17.3,17.4,17.5", \
"18.1,18.2,18.3,18.4,18.5", \
"19.1,19.2,19.3,19.4,19.5", \
"20.1,20.2,20.3,20.4,20.5", \
"21.1,21.2,21.3,21.4,21.5", \
"22.1,22.2,22.3,22.4,22.5", \
"23.1,23.2,23.3,23.4,23.5", \
"24.1,24.2,24.3,24.4,24.5", \
"25.1,25.2,25.3,25.4,25.5", \
);
}
}
}
Ok, so I have to do some text processing (aided by Brad Lanam - user of SO) which is done as follows. The aim of this piece of code is to zero in on the right types of constraints (in my .lib) to do text processing.
set inFile [open "C:/Tcl/official/ref.lib" r]
set inval false
set foundValues 0
set found_setup 0
set found_fall 0
set extract1 0
set extract2 0
set DETECT_END_SYNTAX {\);}
while { [gets $inFile line] >= 0 } {
if { [regexp {setup_rising;} $line] } { set found_setup 1 }
if { [regexp {hold_rising;} $line] } { set found_setup 0 }
if { $found_setup } {
if { [regexp {rise_constraint|fall_constraint} $line] } { set found_fall 1 }
if { $found_fall } {
if {[regexp {values} $line]} {
set foundValues 1
}
if {$foundValues} {
if { [regexp $DETECT_END_SYNTAX $line] } {
if { $inval } {
set inval false
set foundValues 0
set found_fall 0
}
}
}
}
}
}
# { Do text processing after this }
But
if { [regexp {rise_constraint|fall_constraint} $line] }
# Does NOT work
in matching either rise_constraint or fall_constraint to do some regsub commands. My code only ends up processing values for rise_constraint in the modified file written out. I need the values of both constraint types to be changed. Am I doing something wrong in the regexp? Thanks!
Should I just do this:
if { [regexp {rise_constraint} $line] } { set found_fall 1 }
if { [regexp {fall_constraint} $line] } { set found_fall 1 }
Instead of:
if { [regexp {rise_constraint|fall_constraint} $line] } { set found_fall 1 }
Note: found_fall actually will find even the rise_constraint values, it's just a variable.
Reference: tcl text processing - rearrange values in rows and columns based on user defined value
if { [regexp {rise_constraints|fall_constraint} $line] }
Doesn't work because there is no rise_constraints in the lines. There is rise_constraint with no s.
Also, try to better indent your code next time.

Compilation Error using Winbase.h

I am unable to Compile my driver code because my Program shows me error at the time of compilation. Can someone please help me.
Using winddk build environment on Windows 7 , 32-bit OS
Included header files :
#include <wdm.h>
#include <Windows.h>
#include <windef.h>
#include <ntddk.h>
#include <Ntifs.h>
#include <fltkernel.h>
Errors :
1>errors in directory c:\simple_driver\driver\driver
1>c:\winddk\7600.16385.1\inc\api\winbase.h(318) : error C2061: syntax error : id
entifier 'CRITICAL_SECTION'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(318) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(319) : error C2061: syntax error : id
entifier 'PCRITICAL_SECTION'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(319) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(320) : error C2061: syntax error : id
entifier 'LPCRITICAL_SECTION'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(320) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(322) : error C2061: syntax error : id
entifier 'CRITICAL_SECTION_DEBUG'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(322) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(323) : error C2061: syntax error : id
entifier 'PCRITICAL_SECTION_DEBUG'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(323) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(324) : error C2061: syntax error : id
entifier 'LPCRITICAL_SECTION_DEBUG'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(324) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(332) : error C2061: syntax error : id
entifier 'INIT_ONCE'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(332) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(333) : error C2061: syntax error : id
entifier 'PINIT_ONCE'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(333) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(334) : error C2061: syntax error : id
entifier 'LPINIT_ONCE'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(334) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(363) : error C2146: syntax error : mi
ssing ')' before identifier 'InitOnce'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(363) : error C2061: syntax error : id
entifier 'InitOnce'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(363) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(363) : error C2059: syntax error : ',
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(366) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(372) : error C2146: syntax error : mi
ssing ')' before identifier 'InitOnce'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(372) : error C2061: syntax error : id
entifier 'InitOnce'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(372) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(373) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(379) : error C2146: syntax error : mi
ssing ')' before identifier 'InitOnce'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(379) : error C2061: syntax error : id
entifier 'InitOnce'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(379) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(379) : error C2059: syntax error : ',
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(383) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(389) : error C2146: syntax error : mi
ssing ')' before identifier 'lpInitOnce'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(389) : error C2061: syntax error : id
entifier 'lpInitOnce'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(389) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(389) : error C2059: syntax error : ',
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(393) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(399) : error C2146: syntax error : mi
ssing ')' before identifier 'lpInitOnce'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(399) : error C2061: syntax error : id
entifier 'lpInitOnce'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(399) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(399) : error C2059: syntax error : ',
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(402) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(410) : error C2061: syntax error : id
entifier 'SRWLOCK'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(410) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(410) : error C2059: syntax error : ',
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(418) : error C2146: syntax error : mi
ssing ')' before identifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(418) : error C2061: syntax error : id
entifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(418) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(419) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(425) : error C2146: syntax error : mi
ssing ')' before identifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(425) : error C2061: syntax error : id
entifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(425) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(426) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(432) : error C2146: syntax error : mi
ssing ')' before identifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(432) : error C2061: syntax error : id
entifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(432) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(433) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(439) : error C2146: syntax error : mi
ssing ')' before identifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(439) : error C2061: syntax error : id
entifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(439) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(440) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(446) : error C2146: syntax error : mi
ssing ')' before identifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(446) : error C2061: syntax error : id
entifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(446) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(447) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(453) : error C2146: syntax error : mi
ssing ')' before identifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(453) : error C2061: syntax error : id
entifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(453) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(454) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(460) : error C2146: syntax error : mi
ssing ')' before identifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(460) : error C2061: syntax error : id
entifier 'SRWLock'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(460) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(461) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(467) : error C2061: syntax error : id
entifier 'CONDITION_VARIABLE'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(467) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(467) : error C2059: syntax error : ',
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(473) : error C2146: syntax error : mi
ssing ')' before identifier 'ConditionVariable'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(473) : error C2061: syntax error : id
entifier 'ConditionVariable'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(473) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(474) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(480) : error C2146: syntax error : mi
ssing ')' before identifier 'ConditionVariable'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(480) : error C2061: syntax error : id
entifier 'ConditionVariable'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(480) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(481) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(487) : error C2146: syntax error : mi
ssing ')' before identifier 'ConditionVariable'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(487) : error C2061: syntax error : id
entifier 'ConditionVariable'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(487) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(488) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(494) : error C2146: syntax error : mi
ssing ')' before identifier 'ConditionVariable'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(494) : error C2061: syntax error : id
entifier 'ConditionVariable'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(494) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(494) : error C2059: syntax error : ',
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(497) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(503) : error C2146: syntax error : mi
ssing ')' before identifier 'ConditionVariable'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(503) : error C2061: syntax error : id
entifier 'ConditionVariable'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(503) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(503) : error C2059: syntax error : ',
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(507) : error C2059: syntax error : ')
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(554) : error C2061: syntax error : id
entifier 'LPLDT_ENTRY'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(554) : error C2059: syntax error : ';
'
1>c:\winddk\7600.16385.1\inc\api\winbase.h(2288) : error C2373: 'InterlockedIncr
ement' : redefinition; different type modifiers
1>c:\winddk\7600.16385.1\inc\api\winbase.h(2288) : error C1003: error count exce
eds 100; stopping compilation
Linking Executable - objchk_win7_x86\i386\driver.sys
1>link : error LNK1181: cannot open input file 'c:\simple_driver\driver\driver\o
bjchk_win7_x86\i386\code.obj'
BUILD: Finish time: Thu Jun 20 01:27:15 2013
BUILD: Done
3 files compiled - 4 Warnings - 102 Errors - 173 LPS
1 executable built - 1 Error
You're including user mode headers in kernel code.
Remove the Windows.h header.

How to make two lines appear on the same height in RRDtool?

I'm using RRDtool to greate graphs.
Now, this command:
rrdtool graph temp.png \
-w 600 -h 200 \
--zoom 1 \
--title "last 24 hours temperature" \
--vertical-label "temperature (°C)" \
--alt-autoscale \
--alt-y-grid \
--start end-1d \
--force-rules-legend \
--legend-position=south \
--rigid \
--slope-mode \
--font "DEFAULT:12:century schoolbook l" --watermark "$(date '+%F %T %Z')" \
DEF:temperature=temp.rrd:temp:AVERAGE \
GPRINT:temperature:LAST:"Current temp.\: %.2lf°C\r" \
LINE1:temperature\#007070:"Mainboard\l"
Gives me this image:
As you can see, the legend and the text "Current temp.: 42.00°C", do not appear on the same height (baseline).
How can I make those kind of lines appear next to each other, one left floated, the other right floated?
You could try ...
rrdtool graph temp.png \
-w 600 -h 200 \
--zoom 1 \
--title "last 24 hours temperature" \
--vertical-label "temperature (°C)" \
--alt-autoscale \
--alt-y-grid \
--start end-1d \
--force-rules-legend \
--legend-position=south \
--rigid \
--slope-mode \
--font "DEFAULT:12:century schoolbook l" --watermark "$(date '+%F %T %Z')" \
DEF:temperature=temp.rrd:temp:AVERAGE \
LINE1:temperature\#007070:"Mainboard" \
GPRINT:temperature:LAST:"Current temp.\: %.2lf°C\j"
note that I flipped the last two lines around and added \j