Sponsored Content
Full Discussion: Yacc rogram
Top Forums Programming Yacc rogram Post 302747425 by zolafencer on Friday 21st of December 2012 03:14:20 PM
Old 12-21-2012
Yacc rogram

hello, actually i want to generate rgram in yacc able to do do several operations separated by ';' and after show all the results separated by ';' again.
My code do just one operations and i couldn' t find solution to do several ones separated by ';'. I thought may be i can do a do... while but i don't know how to do it for my example. If someone can help me please.
here is my .y for just one operation

Code:
%{ double vbltable[26]; %}

%union {
       double dval ;
       int vblno; }

%token <vblno> NAME 
%token <dval>  NUMBER

%type  <dval> expression

%%
statement_list:  
  statement '\n'
| statement_list statement '\n'
;

statement: 
  NAME '=' expression { vbltable[$1] = $3; }
| expression          { printf("est %g\n", $1); }
;

expression: 
  expression expression '+' { $$ = $1 + $2; }
| expression expression '-' { $$ = $1 - $2; }
| expression expression '*' { $$ = $1 * $2; }
| expression expression '/' {if($2 == 0.0)
                             printf("erreur ! Division par 0");
                             else
                             $$ = $1 / $2; }
| '(' '-' expression ')'    { $$ = -$3; }
| NUMBER                    { $$ = $1; }
| NAME                      { $$ = vbltable[$1]; }
;
%%

int yyerror() { printf("erreur") ; } 
int main () { yyparse(); }

and here is my .l

Code:
%{ 
#include "y.tab.h" 
#include <math.h>
extern double vbltable[26];
%}

%%

([0-9]+|([0-9]*"."[0-9]+)) { yylval.dval = atof(yytext); return NUMBER; }
\t;                        { ; }
" "                        { ; }
[a-z]                      { yylval.vblno = yytext[0] - 'a' ; return NAME;}
"$"                        { return 0; 
                             /* symb. de retour pour fin de fichier */}
\n                         { return yytext[0]; }
.                          { return yytext[0]; }

%%

thanks

---------- Post updated at 03:14 PM ---------- Previous update was at 09:06 AM ----------

no answer?? come on it's christmas soon Smilie

Last edited by joeyg; 12-21-2012 at 10:08 AM.. Reason: Please wrap commands and data with CodeTags
 

4 More Discussions You Might Find Interesting

1. Programming

How to match n number of newline character(\n) in lex and yacc

Hi , I need to develop a parser which should match something like 1. text a=5 " a=20"; 2. text a=..." a=20"; 3 text a=..." a=20 b=34 c=12 "; I have used this regular expression in my Lex file to generate the tokens: \".\s*.*\s.\" (8 Replies)
Discussion started by: vishwa787
8 Replies

2. Programming

actions before parsing rules in lex n yacc

Hi , We have developed a grammer for our domain language using lex n yacc. I want to know is there any pre defined lex-yacc function which gets call before executing any rule (or rules). Oue requirement is, before processing any rule ,we want to perform some specific actions ? is there... (0 Replies)
Discussion started by: supritjain
0 Replies

3. Programming

parsing fixed length field with yacc/bison

How to specify the token length in a yacc file? sample input format <field1,data type ans,fixed length 6> followed by <field2,data type ans,fixed length 3> Example i/p and o/p Sample Input: "ab* d2 9o" O/p : "Field1 Field2 " yacc/bison grammar: record :... (1 Reply)
Discussion started by: sungita
1 Replies

4. Programming

Problem with Yacc

Hi guys, I'm struggling with a simple but at the same time complicated problem related to yacc :wall: Maybe someone can help me with this :confused: I'm working on a big project and it's hard for me to show the problem exactly on my code, but I will give a model of it. Before I had this kind... (2 Replies)
Discussion started by: sisi
2 Replies
AUSEARCH_ADD_expression(3)					  Linux Audit API					AUSEARCH_ADD_expression(3)

NAME
ausearch_add_expression - build up search expression SYNOPSIS
#include <auparse.h> int ausearch_add_expression(auparse_state_t *au, const char *expression, char **error, ausearch_rule_t how); DESCRIPTION
ausearch_add_item adds an expression to the current audit search expression. The search conditions can then be used to scan logs, files, or buffers for something of interest. The expression parameter contains an expression, as specified in ausearch-expression(5). The how parameter determines how this search expression will affect the existing search expression, if one is already defined. The possi- ble values are: AUSEARCH_RULE_CLEAR Clear the current search expression, if any, and use only this search expression. AUSEARCH_RULE_OR If a search expression E is already configured, replace it by (E || this_search_expression). AUSEARCH_RULE_AND If a search expression E is already configured, replace it by (E && this_search_expression). RETURN VALUE
If successful, ausearch_add_expression returns 0. Otherwise, it returns -1, sets errno and it may set *error to an error message; the caller must free the error message using free(3). If an error message is not available or can not be allocated, *error is set to NULL. SEE ALSO
ausearch_add_item(3), ausearch_add_interpreted_item(3), ausearch_add_timestamp_item(3), ausearch_add_regex(3), ausearch_set_stop(3), ause- arch_clear(3), ausearch_next_event(3), ausearch-expression(5). AUTHOR
Miloslav Trmac Red Hat Feb 2008 AUSEARCH_ADD_expression(3)
All times are GMT -4. The time now is 06:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy