Compilation Error using Winbase.h - c++

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.

Related

Powershell Script to run Unit Test using MSTest.exe

How to run all the unit test in a solution directory using Powershell Script.
I tried with the below command
$tool = '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe"'
$x = ""; dir D:\DropBuildOutput\*.Tests.dll -Recurse | foreach { $x += "/testcontainer:""$_"" " }; iex "$tool $x"
But its failing with error below.How can i run all the tests and generate results?
iex : At line:1 char:79
+ ... (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" /testcont ...
+ ~
You must provide a value expression following the '/' operator.
At line:1 char:79
+ ... STest.exe" /testcontainer:"D:\DropBuildOutput\_PublishedWebsites\SCJ. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token
'testcontainer:"D:\DropBuildOutput\_PublishedWebsites\aaa.aaa.aaa.aaa\bin\xxx.aaa.aaa.Tests.dll"' in
expression or statement.
At line:2 char:100
+ ... -Recurse | foreach { $x += "/testcontainer:""$_"" " }; iex "$tool $x"
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
+ FullyQualifiedErrorId : ExpectedValueExpression,Microsoft.PowerShell.Commands.InvokeExpressionCommand
Use the call operator & instead of Invoke-Expression:
& $Tool $x

How to solve "syntax error at line 1 "

Hi I've used lex and yacc to create my own programming language syntax (sort of) , but no matter how my grammar rules are put , it gives me syntax error at the same first line.
This is my lex code of regular expressions:
%{
#include <stdio.h>
#include "y.tab.h"
%}
%option noyywrap
punct [.]
virgula [,]
numar [0-9]+
numar2 [0-9]
%%
"&librarie=>" {return INCLUDE;}
"stringuri"|"vectori"|"mape"|"matematica" {return LIBRARII;}
"intreg"|"caracter"|"string"|"natural" {return TIPVAR;}
"real" {return REAL;}
"daca" {return DACA;}
"pentru" {return PENTRU;}
"cat_timp" {return CATTIMP;}
def_variabla_globala {return VARGLOBALE;}
def_variabla_locala {return VARLOCALE;}
structura_obiect {return STRUCTURA;}
"procedura[]" {return PROCEDURA;}
start_program {return START;}
stop_program {return STOP;}
inceput_bloc_if {return INBLOCIF;}
sfarsit_bloc_if {return SFBLOCIF;}
atunci {return ATUNCI;}
altfel {return ALTFEL;}
from {return FROM;}
to {return TO;}
smaller_than {return MAIMIC;}
greater_than {return MAIMARE;}
equal_to {return EGAL;}
different_than {return DIFERIT;}
inceput_bloc_for {return INBLOCFOR;}
sfarsit_bloc_for {return SFBLOCFOR;}
inceput_bloc_cat_timp {return INBLOCCATTIMP;}
sfarsit_bloc_cat_timp {return SFBLOCCATTIMP;}
executa {return EXECUTA;}
suma {return SUM;}
invers {return INV;}
oglindit {return OGL;}
"<-" {return ASIGNARE;}
[a-zA-Z][a-zA-Z0-9]* {return ID;REJECT;}
{numar} {return NUMAR;REJECT;}
[0-9]{punct}{numar} {return NUMARREAL;}
{numar}|({virgula}{numar})* {return VECTASIGN;}
({numar2}{punct}{numar})|({virgula}({numar2}{punct}{numar}))* {return VECTASIGNREAL;}
[a-zA-Z][a-zA-Z ]* {return CUVANT;REJECT;}
afisare {return AFISARE;}
[ \t] ;
\n {yylineno++;}
. {return yytext[0];}
%%
I used REJECT at those 2 regex , because it gave me a warning , several of my rules were having conflicts with each other.
My grammar rules :
%{
#include <stdio.h>
extern FILE* yyin;
extern char* yytext;
extern int yylineno;
%}
%token INCLUDE LIBRARII ID TIPVAR CUVCHEIE REAL NUMARREAL FROM TO VECTASIGNREAL VARGLOBALE VARLOCALE VECTASIGN STRUCTURA PROCEDURA START STOP DACA PENTRU CATTIMP INBLOCIF SFBLOCIF ATUNCI ALTFEL MAIMIC MAIMARE EGAL DIFERIT INBLOCFOR SFBLOCFOR INBLOCCATTIMP SFBLOCCATTIMP EXECUTA SUM INV OGL ASIGNARE NUMAR CUVANT AFISARE
%start progr
%left '+' '-'
%left '*' '/'
%%
progr: headere declaratii program {printf("correct syntax");}
;
headere : header
|headere header
;
header : INCLUDE LIBRARII
;
declaratii : declaratie ';'
| declaratii declaratie ';'
;
declaratie : VARGLOBALE TIPVAR ID
| VARGLOBALE TIPVAR ID '[' NUMAR ']'
| VARGLOBALE TIPVAR ID ASIGNARE NUMAR
| VARGLOBALE TIPVAR ID ASIGNARE '#' CUVANT '#'
| VARGLOBALE TIPVAR ID '[' NUMAR ']' ASIGNARE '[' VECTASIGN ']'
| VARGLOBALE REAL ID
| VARGLOBALE REAL ID '[' NUMAR ']'
| VARGLOBALE REAL ID ASIGNARE NUMARREAL
| VARGLOBALE REAL ID '[' NUMAR ']' ASIGNARE '[' VECTASIGNREAL ']'
;
program : PROCEDURA START bloc STOP
;
bloc : declaratiile instructiuni
;
declaratiile : declaratia ';'
| declaratiile declaratia ';'
;
declaratia : VARLOCALE TIPVAR ID
| VARLOCALE TIPVAR ID '[' NUMAR ']'
| VARLOCALE TIPVAR ID ASIGNARE NUMAR
| VARLOCALE TIPVAR ID ASIGNARE '#' CUVANT '#'
| VARLOCALE TIPVAR ID '[' NUMAR ']' ASIGNARE '[' VECTASIGN ']'
| VARLOCALE REAL ID
| VARLOCALE REAL ID '[' NUMAR ']'
| VARLOCALE REAL ID ASIGNARE NUMARREAL
| VARLOCALE REAL ID '[' NUMAR ']' ASIGNARE '[' VECTASIGNREAL ']'
;
instructiuni : instructiune ';'
| instructiuni instructiune ';'
;
instructiune : instructiune_simpla ';'
| instructiune_compusa ';'
;
instructiune_simpla : ID ASIGNARE expresie ';'
;
expresie : expresie '+' expresie
| expresie '-' expresie
| expresie '*' expresie
| expresie '/' expresie
| functie
| NUMAR
| ID
;
functie : INV '(' expresie ')'
| SUM '(' expresie ',' expresie ',' expresie ',' expresie ',' expresie ')'
| OGL '(' expresie ')'
| AFISARE '(' NUMAR ')'
| AFISARE '(' ID ')'
| AFISARE '(' CUVANT ')'
;
instructiune_compusa : DACA conditie ATUNCI
INBLOCIF
instructiuni
SFBLOCIF
ALTFEL
INBLOCIF
instructiuni
SFBLOCIF
|PENTRU ID FROM NUMAR TO NUMAR EXECUTA
INBLOCFOR
instructiuni
SFBLOCFOR
|CATTIMP ID conditie NUMAR
INBLOCCATTIMP
instructiuni
SFBLOCCATTIMP
;
conditie : MAIMARE
| MAIMIC
| EGAL
;
%%
int yyerror(char * s){
printf("error: %s line:%d\n",s,yylineno);
}
int main(int argc, char** argv){
yyin=fopen(argv[1],"r");
yyparse();
}
And this is the file that I test with , and it should return that the program has a correct syntax.
&librarie=>stringuri
&librarie=>vectori
def_variabila_globala intreg var1<-23;
def_variabila_globala natural vect[50]<-{1,3,51,2,421,12,43};
def_variabila_globala real a<-12.5;
def_variabila_globala caracter ch<-#x#;
def_variabila_globala string s<-#alabala portocala#;
structura_obiect persoana
~
real inaltime;
natural varsta;
~
procedura[]
start_program
def_variabila_locala intreg negativ,pozitiv,s,contor1,contor2<-5;
def_variabila_locala adunari_scaderi;
def_variabila_locala inmultiri_impartiri;
def_variabila_locala ad_scd_inm_imp;
persoana p1;
p1#inaltime<-1.82;
p1#varsta<-20;
adunari_scaderi<-243-12+43-12+11+31-124;
afisare<adunari_scaderi>;
inmultiri_impartiri<-3*4/2/2*3/9;
afisare<inmultiri_impartiri>;
ad_scd_inm_imp<-4*2-3+5/2*5;
afisare<ad_scd_inm_imp>;
negativ<-invers<2>;
afisare<negativ>;
daca(invers<inmultiri_impartiri> smaller_than 0)
antunci
inceput_bloc_if
pentru contor1 from 0 to 10 executa
inceput_bloc_for
afiseaza<#for1#>;
afiseaza<#for2#>;
sfarsit_bloc_for
sfarsit_bloc_if
altfel
inceput_bloc_if
afiseaza<#if#>;
sfarsit_bloc_if
cat_timp contor2 greater_than 0
inceput_bloc_cat_timp
afisare<#cattimp#>;
contor<-contor-1;
sfarsit_bloc_cat_timp
pozitiv<-invers<-2>;
afisare<pozitiv>;
var1<-oglindit<321>;
afisare<var1>;
s<-suma<1,3,12,31,oglindit<123-2>>;
afisare<s>;
afisare<#ProgramTerminat#>;
stop_program
I don't know where it could be wrong , is because of the lexical rules , are they interfering with each other?
Thank you.
EDIT
error mesage : error: syntax error at line:1
The exact problem is that the parser sees a non valid rule at my "&librarie=>stringuri" declaration , in my file. (line 1)

How do I find and replace substrings through regular expressions in Matlab

I am using Matlabs regular expression function regexprep() to find and replace strings in a .c file
I have been trying to take the following strings in the .c file:
var[12] = powmacro(var[11],"name11",var[25],"name25");
var[13] = divmacro(var[23],"name23",var[12],"name12");
...and convert them to the following format:
var[12] = var[11]^var[25]
var[13] = var[23]/var[12]
Any ideas on how I can do this?
Here is an example code:
% regular expression patterns
re_sp = '\s*';
re_str = [re_sp '"[^"]*"' re_sp];
re_var = [re_sp '(var\[\d+\])' re_sp];
re_pow = [re_var '=' re_sp 'powmacro' re_sp '\(' ...
re_var ',' re_str ',' re_var ',' re_str ')' re_sp ';'];
re_div = [re_var '=' re_sp 'divmacro' re_sp '\(' ...
re_var ',' re_str ',' re_var ',' re_str ')' re_sp ';'];
% replace patterns in strings
str = {'var[12] = powmacro(var[11],"name11",var[25],"name25");' ;
'var[13] = divmacro(var[23],"name23",var[12],"name12");'};
str = regexprep(str, re_pow, '$1 = $2 ^ $3');
str = regexprep(str, re_div, '$1 = $2 / $3');
disp(str)
The result:
>> str
str =
'var[12] = var[11] ^ var[25]'
'var[13] = var[23] / var[12]'

ANTLR4 Mutually Left-recursive Error When Parsing C++ Source

I'm trying to parse a subset of cpp source syntax. The follow ANTLR4 parser rules are directly copied from the c++ language specification (except hypens are replaced by underscores):
abstract_declarator:
ptr_operator abstract_declarator?
| direct_abstract_declarator
;
direct_abstract_declarator:
direct_abstract_declarator? '(' parameter_declaration_clause ')' cv_qualifier_seq? exception_specification?
| direct_abstract_declarator? '[' constant_expression? ']'
| '(' abstract_declarator ')'
;
But I got this error when org.antlr.v4.Tool is parsing the grammar:
error(119): cppProcessor.g4::: The following sets of rules are mutually left-recursive [direct_abstract_declarator]
It seems that direct_abstract_declarator? syntax at the left hand side causes the error. How should I correct it? Why can't ANTLR4 support it?
Manually refactoring the rules to this form doesnt produce the error:
direct_abstract_declarator:
direct_abstract_declarator '(' parameter_declaration_clause ')' cv_qualifier_seq? exception_specification?
| '(' parameter_declaration_clause ')' cv_qualifier_seq? exception_specification?
| direct_abstract_declarator '[' constant_expression? ']'
| '[' constant_expression? ']'
| '(' abstract_declarator ')'
So is it possible for ANTLR4 to support the first syntax directly when handling left recursive rules?
ANTLR 4 supports direct left recursion, but not indirect or hidden left recursion. You can address the situation above by explicitly expanding the optional construct.
direct_abstract_declarator
: direct_abstract_declarator '(' parameter_declaration_clause ')' cv_qualifier_seq? exception_specification?
| direct_abstract_declarator '[' constant_expression? ']'
| '(' parameter_declaration_clause ')' cv_qualifier_seq? exception_specification?
| '[' constant_expression? ']'
| '(' abstract_declarator ')'
;

Visual C++ compiling error

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.