C++ :: Writing Simple Compiler For A Language

Mar 13, 2014

I have a problem about compiler.I want to write a simple compiler for a language.

stm -> id := expr
| print expr
| if expr then stm
| while expr do stm
| begin opt_stmts end

[Code] .....

I guess I should create main.c to convert source code.Also,I should create a source.c to write a example program that is relevant with above grammar.

View 1 Replies


ADVERTISEMENT

C++ :: Simple Class Usage Compiler Error

May 12, 2013

Full disclosure: this is an exercise from "Sams Teach Yourself C++ in 24 Hours" by Jesse Liberty and Rogers Candenhead. This refers to Chapter 9 (Hour 9 Activity 1)

I created a class called Point, in Point.h

I created a class called Rectangle in Rectangle.h and Rectangle.cpp

If I create an int main() function in Rectangle.cpp (that includes Rectangle.h), I can compile Rectangle.cpp and run the resulting program. Fine.

Question:

I create a separate file called main.cpp. I include Rectangle.h. But now the compiler complains.

Code:
$ g++ main.cpp -o main
/tmp/cc38JIph.o: In function `main':
main.cpp:(.text+0x26): undefined reference to `Rectangle::Rectangle(int, int, int, int)'
main.cpp:(.text+0x32): undefined reference to `Rectangle::getArea() const'
collect2: ld returned 1 exit status If I can create a class in Point.h and use it in Rectangle.h, why can I not just use Rectangle in main.cpp?

And the files, of course:

file: main.cpp
Code:
#include <iostream>
#include "Rectangle.h"
using std::cout;
using std::endl;

[Code] .....

View 3 Replies View Related

C++ :: Writing A Simple Copy Constructor

Dec 10, 2012

Code:
class Matrix4 {
Matrix4(float mat[4][4]) {
memcpy (m, mat, 16);
}
float m[4][4];
};

float m[4][4];
cam->getProj(m);
Matrix4 matProj(m);

The above snippet doesn't compile, correcting mistakes in syntax.

View 13 Replies View Related

C/C++ :: Simple Logic Error While Writing To XML File

Sep 15, 2014

I created a program to convert files to XML. This if statement is giving me some trouble. I am trying to replace all &s with the XML & so that &s will work in the entities of the XML file. Some entities have more than 1 &. With those which have more than one I get an output like this: <cit:district>Anambra & Enugu & Eb</cit:district> .

if(word.find("&") != string::npos) {
word.replace(word.find("&"), 1, "&");
}

View 2 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 :: How To Program A Virus With Language

Oct 3, 2013

i'm student in computing science , i want to specialize in IT security and the first step i think is to know how to program a virus and understand how it works and how to stop it now i'm just a beginner I look for a way forward , i need some tips where can i begin? What are the basics of IT security? What programming language should I learn?

View 3 Replies View Related

C :: Language Syntax Checking

Jun 15, 2013

Q. In context of C language syntax checking, which of the following can be modeled using Finite Automata?

(A) Detecting proper termination of an instruction.
(B) Detecting balance of parentheses.
(C) Detecting initialization of a variable.
(D) None of the above.

View 4 Replies View Related

C :: USB To Serial Communication Using Language

Dec 18, 2013

I have to communicate between two laptops using USB-to-Serial adapter. I have written 2 programs one for sending and another for receiving. Programs were written in both C and C# programming languages.

Using C language: I am able to successfully communicate using C-Programs mentioned below. But the problem is speed. It takes around 1 hour(60min) for just to pass 150MB. improving the performance of this programs...I also mention some comments along with programs for self understanding.Sender File on laptop with serial port :

Code:

#include <stdio.h>
#include <bios.h>
#include <conio.h>
}

[code]....

The above 4 programs behaves as, sender send a character and receives an ack for every character. I have followed this approach, bcoz other approaches were not working fine (in the sense the complete data is not sent, the amount of data sent is not judgeable, bcoz it will different every tym). when i used this approach it worked fine.

View 6 Replies View Related

C++ :: Compilation In Machine Language

Jan 25, 2013

Have a program which given a C source code file, gives back RAW MACHINE CODE, which means it doesn't have to be a executable on his own.

Like:

Given a example function for C:

int stdcall Function(void)
{
return 0;
}

Gives back the Machine Code for the Example Function.

It doesn't need to be actual C code, it can also be like:

type int
return 0

Or also it can be a straight assembly-to-machine-code compiler.

Is there any Library? Or even a external tool I can look into?

View 4 Replies View Related

C :: Opening Audio File Using Language

Sep 6, 2013

how to open an audio file using c. write a code to open an audio file.

View 2 Replies View Related

C :: Convert Decimal To Binary On Language

Nov 15, 2013

The goal of my program is to convert a decmial number to a binary number.First, the program gets an input to an array of chars, and the function translate_dec_bin converts this array to a decimal number through the strtoul function.The problem is that my program prints the binary number with an additional "0".For exmaple, for the input 1 - the program prints 01 instead of 1, for the input 3 - the program prints 011 instead of 11.

Code:

#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 20
void translate_dec_bin(char s[]){
char st[sizeof(unsigned)*20] = { 0 };
}

[code]....

View 2 Replies View Related

C/C++ :: Automata - Tell Whether A String Is Accepted By Language

Sep 27, 2014

I have a program that reads a text file and then outputs the corresponding transition table according to the regular expression given in the text file. The first line that is read by the code contains the transition table. The subsequent lines of the text files include the strings. I want my code to read the strings in the subsequent lines of the text file and tell me whether the string is accepted or not by the language. Basically, what my code does is that it translates the regular expression to an NFA and then, it translates the NFA to a DFA and then it builds a transition table according to the language.

I have included a special library in my code and I compiled my code from the command line using the following command:

gcc -o lalab lalab.c -lncurses
then, I just run the program like this:
./lalab

Another problem that I have is that my code does not handle the empty transitions, so the program should output a corresponding result when it is fed a regular expression such as a|e. The alphabet of the language is made of {a, b, e} e is the empty transition. The text file that the program reads from includes a regular expression in its first line and strings to be accepted or not in the following lines. Given an input file like this:

(a|b)*a
aaaa
aba
bba
ab
bbb
:frown:

The code should produce an output like this:

yes
yes
yes
yes
no
no

Code:
#include<stdio.h>
#include<conio.h>
#define MAX 20

//=========================================================
struct nfa_state {
int a, b, eps1, eps2;
}NFA[20];

[Code] .....

View 8 Replies View Related

C/C++ :: Vector Outputs Alien Language?

Oct 19, 2014

Program:I have 2 arrays: 1 for the correct answers to a quiz, 1 for the user. I then have a vector to hold the incorrect answers.

It keeps outputting what looks like alt characters, why.

Here is the code:

#include <iostream>
#include <vector>
using namespace std;
int main() {
const char a1[]={'a','d','b','b','c','b','a','b','c','d','a','c','d','b','d','c','c','a','d','b'};
char a2[20];
int i=0;
int incorrect=0;

[code].....

View 1 Replies View Related

C/C++ :: What Settings Has To Be Made To Run Language In Jgrasp

Nov 25, 2012

Running c in jgrasp.. i am getting error has gcc not found.

View 4 Replies View Related

C :: How To Convert Assembly Language In Txt File To S19 Format

Apr 25, 2013

a few pointers in building an assembler in C for a 68hc11 micro controller I'm struggling on a way to convert the assembly language in a txt file to s19 format.

View 1 Replies View Related

C# :: Way To Build Project To Dynamic Linking Language

Dec 28, 2011

I have a project C# and i want to build it to .dll for use in ASP.Net project . Any way to do it. It look like my attachments image .

View 1 Replies View Related

C++ :: Create Symbol Table For Assembly Language?

Jan 21, 2013

how to create a symbol table for an assembly language and high level language program in c++

View 1 Replies View Related

C :: Language Program Environment Does Nothing To Prevent Buffer Overflows

Sep 25, 2013

TheC language program environment does nothing to prevent buffer overflows ..... is there any pros to the obvious cons of this?

View 3 Replies View Related

C++ :: Create Symbol Table For High Level Language?

Jan 21, 2013

How to create a symbol table for an assembly language and high level language in c++?

View 1 Replies View Related

C++ :: Using GNU GCC Compiler

Jun 9, 2014

I am programming with the Code::Blocks IDE and using the GNU GCC compiler. When I create an simple console application that uses strings it kind of glitches out, but here's the code:

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
ered: " << x;

[code].....

What the output is:

Please enter a string of text: Hello World
You entered: Hello
Process returned 0 (0x0) execution time : 4.735 s
Press any key to continue.

Anyway I don't know why it removes what I typed after the space I put in between Hello and World.

View 1 Replies View Related

C :: Gcc Compiler And Pointers

Mar 3, 2013

The first sample program that I am reading on the book has the following code:

Code:

* Demonstrates basic pointer use. */
#include <stdio.h>
/* Declare and initialize an int variable */
int var = 1;
}

[code]....

Is this a compiler error or is there a proper syntax for pointers using the gcc compiler?

View 3 Replies View Related

C++ :: Class Not Seen By Compiler?

Sep 18, 2014

I have an issue. VS 2013 isn't recognizing objects that I've declared when I use class functions.I'm getting this error: "Line 14 and 15: Error C2228: left of '.asciiToFpc6' must have class/struct/union"...Here's the relevant code:

Source.cpp

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include "fpc6.h"

[code].....

Additionally VS apparently doesn't like my bitwise operators in my class functions and doesn't think they're doing anything. It gives "warning C4552: ['|', '<<', '>>', '&'] : operator has no effect; expected operator with side-effect" for all of them, but it seems to me the code should work fine and actually accomplish things....

View 9 Replies View Related

C++ :: Compiler Says There Is No Constructor But It Does Have One

May 29, 2013

Code:
activity = new Idle(this, NULL);
class Idle : public Activity {
private:
float mTimeInIdle;
public:
Idle() : mTimeInIdle(0) { }
Idle(Objects *actor, Goods *target) : Activity(actor, target)
{
}

Error 1 error C2514: 'Idle' : class has no constructors d:jackydocumentsvisual studio 2010projectsperfectsimperfectsimperfectsimObjectsObjects.h 43 1 PerfectSim

The activity = new Idle(this, NULL) line is located inside the Objects::Objects(...) constructor.

Would it be caused by some cyclic dependencies? How do I go about resolving it?

View 3 Replies View Related

C++ :: Compiler Optimization And Num Accuracy?

Jun 11, 2014

I could not find anything I could understand on this, so I have heard that -O3 option may reduce the numerical accuracy of doubles. Is this true?

View 11 Replies View Related

C :: Compiler Keeps Freezing / Crashing

Feb 11, 2014

I wrote this code as an assignment

Code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main(){

int story, age=0;
int ranColor, ranCar, ranItem;

[Code] ....

And my compiler keeps freezing/crashing. using Dec C++

View 4 Replies View Related

C++ :: Compiler Not Recognizing Numbers

Sep 8, 2013

I'm working on this homework assignment where the program takes in the user's height in inches, weight in pounds, and age, then calculates their hat size, jacket size and waist size. The formulas for these are as follows:

Hat: (weight/height) x 2.9

Jacket: (height x weight)/288 then adjusted by adding 1/8 an inch for every 10 years over the age of 30 (The adjustment only takes place after a full 10 years, so there is no adjustment for 30-39, but there is for 40)

Waist: (weight/5.7) then adjusted by adding 1/10 of an inch for each 2 years over the age of 28 (the adjustment only takes place after a full 2 years, so no adjustment for 29, but there is for 30, etc)

I'm supposed to utilize functions for each of the three formulas.

There's a couple things I can't figure out.

1. Why won't the compiler recognize 2.9 and 5.7 as numbers?

2. How do I adjust the calculation for the jacket and waist based on age?

Here's what I've got so far:

#include <cstdlib>
#include <iostream>
using namespace std;
double hatSize(int weight, int height);
double jacketSize(int weight, int height, int age);
double waistSize(int weight, int height, int age);

[code]....

View 1 Replies View Related







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