Visual C++ :: Writing A Lexical Analyzer / Parser

Oct 6, 2012

I'm trying to learn more about how Lexical Analyzers/Parsers work. I haven't coded any classes yet, because i'm not really sure how the entire process from a Lexer to working code goes.

My goal is to write a simple made up programming language and translate that to another language, like Javascript. The first thing i have to do is give the code to a Lexical Analyzer.

The lexer will split the source into tokens and assign a label to it. So suppose i have the following code:

Code:
def myVar = 10;

The lexer will split that into token like this:

Code:
def -> keyword
myVar -> Identifier
= -> Operator
10 -> Number

That's basically as far as i understand what a lexer does. How can i translate the tokens to a language like Javascript? From what i understand i need to write a Parser class. But i couldn't find any info on what that class exactly does. So what is exactly the next step i have to take?

View 2 Replies


ADVERTISEMENT

C++ :: Lexical Analyzer Code Error

Mar 17, 2013

i am running this code but i am geting few errors .as shown in the image

Code:
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <string>
using namespace System;

[Code] .....

View 7 Replies View Related

Visual C++ :: Creating Code Analyzer Tool For Project?

Sep 10, 2013

I am creating an application which will work as a static code analyzer after compiling my code in VS 2008 for VC++ projects. It will be a kind of code review.

how and where do I need to put my custom rule sets, and what should I do to create such a application.

View 4 Replies View Related

C :: Writing A Simple File / Text Parser To Read A Config File

Feb 6, 2014

I am writing a simple file/text parser to read a config file for some code I am working on. It's dead simple and not particularly smart but it should get the job done. The code reads a config file:

Code:

readlength=2500000
start=0
finish=25000000
cutoff=20000
samplingfreq=250000
poles=10
filterpadding=500
}

[code]....

Here is where it gets wierd. You'll notice that there is an unused variable (filepath) in the config struct. This variable is not referenced or used anywhere in the code, ever. Yet if I comment out the declaration of char filepath[1024], the code segfaults partway through the read_config() function.

My best guess is that there is a buffer overflow elsewhere and it just so happens that the memory allocated for filepath happened to be there to catch it up until now, but I can't work out where it might be happening. With the declaration commented out, the read_config() function gets as far as reading the "padding" variable before it crashes. Yet when the declaration is there, then all the variabled are read correctly and everything seems to work.

View 10 Replies View Related

C++ :: Sorting Strings / Arrays In A User Defined Lexical Order?

May 7, 2013

I previously tried to put strings in an array, but i couldn't modify the first index in the string that is in the array. I changed my code later.

[URL]

Suggest a function that sorts the inputs vertically according to the order given by the user? I made this one

void order(string order, char index[][15]){
int counter=0,line=0,i=0,j=0;
for(i=0;i<=15-1;i++)
{for(j=0;j<=15-1;j++) {
if(index[j][i]==order[counter])

[code].....

View 1 Replies View Related

Visual C++ :: File Writing With Onsavedocument

Oct 15, 2012

Code:
void CFileMgm::write(string fname, solutions databox) {
file1.open (fname.c_str(), ios::out);
if (file1.is_open())//if(file)+ {
file1<<"Population Size is : ";
file1<<databox.pop_size;

[Code] ....

I don't know why this code is unable to write any thing in file. Following is onsavedocument function

Code:
BOOL CTspGeneticAlgoDoc::OnSaveDocument(LPCTSTR lpszPathName) {
string filename = (string) lpszPathName;
CFileMgm mydatafile;
mydatafile.write(filename,sol);
return CDocument::OnSaveDocument(lpszPathName);
}

View 3 Replies View Related

Visual C++ :: Reading / Writing Registry In Windows 7?

Feb 19, 2013

I have a 32-bit application that I've been maintaining for about 12 years and it runs on every Windows platform up to Windows 7. In all that time I've been using CWinApp::GetProfileXxxx() and CWinApp::WriteProfileXxxx() calls to read and write my program settings (about 70 settings) in the Registry. The settings are read from the Registry at start-up and written to the Registry when the program closes. There is also a method for the user to read and write the program settings to an INI file using the same code as the Registry access.

On my Windows 7 system the Registry read/write works just like it always has on all previous Windows versions. However, on some customer's Windows 7 machines there appears to be a problem with the Registry access. The program settings are either not being read from the Registry or are not being written to the Registry. I think the settings are not being written - but I don't know that. When the user uses the INI file the settings appear to be read and written.

The customer has complained a bit (I'd complain too) but doesn't have the time or doesn't want to take the time to run some simple tests for me to find out what's going on with his Windows 7 system.

So here is my question: Are there any user account settings or permissions that can block the program's access to the Registry? He claims he is an Administrator but I can't even get him to verify that.

View 5 Replies View Related

Visual C++ :: Writing Structure To CSV File Won't Work

Jan 23, 2013

I need to compute some values, place them in a structure containing two vector variables, and save them in a CSV file. Right now, I can't even generate a file. I wrote the structure definition and file writing code in a header file (after first borrowing it). I have a "button" that is supposed to trigger all of the activity. I'll attach the code below:

HEADER
________-----_______------
#ifndef EINSTEIN_H
#define EINSTEIN_H
#include <stdio.h>
struct SizeAll{
int year;
double R;
};
int write_to_file(int count, struct SizeAll *data, char const *fileName)

[code].....

My grasp of pointers and how and when to use them evaporated long ago.

View 14 Replies View Related

Visual C++ :: Writing To HKLM Registry In Windows 7?

Jul 8, 2013

When I write to the Windows 7 Registry at HKEY_LOCAL_MACHINE, I get a return code of 5 which is the "access denied" message when I execute RegCreateKeyEx.

This happens even if the User has administrator rights.

How can I tell Windows 7 to allow the program to write to the registry?

The application is a 32-bit application and it should be allowed to run in either a Windows 7 32-bit or 64-bit machine.

I noticed that when I run certain popular programs, a User Account Control dialog box comes asking:

"Do if you want to allow the following program from an unknown publisher to make changes to this computer".

Should my application call User Account Control and if so, how do I do it in C++ Visual Studio 2008?

I also found out that 64-bit Windows machines have two registry hives. Is there a different code to handle the same task?

View 8 Replies View Related

Visual C++ :: Writing Formula For Standard Deviation?

Apr 17, 2013

How to write a formula for standard deviation but im having a hard time ?

View 2 Replies View Related

Visual C++ :: Writing And Reading Char Bytes?

Jun 26, 2013

I have used the following code to write and read wchar_t bytes from a disk file:

Code:
int WriteBytesW(wchar_t * wcp, int nsz, wchar_t * wcfilepath) {
wfstream wf;
codecvt_utf16<wchar_t, 0x10ffff, little_endian> ccvt(1);
locale wloc(wf.getloc(), &ccvt);
wf.imbue(wloc);

[Code] ....

Output:

save bytes succeeded
1234 5678 9ABC EF12 ABCD FE21 DCBA 1F2A EFFF 02FF
read bytes succeeded
nsz =: 20

Now, if wbuf[8] = 0xefff; is replaced by wbuf[8] = 0xffff;

Output:

save bytes succeeded
1234 5678 9ABC EF12 ABCD FE21 DCBA 1F2A 02FF
read bytes succeeded
nsz =: 18

Obviously, the 0xffff wbyte is not read. WHY ?

This presents a significant problem when attempting to read ALL wbytes from a file.

View 9 Replies View Related

Visual C++ :: Reading And Writing Values From Excel Spreadsheet

Jul 31, 2013

I just got a job programming a windows application. One of the requirements is reading and writing values from an excel spreadsheet. Looking online, it appears that C++ isn't the best (one of the worst?) languages for reading and writing values from excel files. Now the language I'm most familiar with is C++ and I've been looking at C#, and it appears to be much easier to read excel files.

View 8 Replies View Related

Visual C++ :: Writing A Function That Sort Elements Of Array In Numerical Order?

Oct 17, 2014

I have to write a function called sortMe that sorts the elements of an array in numerical order from highest to lowest values (descending order) or vice versa (ascending order).

The assignment asks to: NOT re-arrange elements in the array; instead, it uses a second array, an array of indexes for the elements in the original array and then sortMe sorts the second array based on the values in the original array. A sorted version of the original array can then be produced with these sorted indexes.

Header of the function sortMe must be as shown below:

void sortMe(int array[],int sortedIndexes [], int size, char mode)

When mode is 'a', the function sorts the array in the ascending order, and when mode is 'd', the function sorts it in the descending order.

Declare and initialize the array array.

Declare the array sortedIndexes but do not initialize it. You are going to play with the array sortedIndexes in the function sortMe.

EXAMPLE:

int array[5]={3, 5,-1,10,0};
int sortedIndexes[5];
sortMe(array,sortedIndexes, 5, 'a');

After the function call, the elements of the array sortedIndexes should be: 2,4,0,1,3.

notice that the function does not e-arrange the elements in the array.

Code:
#include <iostream>
using namespace std;
void sortMe(int[], int, char);
void main() {
int arr[6] = { 14, -5, 5, 0, 22, -99 };

[code]...

how to use the other array.

View 5 Replies View Related

Visual C++ :: Enable Writing To And Reading From Files - Unresolved External Symbol

May 13, 2013

Perhaps this can be a very popular error,

Code:

#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <fstream>// enable writing to and reading from files
#include <cstdlib>
#include <time.h>
using namespace std;
class Person {

[Code] .....

Error list:

Code:

Error 1 error LNK2019: unresolved external symbol "void __cdecl saveperson(void)" (?saveperson@@YAXXZ) referenced in function _main H:Cry_DevProgrammingC++Using_class_ in_ c++Using_class_ in_ c++Using_class_ in_ c++.obj
Error 2 error LNK2019: unresolved external symbol "void __cdecl displayperson(void)" (?displayperson@@YAXXZ) referenced in function _main H:Cry_DevProgrammingC++Using_class_ in_ c++Using_class_ in_ c++Using_class_ in_ c++.obj
Error 3 error LNK2019: unresolved external symbol "void __cdecl editperson(void)" (?editperson@@YAXXZ) referenced in function _main H:Cry_DevProgrammingC++Using_class_ in_ c++Using_class_ in_ c++Using_class_ in_ c++.obj
Error 4 error LNK1120: 3 unresolved externals H:Cry_DevProgrammingC++Using_class_ in_ c++DebugUsing_class_ in_ c++.exe 1

What I can do to fit this problem?

View 14 Replies View Related

C :: Simple File Parser

Oct 5, 2013

I am writing a simple file parser for use in another project (for config file). The trickiest thing seems to be skipping unwanted characters (comments, spaces). It works partly, but after the second line of an inputed file processes only the first three characters.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TEXT_FILE "data.txt"
[code]....

NOTE: Currently I am just trying to process and remove unwanted data, the actual processing of extracted data should be much simpler.

View 6 Replies View Related

C/C++ :: Recursive Descent Parser?

Mar 22, 2014

I am implementing a recursive descent parser that recognizes strings in the language below.

The grammar:
A -> I = E | E
E -> T + E | T - E | T
T -> F * T | F / T | F
F -> P ^ F | P
P -> I | L | UI | UL | (A)
U -> + | - | !
I -> C | CI
C -> a | b | ... | y | z
L -> D | DL
D -> 0 | 1 | ... | 8 | 9

My input file has the following two strings:
a=a+b-c*d
a=a**b++c

The desired output:

String read from file: a=a+b-c*d
The string "a=a+b-c*d" is in the language.
String read from file: a=a**b++c
The string "a=a**b++c" is not in the language.

[Code].....

When I test the code without reading the text file and just write a string in the source code, it appears to parse fine. I believe my main problem is in the int main function and how i am reading the text file and outputting it. I was able to write the same program fine in Java.

View 3 Replies View Related

C++ :: Expression Parser Implementation?

May 5, 2014

How can we implement an expression parser in C++.

View 3 Replies View Related

C++ :: Running A SLR Parser Program?

Apr 27, 2012

I need to run a program that makes a SLR Parser Table.

Here is the code :

Code to find first and follow:

saved as SLR.h
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream.h>
#define epsilon '^'

since I didn't know how to type epsilon symbol temporarily I am using ^

char prod[20][20],T[20],NT[20],c[10][10],foll[10][10],fir[10][10];
int tt,tnt,tp,a;
int follow[20][20],first[20][20];
void first_of(char);
int count(int j);
void rhs(int j);

[code]....

View 3 Replies View Related

C++ :: Parser Does Not Name A Type Error

Oct 22, 2014

I am trying to write a program that reads in an XML file, parses it and prints out information about each tag. I am getting the following errors when trying to build the program:

Parser.cpp:24:1: error: 'Parser' does not name a type
Parser::getXMLData() {
^
Parser.cpp:120:1: error: 'Parser' does not name a type
Parser:rocessXMLData(

[Code] ....

Here is my code for the 5 files.

[ATTACH]main.cpp
[/ATTACH][ATTACH]Parser.h
[/ATTACH][ATTACH]Parser.cpp
[/ATTACH][ATTACH]Element.h
[/ATTACH][ATTACH]Element.cpp[/ATTACH]

View 5 Replies View Related

C :: Visual Studio 2012 - Writing Data Into TXT File / How To Stop Reading Char

Feb 23, 2013

I am using visual studio 2012.....in below code i m writing data in to a test.txt file but i dont know with which key file stop accepting char...i tried ctrl+z and ctrl+d but not working ....

Code:
#include<stdio.h>
#include<conio.h>
main(){
char ch;
FILE *ptr;

[Code] ....

View 7 Replies View Related

Visual C++ :: Writing To Named Pipe Coming From A Service (session 0) Without Admin Rights

Dec 9, 2014

I'm trying to write to a named pipe created by a service, as we all know the session 0 isolation implemented in vista and forward makes this task a bit complicated.

well at this point i managed to make almost all to work but my real problem comes when i try to write on the named pipe from my GUI application with no administrator rights

If i run the GUI application with admin rights it works 100% but, I don't need that application to require the user admin rights and for security reasons i rather to leave it without admin...

so i started my research and i found that there is a way to achieve this by calling CreateNamedPipe() with a low integrity security attributes...

well how to implement but i finally made it, the problem is that it gets worse than passing null security attributes, it works with admin rights with NULL security attributes, but when i pass the low integrity security attributes it gives "access denied" even when using admin rights, so i guess im passing the wrong security attributes but how to manually create the security descriptor string.

This is the code:

Service (session0) SERVER

Code:
DWORD WINAPI PipeThreadRSVS(void* pParameter){
LPTSTR _PIPE_NAME = "\.pipeRSVHPipeIn";
bool Break=false;
char Received_Buffer[BlockSize+16];
DWORD BytesRead = 0;

[Code] ....

View 2 Replies View Related

C :: Text Parser - String Separation

Jan 4, 2015

I would like to make a sort of text parser, in which one enters a string, and it is broken by the whitespaces into chunks, and those chunks compared to different "dictionaries" where the words are assigned a value. For example if the operator enters "take lamp" it would separate "take" and "lamp" and then produce preassigned values for each of these words.

View 3 Replies View Related

C :: Simple Parser / How To Deal With Slashes

Feb 13, 2013

I've knocked up a rough C parser for the purpose of colourizing code into XHTML/CSS, which makes me feel fancy. However, it doesn't quite handle comments properly. I can't quite work out how to deal with the slashes. Plus I'm sure there are other places that it slips up that don't feature in my simple tests, so here you go:-

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FLAG_OUTPUT1
#define FLAG_EVEN2
#define NUMKEYWORDS32
}

[code]....

View 6 Replies View Related

C++ :: Getting Segmentation Fault In Parser Code

Dec 23, 2014

For some reason when i put cout<<endl i'm getting segmentation faults in my Parser code. It's really weird some inputs of strings using cout is already faulting. However sometimes printf doesn't fault, but sometimes it will, it seems really unstable.

The court can basically be anywhere in the Parse(string) function, i have a cout at line 254 which faults.

Here is the code:

#include "Parser.h"
#include <stdio.h>
#include <iostream>
using namespace std;
Parser::Parser() {

[Code] ....

View 3 Replies View Related

C++ :: CSV Parser - Infile Using Variable Filename?

Jan 18, 2013

So. I have a CSV Parser that I built. It works very well. The way it currently works is that I have the parser in a header file "CSV_Parser". So my .cpp code would look like this:

#include <iostream>
#include <eigen3/Eigen/Dense>
#include "CSV_Parser.h"
using namespace std;
using Eigen;

[Code] ....

This all works great. I am running Eclipse in Linux (Xubuntu to be precise). In the header file the .csv is opened as follows:

ifstream infile;
infile.open("/home/karrotman/Desktop/Matrix.csv");

What I would like is for the user to be able to change the file that the parser is opening through the main .cpp file. In other words, is there a way to create some variable, say "FileName" and do the following:

CSV firstMat;
string MatrixA = "/home/karrotman/Desktop/Matrix1.csv";
firstMat.extract(MatrixA);
CSV secondMat;
string MatrixB = "/home/karrotman/Desktop/Matrix2.csv";
secondMat.extract(MatrixB);

And then the .h would now say:

void extract(string FileName)
...
ifstream infile;
infile.open(FileName);

Obviously this does not work. Ultimately the goal is for me to open 4 .csvs at one time so I can do numerical operations on them.

View 2 Replies View Related

C/C++ :: How To Do Error Handling In Predictive Parser

May 9, 2014

#include<iostream>
using namespace std;
void E();
void T();
void F();
void match(char m);

[Code] ....

I have written this code for predictive parser. It is working for valid input but it is not working for invalid input when i give invalid input it says its valid. How to do error handling in predictive parser.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved