Search Results

Search found 296 results on 12 pages for 'hai bison'.

Page 1/12 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • ANTLR grammar from bison

    - by Iulian Serbanoiu
    Hello, I'm trying to translate a grammar from bison to ANTLR. The grammar itself is pretty simple in bison but I cannot find a simple way for doing this. Grammar in bison: expr = expr or expr | expr and expr | (expr) Any hints/links/pointers are welcome. Thanks, Iulian

    Read the article

  • How do i implement If statement in Flex/bison

    - by Imran
    Hallo, I need help in flex/bison. Im a beginner in flex/bison, and i hav already looked out these programs and somethings i inderstood, but im learning. My problem is, i want to implement a If-statement via Flex/Bison and i dont know how to start how to do, someone any idea, im very thankful for all your help. here is an example i want to implement: :L1 IF FLAG AND X"0001" EVT 23; ELSE WAIT 500 ms; JMP L1; END IF; how do i implement JMP (jump), when JMP comes it has to jump to the Label L1.

    Read the article

  • generating program structur (nodes) using bison and flex

    - by gruszczy
    I would like to write myself a pretty printer for java using bison and flex. I have written a pretty printer for a script language, but I was only writing visitors, which made the printing. How can I turn a program using my formal grammar into a tree of nodes (made using C++ classes), that afterwards I could visit using my visitor? Maybe you could give me some link with an example of this? What i need to put into flex/bison files?

    Read the article

  • generating program structure (nodes) using bison and flex

    - by gruszczy
    I would like to write myself a pretty printer for java using bison and flex. I have written a pretty printer for a script language, but I was only writing visitors, which made the printing. How can I turn a program using my formal grammar into a tree of nodes (made using C++ classes), that afterwards I could visit using my visitor? Maybe you could give me some link with an example of this? What i need to put into flex/bison files?

    Read the article

  • Recognizing Tail-recursive functions with Flex+Bison and convert code to an Iterative form

    - by Viet
    I'm writing a calculator with an ability to accept new function definitions. Being aware of the need of newbies to try recursive functions such as Fibonacci, I would like my calculator to be able to recognize Tail-recursive functions with Flex + Bison and convert code to an Iterative form. I'm using Flex & Bison to do the job. If you have any hints or ideas, I welcome them warmly. Thanks!

    Read the article

  • Bison: Optional tokens in a single rule.

    - by Simone Margaritelli
    Hi there .. i'm using GNU Bison 2.4.2 to write a grammar for a new language i'm working on and i have a question. When i specify a rule, let's say : statement : T_CLASS T_IDENT '{' T_CLASS_MEMBERS '}' { // create a node for the statement ... } If i have a variation on the rule, for instance statement : T_CLASS T_IDENT T_EXTENDS T_IDENT_LIST '{' T_CLASS_MEMBERS '}' { // create a node for the statement ... } Where (from flex scanner rules) : "class" return T_CLASS; "extends" return T_EXTENDS; [a-zA-Z\_][a-zA-Z0-9\_]* return T_IDENT; (and T_IDENT_LIST is a rule for comma separated identifiers). Is there any way to specify all of this only in one rule, setting somehow the "T_EXTENDS T_IDENT_LIST" as optional? I've already tried with T_CLASS T_IDENT (T_EXTENDS T_IDENT_LIST)? '{' T_CLASS_MEMBERS '}' { // create a node for the statement ... } But Bison gave me an error. Thanks

    Read the article

  • FLEX/BISON : Why my rule is not regonized ?

    - by Natim
    Hi, I am trying to do a little exercice in FLEX and BISON. Here is the code I wrote : calc_pol.y %{ #define YYSTYPE double #include "calc_pol.tab.h" #include <math.h> #include <stdlib.h> %} %start line %token NOMBRE %token FIN %% line: exp '\n' { printf("\t%.2lf\n", $1); }; exp: exp exp '+' { $$ = $1 + $2 ;} | exp exp '-' { $$ = $1 - $2 ;} | exp exp '*' { $$ = $1 * $2 ;} | exp exp '/' { $$ = $1 / $2 ;} | exp exp '^' { $$ = pow($1, $2) ;} | NOMBRE; %% calc_pol.l %{ #include "calc_pol.tab.h" #include <stdlib.h> #include <stdio.h> extern YYSTYPE yylval; %} blancs [ \t]+ chiffre [0-9] entier [+-]?[1-9][0-9]* | 0 reel {entier}('.'{entier})? %% {blancs} {reel} { yylval = atof(yytext); return NOMBRE; } \n { return FIN; } . { return yytext[0]; } %% Makefile all: calc_pol.tab.c lex.yy.c gcc -o calc_pol $< -ly -lfl -lm calc_pol.tab.c: calc_pol.y bison -d calc_pol.y lex.yy.c: calc_pol.l flex calc_pol.l Do you have any idea of what's wrong ? Thanks Edited: The error message is flex calc_pol.l: calc_pol.l:18: règle non reconnue Line 18 is the line beginning with {reel}, and the error message translates to English as "unrecognized rule".

    Read the article

  • Bison input analyzer - basic question on optional grammer and input interpretation

    - by kumar_m_kiran
    Hi All, I am very new to Flex/Bison, So it is very navie question. Pardon me if so. May look like homework question - but I need to implement project based on below concept. My question is related to two parts, Question 1 In Bison parser, How do I provide rules for optional input. Like, I need to parse the statment Example : -country='USA' -state='INDIANA' -population='100' -ratio='0.5' -comment='Census study for Indiana' Here the ratio token can be optional. Similarly, If I have many tokens optional, then How do I provide the grammer in the parser for the same? My code looks like, %start program program : TK_COUNTRY TK_IDENTIFIER TK_STATE TK_IDENTIFIER TK_POPULATION TK_IDENTIFIER ... where all the tokens are defined in the lexer. Since there are many tokens which are optional, If I use "|" then there will be many different ways of input combination possible. Question 2 There are good chance that the comment might have quotes as part of the input, so I have added a token -tag which user can provide to interpret the same, Example : -country='USA' -state='INDIANA' -population='100' -ratio='0.5' -comment='Census study for Indiana$'s population' -tag=$ Now, I need to reinterpret Indiana$'s as Indiana's since -tag=$. Please provide any input or related material for to understand these topic. Thanks for your input in advance.

    Read the article

  • errors when using c++ bison ---- in the file position.hh

    - by Eric
    firstly I'm not good at English so forgive me. I compile my program with the bison generated files in visual studio and get these errors: ...\position.hh(83): error C2589: '(' : illegal token on right side of '::' ...\position.hh(83): error C2059: syntax error : '::' ...\position.hh(83): error C2589: '(' : illegal token on right side of '::' ...\position.hh(83): error C2059: syntax error : '::' and the corresponding code is: inline void columns (int count = 1) { column = std::max (1u, column + count); } I think the problem is with std::max. If I change std::max to equivalent code then there is problem anymore, but is there a better solution instead of changing the generated code? here is the *.yy file I wrote. // // bison.yy // %skeleton "lalr1.cc" %require "2.4.2" %defines %define parser_class_name "cmd_parser" %locations %debug %error-verbose %code requires { class ParserDriver; } %parse-param { ParserDriver& driver } %lex-param { ParserDriver& driver } %union { struct ast *a; double d; struct symbol *s; struct symlist *sl; int fn; } %code { #include "helper_func.h" #include "ParserDriver.h" std::string error_msg = ""; } %token <d> NUMBER %token <s> NAME %token <fn> FUNC %token EOL %token IF THEN ELSE WHILE DO LET %token SYM_TABLE_OVERFLOW %token UNKNOWN_CHARACTER %nonassoc <fn> CMP %right '=' %left '+' '-' %left '*' '/' %nonassoc '|' UMINUS %type <a> exp stmt list explist %type <sl> symlist %{ extern int yylex(yy::cmd_parser::semantic_type *yylval, yy::cmd_parser::location_type* yylloc); %} %start calclist %% ... grammar rules ...

    Read the article

  • Simple XML parser in bison/flex

    - by user360872
    I would like to create simple xml parser using bison/flex. I don't need validation, comments, arguments, only <tag>value</tag>, where value can be number, string or other <tag>value</tag>. So for example: <div> <mul> <num>20</num> <add> <num>1</num> <num>5</num> </add> </mul> <id>test</id> </div> If it helps, I know the names of all tags that may occur. I know how many sub-tag can be hold by given tag. Is it possible to create bison parser that would do something like that: - new Tag("num", 1) // tag1 - new Tag("num", 5) // tag2 - new Tag("add", tag1, tag2) // tag3 - new Tag("num", 20) // tag4 - new Tag("mul", tag4, tag3) ... - root = top_tag Tag & number of sub-tags: num: 1 (only value) str: 1 (only value) add | sub | mul | div: 2 (num | str | tag, num | str | tag) Could you help me with grammar to be able to create AST like given above?

    Read the article

  • Creating simple calculator with bison & flex in C++ (not C)

    - by ak91
    Hey, I would like to create simple C++ calculator using bison and flex. Please note I'm new to the creating parsers. I already found few examples in bison/flex but they were all written in C. My goal is to create C++ code, where classes would contain nodes of values, operations, funcs - to create AST (evaluation would be done just after creating whole AST - starting from the root and going forward). For example: my_var = sqrt(9 ** 2 - 32) + 4 - 20 / 5 my_var * 3 Would be parsed as: = / \ my_var + / \ sqrt - | / \ - 4 / / \ / \ ** 32 20 5 / \ 9 2 and the second AST would look like: * / \ my_var 3 Then following pseudocode reflects AST: ast_root = create_node('=', new_variable("my_var"), exp) where exp is: exp = create_node(OPERATOR, val1, val2) but NOT like this: $$ = $1 OPERATOR $3 because this way I directly get value of operation instead of creation the Node. I believe the Node should contain type (of operation), val1 (Node), val2 (Node). In some cases val2 would be NULL, like above mentioned sqrt which takes in the end one argument. Right? It will be nice if you can propose me C++ skeleton (without evaluation) for above described problem (including *.y file creating AST) to help me understand the way of creating/holding Nodes in AST. Code can be snipped, just to let me get the idea. I'll also be grateful if you point me to an existing (possibly simple) example if you know any. Thank you all for your time and assistance!

    Read the article

  • Filter y.output from bison or yacc?

    - by acidzombie24
    I am using bison and its difficult to figure out the conflicts by looking at y.output. Is there a tool to make or filter y.output so its more useful? i would love to see the full path to the state with the conflict but anything helpful is what i would like.

    Read the article

  • rules precedence in bison

    - by arbiadr
    Hi Here is the grammar rules: ProcessExpression : EventExpression "->" ProcessExpression | ProcessName ; Please can you tell me how can I tell to bison that the first rule has the highest precedence than the second one? I have tried: %nonassoc PROC %right "->" ProcessExpression : EventExpression "->" ProcessExpression | ProcessName % prec PROC; But without any result. Thank you.

    Read the article

  • How to access class member from bison action

    - by yodhevauhe
    I am calling yyparse from a member function. How to access the member variables/function from the bison action. I am currently doing as %{ #include "myclass.h" #include "parse.tab.hh" MyClass *ptr=NULL; void MyClass::evaluate(string expression) { ptr=this; yy_scan_string(expression.c_str()); yyparse(); } %} %% EXPR : EXPR PLUS EXPR { $$ = ptr->memberFunction("+",$1,$3); }

    Read the article

  • How to write a bison grammer for WDI?

    - by Rizo
    I need some help in bison grammar construction. From my another question: I'm trying to make a meta-language for writing markup code (such as xml and html) wich can be directly embedded into C/C++ code. Here is a simple sample written in this language, I call it WDI (Web Development Interface): /* * Simple wdi/html sample source code */ #include <mySite> string name = "myName"; string toCapital(string str); html { head { title { mySiteTitle; } link(rel="stylesheet", href="style.css"); } body(id="default") { // Page content wrapper div(id="wrapper", class="some_class") { h1 { "Hello, " + toCapital(name) + "!"; } // Lists post ul(id="post_list") { for(post in posts) { li { a(href=post.getID()) { post.tilte; } } } } } } } Basically it is a C source with a user-friendly interface for html. As you can see the traditional tag-based style is substituted by C-like, with blocks delimited by curly braces. I need to build an interpreter to translate this code to html and posteriorly insert it into C, so that it can be compiled. The C part stays intact. Inside the wdi source it is not necessary to use prints, every return statement will be used for output (in printf function). The program's output will be clean html code. So, for example a heading 1 tag would be transformed like this: h1 { "Hello, " + toCapital(name) + "!"; } // would become: printf("<h1>Hello, %s!</h1>", toCapital(name)); My main goal is to create an interpreter to translate wdi source to html like this: tag(attributes) {content} = <tag attributes>content</tag> Secondly, html code returned by the interpreter has to be inserted into C code with printfs. Variables and functions that occur inside wdi should also be sorted in order to use them as printf parameters (the case of toCapital(name) in sample source). Here are my flex/bison files: id [a-zA-Z_]([a-zA-Z0-9_])* number [0-9]+ string \".*\" %% {id} { yylval.string = strdup(yytext); return(ID); } {number} { yylval.number = atoi(yytext); return(NUMBER); } {string} { yylval.string = strdup(yytext); return(STRING); } "(" { return(LPAREN); } ")" { return(RPAREN); } "{" { return(LBRACE); } "}" { return(RBRACE); } "=" { return(ASSIGN); } "," { return(COMMA); } ";" { return(SEMICOLON); } \n|\r|\f { /* ignore EOL */ } [ \t]+ { /* ignore whitespace */ } . { /* return(CCODE); Find C source */ } %% %start wdi %token LPAREN RPAREN LBRACE RBRACE ASSIGN COMMA SEMICOLON CCODE QUOTE %union { int number; char *string; } %token <string> ID STRING %token <number> NUMBER %% wdi : /* empty */ | blocks ; blocks : block | blocks block ; block : head SEMICOLON | head body ; head : ID | ID attributes ; attributes : LPAREN RPAREN | LPAREN attribute_list RPAREN ; attribute_list : attribute | attribute COMMA attribute_list ; attribute : key ASSIGN value ; key : ID {$$=$1} ; value : STRING {$$=$1} /*| NUMBER*/ /*| CCODE*/ ; body : LBRACE content RBRACE ; content : /* */ | blocks | STRING SEMICOLON | NUMBER SEMICOLON | CCODE ; %% I am having difficulties on defining a proper grammar for the language, specially in splitting WDI and C code . I just started learning language processing techniques so I need some orientation. Could someone correct my code or give some examples of what is the right way to solve this problem?

    Read the article

  • flex and bison: wrong output

    - by user2972227
    I am doing a homework using flex and bison to make a complex number calculator. But my program cannot give a correct output. .lex file: %option noyywrap %{ #include<stdio.h> #include<stdlib.h> #include "complex_cal.h" #define YYSTYPE complex #include "complex_cal.tab.h" void RmWs(char* str); %} /* Add your Flex definitions here */ /* Some definitions are already provided to you*/ ws [ \t]+ digits [0-9] number (0|[1-9]+{digits}*)\.?{digits}* im [i] complexnum {ws}*[-]*{ws}*{number}{ws}*[+|-]{ws}*{number}{ws}*{im}{ws}* op [-+*/()] %% {complexnum} {RmWs(yytext); sscanf(yytext,"%lf %lf",&(yylval.real),&(yylval.img)); return CNUMBER;} {ws} /**/ {op} return *yytext; %% /* function provided to student to remove */ /* all the whitespaces from a string. */ void RmWs(char* str){ int i=0,j=0; char temp[strlen(str)+1]; strcpy(temp,str); while (temp[i]!='\0'){ while (temp[i]==' '){i++;} str[j]=temp[i]; i++; j++; } str[j]='\0'; } .y file: %{ #include <stdio.h> #include <stdlib.h> #include "complex_cal.h" /* prototypes of the provided functions */ complex complex_add (complex, complex); complex complex_sub (complex, complex); complex complex_mul (complex, complex); complex complex_div (complex, complex); /* prototypes of the provided functions */ int yylex(void); int yyerror(const char*); %} %token CNUMBER %left '+' '-' %left '*' '/' %nonassoc '(' ')' %% /* start: Add your grammar rules and actions here */ complexexp: complexexp '+' complexexpmultidiv {$$=complex_add($1, $3);} | complexexp '-' complexexpmultidiv {$$=complex_sub($1, $3);} | complexexpmultidiv {$$.real=$1.real;$$.img=$1.img;} ; complexexpmultidiv: complexexpmultidiv '*' complexsimple {$$=complex_mul($1, $3);} | complexexpmultidiv '/' complexsimple {$$=complex_div($1, $3);} | complexsimple {$$.real=$1.real;$$.img=$1.img;} ; complexsimple: '(' complexexp ')' {$$.real=$2.real;$$.img=$2.img;} | '(' CNUMBER ')' {$$.real=$2.real;$$.img=$2.img;} ; /* end: Add your grammar rules and actions here */ %% int main(){ return yyparse(); } int yyerror(const char* s){ printf("%s\n", s); return 0; } /* function provided to do complex addition */ /* input : complex numbers c1, c2 */ /* output: nothing */ /* side effect : none */ /* return value: result of addition in c3 */ complex complex_add (complex c1, complex c2){ /* c1 + c2 */ complex c3; c3.real = c1.real + c2.real; c3.img = c1.img + c2.img; return c3; } /* function provided to do complex subtraction */ /* input : complex numbers c1, c2 */ /* output: nothing */ /* side effect : none */ /* return value: result of subtraction in c3 */ complex complex_sub (complex c1, complex c2){ /* c1 - c2 */ complex c3; c3.real = c1.real - c2.real; c3.img = c1.img - c2.img; return c3; } /* function provided to do complex multiplication */ /* input : complex numbers c1, c2 */ /* output: nothing */ /* side effect : none */ /* return value: result of multiplication in c3 */ complex complex_mul (complex c1, complex c2){ /* c1 * c2 */ complex c3; c3.real = c1.real*c2.real - c1.img*c2.img; c3.img = c1.img*c2.real + c1.real*c2.img; return c3; } /* function provided to do complex division */ /* input : complex numbers c1, c2 */ /* output: nothing */ /* side effect : none */ /* return value: result of c1/c2 in c3 */ complex complex_div (complex c1, complex c2){ /* c1 / c2 (i.e. c1 divided by c2 ) */ complex c3; double d; /*divisor calculation using the conjugate of c2*/ d = c2.real*c2.real + c2.img*c2.img; c3.real = (c1.real*c2.real + c1.img*c2.img)/d; c3.img = (c1.img*c2.real - c1.real*c2.img)/d; return c3; } .h file: #include <string.h> /* struct for holding a complex number */ typedef struct { double real; double img; } complex; /* define the return type of FLEX */ #define YYSTYPE complex Script for compiling the file: bison -d -v complex_cal.y flex -ocomplex_cal.lex.yy.c complex_cal.lex gcc -o complex_cal complex_cal.lex.yy.c complex_cal.tab.c ./complex_cal Some correct sample run of the program: input:(5+6i)*(6+1i) output:24.000000+41.000000i input:(7+8i)/(-3-4i)*(5+7i) output:-11.720000-14.040000i input:(7+8i)/((-3-4i)*(5+7i)) output:-0.128108+0.211351i But when I run this program, the program only give an output which is identical to my input. For example, when I input (5+6i)(6+1i), it just gives (5+6i)(6+1i). Even if I input any other things, for example, input "abc" it just gives "abc" and is not syntax error. I don't know where the problem is and I hope to know how to solve it.

    Read the article

  • Problem compiling bison & flex program under vc++

    - by Eric
    I'm using bison & flex (downloaded via cygwin) with vc++. When I compile the program I got an error: ...: fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory The corresponding code in the flex-generated file is: #ifndef YY_NO_UNISTD_H /* Special case for "unistd.h", since it is non-ANSI. We include it way * down here because we want the user's section 1 to have been scanned first. * The user has a chance to override it with an option. */ /* %if-c-only */ #include <unistd.h> /* %endif */ /* %if-c++-only */ /* %endif */ #endif If I define YY_NO_UNISTD_H in the flex file(.l) this error will disappear, but I get several other errors: ...: error C2447: '{' : missing function header (old-style formal list?) ...: warning C4018: '<' : signed/unsigned mismatch ...: error C3861: 'isatty': identifier not found How can I fix this problem?

    Read the article

  • JMP instruction in Flex/bison

    - by Imran
    Hallo everybody, Can someone help me out of my situation, im searching for a instrucior that implements the JMP (Jump) instructior like in Assembler. I've found out that it could be withe the goto function of Flex/Bison but i have no really idea how to do. Have got anyone idea. Im very grateful of yours help. Thanks. Here is an example how it looks like. with the JMP instructor, he goes to the label L1. :L1 IF FLAG AND X"0001" EVT 23; ELSE WAIT 500 ms; JMP L1; END IF;

    Read the article

  • unistd.h related problem when compiling bison & flex program under vc++

    - by Eric
    I'm using bison & flex (downloaded via cygwin) with vc++. When I compile the program I got an error: ...: fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory The corresponding code in the flex-generated file is: #ifndef YY_NO_UNISTD_H /* Special case for "unistd.h", since it is non-ANSI. We include it way * down here because we want the user's section 1 to have been scanned first. * The user has a chance to override it with an option. */ /* %if-c-only */ #include <unistd.h> /* %endif */ /* %if-c++-only */ /* %endif */ #endif If I define YY_NO_UNISTD_H in the flex file(.l) this error will disappear, but I get several other errors: ...: error C2447: '{' : missing function header (old-style formal list?) ...: warning C4018: '<' : signed/unsigned mismatch ...: error C3861: 'isatty': identifier not found How can I fix this problem? All these errors occur in the flex-generated scanner. I know it's because unistd.h doesn't exist in windows. Do I have to write my own unistd.h? If so how to write it in order to eliminate those errors?

    Read the article

  • Flex/bison, error: undeclared

    - by Imran
    hallo, i have a problem, the followed program gives back an error, error:: Undeclared(first use in function), why this error appears all tokens are declared, but this error comes, can anyone help me, here are the lex and yac files.thanks lex: %{ int yylinenu= 1; int yycolno= 1; %} %x STR DIGIT [0-9] ALPHA [a-zA-Z] ID {ALPHA}(_?({ALPHA}|{DIGIT}))*_? GROUPED_NUMBER ({DIGIT}{1,3})(\.{DIGIT}{3})* SIMPLE_NUMBER {DIGIT}+ NUMMER {GROUPED_NUMBER}|{SIMPLE_NUMBER} %% <INITIAL>{ [\n] {++yylinenu ; yycolno=1;} [ ]+ {yycolno=yycolno+yyleng;} [\t]+ {yycolno=yycolno+(yyleng*8);} "*" {return MAL;} "+" {return PLUS;} "-" {return MINUS;} "/" {return SLASH;} "(" {return LINKEKLAMMER;} ")" {return RECHTEKLAMMER;} "{" {return LINKEGESCHWEIFTEKLAMMER;} "}" {return RECHTEGESCHEIFTEKLAMMER;} "=" {return GLEICH;} "==" {return GLEICHVERGLEICH;} "!=" {return UNGLEICH;} "<" {return KLEINER;} ">" {return GROSSER;} "<=" {return KLEINERGLEICH;} ">=" {return GROSSERGLEICH;} "while" {return WHILE;} "if" {return IF;} "else" {return ELSE;} "printf" {return PRINTF;} ";" {return SEMIKOLON;} \/\/[^\n]* { ;} {NUMMER} {return NUMBER;} {ID} {return IDENTIFIER;} \" {BEGIN(STR);} . {;} } <STR>{ \n {++yylinenu ;yycolno=1;} ([^\"\\]|"\\t"|"\\n"|"\\r"|"\\b"|"\\\"")+ {return STRING;} \" {BEGIN(INITIAL);} } %% yywrap() { } YACC: %{ #include stdio.h> #include string.h> #include "lex.yy.c" void yyerror(char *err); int error=0,linecnt=1; %} %token IDENTIFIER NUMBER STRING COMMENT PLUS MINUS MAL SLASH LINKEKLAMMER RECHTEKLAMMER LINKEGESCHWEIFTEKLAMMER RECHTEGESCHEIFTEKLAMMER GLEICH GLEICHVERGLEICH UNGLEICH GROSSER KLEINER GROSSERGLEICH KLEINERGLEICH IF ELSE WHILE PRINTF SEMIKOLON %start Stmts %% Stmts : Stmt {puts("\t\tStmts : Stmt");} |Stmt Stmts {puts("\t\tStmts : Stmt Stmts");} ; //NEUE REGEL---------------------------------------------- Stmt : LINKEGESCHWEIFTEKLAMMER Stmts RECHTEGESCHEIFTEKLAMMER {puts("\t\tStmt : '{' Stmts '}'");} |IF LINKEKLAMMER Cond RECHTEKLAMMER Stmt {puts("\t\tStmt : '(' Cond ')' Stmt");} |IF LINKEKLAMMER Cond RECHTEKLAMMER Stmt ELSE Stmt {puts("\t\tStmt : '(' Cond ')' Stmt 'ELSE' Stmt");} |WHILE LINKEKLAMMER Cond RECHTEKLAMMER Stmt {puts("\t\tStmt : 'PRINTF' Expr ';'");} |PRINTF Expr SEMIKOLON {puts("\t\tStmt : 'PRINTF' Expr ';'");} |IDENTIFIER GLEICH Expr SEMIKOLON {puts("\t\tStmt : 'IDENTIFIER' '=' Expr ';'");} |SEMIKOLON {puts("\t\tStmt : ';'");} ;//NEUE REGEL --------------------------------------------- Cond: Expr GLEICHVERGLEICH Expr {puts("\t\tCond : '==' Expr");} |Expr UNGLEICH Expr {puts("\t\tCond : '!=' Expr");} |Expr KLEINER Expr {puts("\t\tCond : '<' Expr");} |Expr KLEINERGLEICH Expr {puts("\t\tCond : '<=' Expr");} |Expr GROSSER Expr {puts("\t\tCond : '>' Expr");} |Expr GROSSERGLEICH Expr {puts("\t\tCond : '>=' Expr");} ;//NEUE REGEL -------------------------------------------- Expr:Term {puts("\t\tExpr : Term");} |Term PLUS Expr {puts("\t\tExpr : Term '+' Expr");} |Term MINUS Expr {puts("\t\tExpr : Term '-' Expr");} ;//NEUE REGEL -------------------------------------------- Term:Factor {puts("\t\tTerm : Factor");} |Factor MAL Term {puts("\t\tTerm : Factor '*' Term");} |Factor SLASH Term {puts("\t\tTerm : Factor '/' Term");} ;//NEUE REGEL -------------------------------------------- Factor:SimpleExpr {puts("\t\tFactor : SimpleExpr");} |MINUS SimpleExpr {puts("\t\tFactor : '-' SimpleExpr");} ;//NEUE REGEL -------------------------------------------- SimpleExpr:LINKEKLAMMER Expr RECHTEKLAMMER {puts("\t\tSimpleExpr : '(' Expr ')'");} |IDENTIFIER {puts("\t\tSimpleExpr : 'IDENTIFIER'");} |NUMBER {puts("\t\tSimpleExpr : 'NUMBER'");} |STRING {puts("\t\tSimpleExpr : 'String'");} ;//ENDE ------------------------------------------------- %% void yyerror(char *msg) { error=1; printf("Line: %d , Column: %d : %s \n", yylinenu, yycolno,yytext, msg); } int main(int argc, char *argv[]) { int val; while(yylex()) { printf("\n",yytext); } return yyparse(); }

    Read the article

  • Syntactical analysis with Flex/Bison part 2

    - by Imran
    Hallo, I need help in Lex/Yacc Programming. I wrote a compiler for a syntactical analysis for inputs of many statements. Now i have a special problem. In case of an Input the compiler gives the right output, which statement is uses, constant operator or a jmp instructor to which label, now i have to write so, if now a if statement comes, first the first command (before the else) must be give out when the assignment of the if is yes then it must jump to the end because the command after the else isnt needed, so after this jmp then the second command must be give out. I show it in an example maybe you understand what i mean. Input adr. Output if(x==0) 10 if(x==0) Wait 5 20 WAIT 5 else 30 JMP 50 Wait 1 40 WAIT 1 end 50 END like so. I have an idea, maybe i can do it whith a special if statement like IF exp jmp_stmt_end stmt_seq END when the if statement is given in the input the compiler has to recognize the end ofthe statement and like my jmp_stmt in my compiler ( you have to download the files from http://bitbucket.org/matrix/changed-tiny) only to jump to the end. I hope you understand my problem.thanks.

    Read the article

  • How do I get Bison/YACC to not recognize a command until it parses the whole string?

    - by chucknelson
    I have some bison grammar: input: /* empty */ | input command ; command: builtin | external ; builtin: CD { printf("Changing to home directory...\n"); } | CD WORD printf("Changing to directroy %s\n", $2); } ; I'm wondering how I get Bison to not accept (YYACCEPT?) something as a command until it reads ALL of the input. So I can have all these rules below that use recursion or whatever to build things up, which either results in a valid command or something that's not going to work. One simple test I'm doing with the code above is just entering "cd mydir mydir". Bison parses CD and WORD and goes "hey! this is a command, put it to the top!". Then the next token it finds is just WORD, which has no rule, and then it reports an error. I want it to read the whole line and realize CD WORD WORD is not a rule, and then report an error. I think I'm missing something obvious and would greatly appreciate any help - thanks! Also - I've tried using input command NEWLINE or something similar, but it still pushes CD WORD to the top as a command and then parses the extra WORD separately.

    Read the article

  • How do I get bison/flex to restart scanning after something like token substitution?

    - by chucknelson
    Is there a way to force bison and/or flex to restart scanning after I replace some token with something else? My particular example would be with replacement for a specific word/string. If I want a word of hello to be replaced by echo hello, how can I get flex or bison to replace hello and then start parsing again (to pick up 2 words instead of just one). So it would be like: Get token WORD (which is a string type) If hello, replace token value with echo hello Restart parsing entire input (which is now echo hello) Get token WORD (echo) Get token WORD (hello) I've seen very tempting functions like yyrestart(), but I don't really understand what that function in particular really accomplishes. Any help is greatly appreciated, thanks!

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >