回复 2楼 C-入门
源代码(估计看不懂)
/****************************************************************************
* U N R E G I S T E R E D C O P Y
*
* You are on day 1 of your 30 day trial period.
*
* This file was produced by an UNREGISTERED COPY of Parser Generator. It is
* for evaluation purposes only. If you continue to use Parser Generator 30
* days after installation then you are required to purchase a license. For
* more information see the online help or go to the Bumble-Bee Software
* homepage at:
*
* http://www.
*
* This notice must remain present in the file. It cannot be removed.
****************************************************************************/
/****************************************************************************
* myparser.c
* C source file generated from myparser.y.
*
* Date: 12/29/10
* Time: 20:34:04
*
* AYACC Version: 2.07
****************************************************************************/
#include <yypars.h>
/* namespaces */
#if defined(__cplusplus) && defined(YYSTDCPPLIB)
using namespace std;
#endif
#if defined(__cplusplus) && defined(YYNAMESPACE)
using namespace yl;
#endif
#define YYFASTPARSER
#line 1 ".\\myparser.y"
#include <ctype.h>
#include <stdio.h>
#define YYSTYPE double /* double type for YACC stack */
#line 47 "myparser.c"
/* repeated because of possible precompiled header */
#include <yypars.h>
/* namespaces */
#if defined(__cplusplus) && defined(YYSTDCPPLIB)
using namespace std;
#endif
#if defined(__cplusplus) && defined(YYNAMESPACE)
using namespace yl;
#endif
#define YYFASTPARSER
#include ".\myparser.h"
#ifndef YYSTYPE
#define YYSTYPE int
#endif
#ifndef YYSTACK_SIZE
#define YYSTACK_SIZE 100
#endif
#ifndef YYSTACK_MAX
#define YYSTACK_MAX 0
#endif
/* (state) stack */
#if (YYSTACK_SIZE) != 0
static yystack_t YYNEAR yystack[(YYSTACK_SIZE)];
yystack_t YYFAR *YYNEAR YYDCDECL yysstackptr = yystack;
yystack_t YYFAR *YYNEAR YYDCDECL yystackptr = yystack;
#else
yystack_t YYFAR *YYNEAR YYDCDECL yysstackptr = NULL;
yystack_t YYFAR *YYNEAR YYDCDECL yystackptr = NULL;
#endif
/* attribute stack */
#if (YYSTACK_SIZE) != 0
static YYSTYPE YYNEAR yyattributestack[(YYSTACK_SIZE)];
#ifdef YYPROTOTYPE
void YYFAR *YYNEAR YYDCDECL yysattributestackptr = yyattributestack;
void YYFAR *YYNEAR YYDCDECL yyattributestackptr = yyattributestack;
#else
char YYFAR *YYNEAR YYDCDECL yysattributestackptr = (char YYFAR *) yyattributestack;
char YYFAR *YYNEAR YYDCDECL yyattributestackptr = (char YYFAR *) yyattributestack;
#endif
#else
#ifdef YYPROTOTYPE
void YYFAR *YYNEAR YYDCDECL yysattributestackptr = NULL;
void YYFAR *YYNEAR YYDCDECL yyattributestackptr = NULL;
#else
char YYFAR *YYNEAR YYDCDECL yysattributestackptr = NULL;
char YYFAR *YYNEAR YYDCDECL yyattributestackptr = NULL;
#endif
#endif
int YYNEAR YYDCDECL yysstack_size = (YYSTACK_SIZE);
int YYNEAR YYDCDECL yystack_size = (YYSTACK_SIZE);
int YYNEAR YYDCDECL yystack_max = (YYSTACK_MAX);
/* attributes */
YYSTYPE YYNEAR yyval;
YYSTYPE YYNEAR yylval;
#ifdef YYPROTOTYPE
void YYFAR *YYNEAR YYDCDECL yyvalptr = &yyval;
void YYFAR *YYNEAR YYDCDECL yylvalptr = &yylval;
#else
char YYFAR *YYNEAR YYDCDECL yyvalptr = (char *) &yyval;
char YYFAR *YYNEAR YYDCDECL yylvalptr = (char *) &yylval;
#endif
size_t YYNEAR YYDCDECL yyattribute_size = sizeof(YYSTYPE);
/* yyattribute */
#ifdef YYDEBUG
#ifdef YYPROTOTYPE
static YYSTYPE YYFAR *yyattribute1(int index)
#else
static YYSTYPE YYFAR *yyattribute1(index)
int index;
#endif
{
YYSTYPE YYFAR *p = &((YYSTYPE YYFAR *) yyattributestackptr)[yytop + index];
return p;
}
#define yyattribute(index) (*yyattribute1(index))
#else
#define yyattribute(index) (((YYSTYPE YYFAR *) yyattributestackptr)[yytop + (index)])
#endif
#ifdef YYDEBUG
#ifdef YYPROTOTYPE
static void yyinitdebug(YYSTYPE YYFAR **p, int count)
#else
static void yyinitdebug(p, count)
YYSTYPE YYFAR **p;
int count;
#endif
{
int i;
yyassert(p != NULL);
yyassert(count >= 1);
for (i = 0; i < count; i++) {
p[i] = &((YYSTYPE YYFAR *) yyattributestackptr)[yytop + i - (count - 1)];
}
}
#endif
#ifdef YYPROTOTYPE
void YYCDECL yyparseraction(int action)
#else
void YYCDECL yyparseraction(action)
int action;
#endif
{
switch (action) {
case 0:
{
#ifdef YYDEBUG
YYSTYPE YYFAR *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 11 ".\\myparser.y"
printf("%g ", yyattribute(2 - 3));
#line 173 "myparser.c"
}
}
break;
case 1:
{
#ifdef YYDEBUG
YYSTYPE YYFAR *yya[3];
yyinitdebug(yya, 3);
#endif
{
#line 14 ".\\myparser.y"
yyerror("reenter last line:"); yyerrok();
#line 186 "myparser.c"
}
}
break;
case 2:
{
#ifdef YYDEBUG
YYSTYPE YYFAR *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 17 ".\\myparser.y"
yyval = yyattribute(1 - 3) + yyattribute(3 - 3);
#line 199 "myparser.c"
}
}
break;
case 3:
{
#ifdef YYDEBUG
YYSTYPE YYFAR *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 18 ".\\myparser.y"
yyval = yyattribute(1 - 3) - yyattribute(3 - 3);
#line 212 "myparser.c"
}
}
break;
case 4:
{
#ifdef YYDEBUG
YYSTYPE YYFAR *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 22 ".\\myparser.y"
yyval = yyattribute(1 - 3) * yyattribute(3 - 3);
#line 225 "myparser.c"
}
}
break;
case 5:
{
#ifdef YYDEBUG
YYSTYPE YYFAR *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 23 ".\\myparser.y"
yyval = yyattribute(1 - 3) / yyattribute(3 - 3);
#line 238 "myparser.c"
}
}
break;
case 6:
{
#ifdef YYDEBUG
YYSTYPE YYFAR *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 27 ".\\myparser.y"
yyval = yyattribute(2 - 3);
#line 251 "myparser.c"
}
}
break;
case 7:
{
#ifdef YYDEBUG
YYSTYPE YYFAR *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 28 ".\\myparser.y"
yyval = yyattribute(2 - 3); yyerror("missing ')'"); yyerrok();
#line 264 "myparser.c"
}
}
break;
case 8:
{
#ifdef YYDEBUG
YYSTYPE YYFAR *yya[3];
yyinitdebug(yya, 3);
#endif
{
#line 29 ".\\myparser.y"
yyval = -yyattribute(2 - 2);
#line 277 "myparser.c"
}
}
break;
default:
yyassert(0);
break;
}
}
#ifdef YYDEBUG
YYCONST yysymbol_t YYNEARFAR YYBASED_CODE YYDCDECL yysymbol[] = {
{ "$end", 0 },
{ "\' \'", 32 },
{ "\'(\'", 40 },
{ "\')\'", 41 },
{ "\'*\'", 42 },
{ "\'+\'", 43 },
{ "\'-\'", 45 },
{ "\'/\'", 47 },
{ "error", 256 },
{ "NUMBER", 257 },
{ NULL, 0 }
};
YYCONST char *YYCONST YYNEARFAR YYBASED_CODE YYDCDECL yyrule[] = {
"$accept: lines",
"lines: lines expr \' \'",
"lines: lines \' \'",
"lines:",
"lines: error \' \'",
"expr: expr \'+\' term",
"expr: expr \'-\' term",
"expr: term",
"term: term \'*\' factor",
"term: term \'/\' factor",
"term: factor",
"factor: \'(\' expr \')\'",
"factor: \'(\' expr error",
"factor: \'-\' factor",
"factor: NUMBER"
};
#endif
YYCONST yyreduction_t YYNEARFAR YYBASED_CODE YYDCDECL yyreduction[] = {
{ 0, 1, -1 },
{ 1, 3, 0 },
{ 1, 2, -1 },
{ 1, 0, -1 },
{ 1, 2, 1 },
{ 2, 3, 2 },
{ 2, 3, 3 },
{ 2, 1, -1 },
{ 3, 3, 4 },
{ 3, 3, 5 },
{ 3, 1, -1 },
{ 4, 3, 6 },
{ 4, 3, 7 },
{ 4, 2, 8 },
{ 4, 1, -1 }
};
int YYNEAR YYDCDECL yytokenaction_size = 225;
YYCONST yytokenaction_t YYNEARFAR YYBASED_CODE YYDCDECL yytokenaction[] = {
{ 11, YYAT_ERROR, 0 },
{ 17, YYAT_SHIFT, 5 },
{ 2, YYAT_ACCEPT, 0 },
{ 8, YYAT_SHIFT, 13 },
{ 1, YYAT_SHIFT, 3 },
{ 21, YYAT_SHIFT, 16 },
{ 17, YYAT_SHIFT, 6 },
{ 20, YYAT_SHIFT, 16 },
{ 9, YYAT_SHIFT, 16 },
{ 11, YYAT_SHIFT, 18 },
{ 21, YYAT_SHIFT, 17 },
{ 0, YYAT_SHIFT, 1 },
{ 20, YYAT_SHIFT, 17 },
{ 9, YYAT_SHIFT, 17 },
{ 8, YYAT_SHIFT, 14 },
{ -1, YYAT_ERROR, 0 },
{ 8, YYAT_SHIFT, 15 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ 2, YYAT_SHIFT, 4 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ 17, YYAT_SHIFT, 7 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ -1, YYAT_ERROR, 0 },
{ 11, YYAT_SHIFT, 19 }
};
YYCONST yystateaction_t YYNEARFAR YYBASED_CODE YYDCDECL yystateaction[] = {
{ -245, 1, YYAT_REDUCE, 3 },
{ -28, 1, YYAT_ERROR, 0 },
{ 2, 1, YYAT_DEFAULT, 17 },
{ 0, 0, YYAT_REDUCE, 4 },
{ 0, 0, YYAT_REDUCE, 2 },
{ 0, 0, YYAT_DEFAULT, 17 },
{ 0, 0, YYAT_DEFAULT, 17 },
{ 0, 0, YYAT_REDUCE, 14 },
{ -29, 1, YYAT_ERROR, 0 },
{ -34, 1, YYAT_REDUCE, 7 },
{ 0, 0, YYAT_REDUCE, 10 },
{ -32, 1, YYAT_DEFAULT, 8 },
{ 0, 0, YYAT_REDUCE, 13 },
{ 0, 0, YYAT_REDUCE, 1 },
{ 0, 0, YYAT_DEFAULT, 17 },
{ 0, 0, YYAT_DEFAULT, 17 },
{ 0, 0, YYAT_DEFAULT, 17 },
{ -39, 1, YYAT_ERROR, 0 },
{ 0, 0, YYAT_REDUCE, 11 },
{ 0, 0, YYAT_REDUCE, 12 },
{ -35, 1, YYAT_REDUCE, 5 },
{ -37, 1, YYAT_REDUCE, 6 },
{ 0, 0, YYAT_REDUCE, 8 },
{ 0, 0, YYAT_REDUCE, 9 }
};
int YYNEAR YYDCDECL yynontermgoto_size = 10;
YYCONST yynontermgoto_t YYNEARFAR YYBASED_CODE YYDCDECL yynontermgoto[] = {
{ 15, 21 },
{ 15, 10 },
{ 5, 11 },
{ 5, 9 },
{ 17, 23 },
{ 16, 22 },
{ 14, 20 },
{ 6, 12 },
{ 2, 8 },
{ 0, 2 }
};
YYCONST yystategoto_t YYNEARFAR YYBASED_CODE YYDCDECL yystategoto[] = {
{ 8, -1 },
{ 0, -1 },
{ 6, 5 },
{ 0, -1 },
{ 0, -1 },
{ 0, 15 },
{ 3, -1 },
{ 0, -1 },
{ 0, -1 },
{ 0, -1 },
{ 0, -1 },
{ 0, -1 },
{ 0, -1 },
{ 0, -1 },
{ 3, 15 },
{ -3, -1 },
{ 1, -1 },
{ 0, -1 },
{ 0, -1 },
{ 0, -1 },
{ 0, -1 },
{ 0, -1 },
{ 0, -1 },
{ 0, -1 }
};
YYCONST yydestructor_t YYNEARFAR *YYNEAR YYDCDECL yydestructorptr = NULL;
YYCONST yytokendest_t YYNEARFAR *YYNEAR YYDCDECL yytokendestptr = NULL;
int YYNEAR YYDCDECL yytokendest_size = 0;
YYCONST yytokendestbase_t YYNEARFAR *YYNEAR YYDCDECL yytokendestbaseptr = NULL;
int YYNEAR YYDCDECL yytokendestbase_size = 0;
#line 35 ".\\myparser.y"
/////////////////////////////////////////////////////////////////////////////
// programs section
int main(void)
{
return yyparse();
}
int yylex(void)
{
int c;
while ((c = getchar()) == ' ');
if (c == '.' || isdigit(c)) {
ungetc(c, stdin);
scanf("%lf", &yylval);
return NUMBER;
}
return c;
}