4 Replies - 425 Views - Last Post: 04 December 2012 - 06:24 PM Rate Topic: -----

#1 yotic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 11-October 11

recursive descent parser unresolved lnk errors

Posted 04 December 2012 - 04:57 PM

so i have this code that i have to configure to scan a file and read the info in the file to determine whether it is what it is, meaning that if the first line is a string, then it will know and output such, and so on and so forth with numbers and characters. The issue im having is that i have 2 unresolved errors and i have no idea how to fix them.
any help at all will be greatly appreciated

#include <iostream>
#include <iomanip>
using namespace std;

typedef enum {ident, number, lparen, rparen, times, slash, plus,minus, eql, neq, lss, leq, gtr, geq, 
	callsym, beginsym, semicolon,endsym, ifsym, whilesym, becomes, thensym, 
	dosym, constsym, comma,varsym, procsym, period, oddsym} Symbol;


Symbol sym;
void getsym(void);
void error(const char msg[]);
void expression(void);
 
int accept(Symbol s) 
{
    if (sym == s)
	{
        getsym();
        return 1;
    }
    return 0;
}
 
int expect(Symbol s) 
{
    if (accept(s))
	{
        return 1;
	}
    error("expect: unexpected symbol");
    return 0;
}
 
void factor(void) 
{
    if (accept(ident))
	{
        //;
    } 
	else if (accept(number)) 
	{
        //;
    } 
	else if (accept(lparen)) 
	{
        expression();
        expect(rparen);
    } 
	else 
	
	{
        error("factor: syntax error");
        getsym();
    }
}
 
void term(void) 
{
    factor();
    while (sym == times || sym == slash) 
	{
        getsym();
        factor();
    }
}
 
void expression(void) 
{
    if (sym == plus || sym == minus)
	{
        getsym();
	}
    term();
    while (sym == plus || sym == minus) 
	{
        getsym();
        term();
    }
}
 
void condition(void) 
{
    if (accept(oddsym)) 
	{
        expression();
    } 
	else 
	{
        expression();
        if (sym == eql || sym == neq || sym == lss || sym == leq || sym == gtr || sym == geq) 
		{
            getsym();
            expression();
        } else {
            error("condition: invalid operator");
            getsym();
        }
    }
}
 
void statement(void) 
{
    if (accept(ident)) 
	{
        expect(becomes);
        expression();
    } 
	else if (accept(callsym)) 
	{
        expect(ident);
    } 
	else if (accept(beginsym)) 
	{
        do 
		{
            statement();
        } 
		while (accept(semicolon));
        expect(endsym);
    } 
	else if (accept(ifsym)) 
	{
        condition();
        expect(thensym);
        statement();
    } 
	else if (accept(whilesym)) 
	{
        condition();
        expect(dosym);
        statement();
    } 
	else 
	{
        error("statement: syntax error");
        getsym();
    }
}
 
void block(void) {
    if (accept(constsym)) 
	{
        do 
		{
            expect(ident);
            expect(eql);
            expect(number);
        } while (accept(comma));
        expect(semicolon);
    }
    if (accept(varsym)) 
	{
        do 
		{
            expect(ident);
        } while (accept(comma));
        expect(semicolon);
    }
    while (accept(procsym)) 
	{
        expect(ident);
        expect(semicolon);
        block();
        expect(semicolon);
    }
    statement();
}
 
void main()
{
    getsym();
    block();
    expect(period);
	return;
}



Is This A Good Question/Topic? 0
  • +

Replies To: recursive descent parser unresolved lnk errors

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2117
  • View blog
  • Posts: 3,242
  • Joined: 21-June 11

Re: recursive descent parser unresolved lnk errors

Posted 04 December 2012 - 05:21 PM

View Postyotic, on 05 December 2012 - 12:57 AM, said:

The issue im having is that i have 2 unresolved errors and i have no idea how to fix them.


Neither does anyone else given that you didn't even tell us what those errors are.
Was This Post Helpful? 0
  • +
  • -

#3 yotic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 11-October 11

Re: recursive descent parser unresolved lnk errors

Posted 04 December 2012 - 05:23 PM

1> All outputs are up-to-date.
1>pars.obj : error LNK2019: unresolved external symbol "void __cdecl getsym(void)" (?getsym@@YAXXZ) referenced in function "int __cdecl accept(enum Symbol)" (?accept@@YAHW4Symbol@@@Z)
1>pars.obj : error LNK2019: unresolved external symbol "void __cdecl error(char const * const)" (?error@@YAXQBD@Z) referenced in function "int __cdecl expect(enum Symbol)" (?expect@@YAHW4Symbol@@@Z)
1>c:\users\soyo\documents\visual studio 2010\Projects\parser2\Debug\parser2.exe : fatal error LNK1120: 2 unresolved externals
1>
1>Build FAILED.
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2117
  • View blog
  • Posts: 3,242
  • Joined: 21-June 11

Re: recursive descent parser unresolved lnk errors

Posted 04 December 2012 - 05:27 PM

Okay, so it says it can't find the definitions of the functions getsym and error. Where did you define those functions?
Was This Post Helpful? 0
  • +
  • -

#5 yotic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 11-October 11

Re: recursive descent parser unresolved lnk errors

Posted 04 December 2012 - 06:24 PM

i see what your saying, but how can i define those functions to read in a text file and use the text file as input? here is an example of the txt file below

read
A
read
B
sum
:=
(
A
+
B
)
*
45.325
write
sum
write
sum
*
80.777
-
A
$$



another note, the $$ at the end will let the program know when to stop parsing, but that should be easy to setup.

this is the calculator language my teacher refers to, or at least thats what he calls it.

program → stmt_list $$
stmt_list → stmt stmt_list | ε
stmt → id := expr | read id | write expr
expr → term term_tail
term_tail → add_op term term_tail | ε
term → factor fact_tailt
fact_tail → mult_op fact fact_tail | ε
factor → ( expr ) | id | number
add_op → + | -
mult_op → * | /



also here is what the, so called, expected output is suppose to look like but im sure mine wont since im just gonna make it simple to read.

Executing: program() stmt_list() stmt()
Token: read consumed
Token: A consumed
Executing: stmt_list() stmt()
Token: read consumed
Token: B consumed
Executing: stmt_list() stmt()
Token: sum consumed
Token: := consumed
Executing: expr() term() factor()
Token: ( consumed
Executing: expr() term() factor()
Token: A consumed
Executing: factor_tail() term_tail() add_op()
Token: - consumed
Executing: term() factor()
Token: B consumed
Executing: factor_tail() term_tail()
Calling match("")""):
Token: ) consumed
Executing: factor_tail() mult_op()
Token: * consumed
Executing: factor()
Token: 45.325 consumed
Executing: factor_tail() term_tail() stmt_list() stmt()
Token: write consumed
Executing: expr() term() factor()
Token: sum consumed
Executing: factor_tail() term_tail() stmt_list() stmt()
Token: write consumed
Executing: expr() term() factor()
Token: sum consumed
Executing: factor_tail() mult_op()
Token: * consumed
Executing: factor()
Token: 80.777 consumed
Executing: factor_tail() term_tail() add_op()
Token: - consumed
Executing: term() factor()
Token: A consumed
Executing: factor_tail() term_tail() stmt_list() stmt_list()
Token: $$ consumed
-----------------------
No Error was generated



hope this helps a little

This post has been edited by yotic: 04 December 2012 - 06:31 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1