actions before parsing rules in lex n yacc


 
Thread Tools Search this Thread
Top Forums Programming actions before parsing rules in lex n yacc
# 1  
Old 11-26-2008
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 any pre defined lex-yacc function which get call before processing rules?

In case of ANTLR (Another Tool for Language Recognition), we can specify actions before processing rule using a block "@init" . Is there anything like "@init" in lex n yacc ?

Regards,
Suprit
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

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... (0 Replies)
Discussion started by: zolafencer
0 Replies

2. 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

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

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

5. Programming

regarding lex regular expression

Hi all I am using lex for my application scanning and I need to skip some lines for which I don't know the exact pattern. So, could anybody tell me the regular expression to display lines NOT beginning with the specified pattern. I know how to display lines beginning with the... (1 Reply)
Discussion started by: axes
1 Replies

6. Linux

lex for Chinese character

Hi, I need to read one chinese char using lex. I tried using "." ( period ) for pattern matching but in vain. Could anyone suggest me how do i proceeed. Sample pgm: to read a chinese char in single quotes. %{ #include <locale.h> %} %% \'.\' printf("SUCCESS\n"); . ... (0 Replies)
Discussion started by: suman_jakkula
0 Replies

7. Shell Programming and Scripting

probs compiling lex

this is my lex file ------------ test.l %% printf("%c",yytext+'a'-'A');.ECHO; how do i compile it $ lex test.l cc lex.yy.c -o test -ll <------| | if this is correct do i add this line--------| @the command line or does it... (0 Replies)
Discussion started by: sinner
0 Replies
Login or Register to Ask a Question
yacc(1) 							   User Commands							   yacc(1)

NAME
yacc - yet another compiler-compiler SYNOPSIS
yacc [-dltVv] [-b file_prefix] [-Q [y | n]] [-P parser] [-p sym_prefix] file DESCRIPTION
The yacc command converts a context-free grammar into a set of tables for a simple automaton that executes an LALR(1) parsing algorithm. The grammar can be ambiguous. Specified precedence rules are used to break ambiguities. The output file, y.tab.c, must be compiled by the C compiler to produce a function yyparse(). This program must be loaded with the lexical analyzer program, yylex(), as well as main() and yyerror(), an error handling routine. These routines must be supplied by the user. The lex(1) command is useful for creating lexical analyzers usable by yacc. OPTIONS
The following options are supported: -b file_prefix Uses file_prefix instead of y as the prefix for all output files. The code file y.tab.c, the header file y.tab.h (created when -d is specified), and the description file y.output (created when -v is specified), is changed to file_prefix.tab.c, file_prefix.tab.h, and file_prefix.output, respectively. -d Generates the file y.tab.h with the #define statements that associate the yacc user-assigned "token codes" with the user- declared "token names". This association allows source files other than y.tab.c to access the token codes. -l Specifies that the code produced in y.tab.c does not contain any #line constructs. This option should only be used after the grammar and the associated actions are fully debugged. -p sym_prefix Uses sym_prefix instead of yy as the prefix for all external names produced by yacc. The names affected include the func- tions yyparse(), yylex() and yyerror(), and the variables yylval, yychar and yydebug. (In the remainder of this section, the six symbols cited are referenced using their default names only as a notational convenience.) Local names can also be affected by the -p option. However, the -p option does not affect #define symbols generated by yacc. -P parser Allows you to specify the parser of your choice instead of /usr/share/lib/ccs/yaccpar. For example, you can specify: example% yacc -P ~/myparser parser.y -Q[y|n] The -Qy option puts the version stamping information in y.tab.c. This allows you to know what version of yacc built the file. The -Qn option (the default) writes no version information. -t Compiles runtime debugging code by default. Runtime debugging code is always generated in y.tab.c under conditional com- pilation control. By default, this code is not included when y.tab.c is compiled. Whether or not the -t option is used, the runtime debugging code is under the control of YYDEBUG , a preprocessor symbol. If YYDEBUG has a non-zero value, then the debugging code is included. If its value is 0, then the code is not included. The size and execution time of a pro- gram produced without the runtime debugging code is smaller and slightly faster. -v Prepares the file y.output, which contains a description of the parsing tables and a report on conflicts generated by ambiguities in the grammar. -V Prints on the standard error output the version information for yacc. OPERANDS
The following operand is required: file A path name of a file containing instructions for which a parser is to be created. EXAMPLES
Example 1 Accessing the yacc Library Access to the yacc library is obtained with library search operands to cc. To use the yacc library main: example% cc y.tab.c -ly Both the lex library and the yacc library contain main. To access the yacc main: example% cc y.tab.c lex.yy.c -ly -ll This ensures that the yacc library is searched first, so that its main is used. The historical yacc libraries have contained two simple functions that are normally coded by the application programmer. These library functions are similar to the following code: #include <locale.h> int main(void) { extern int yyparse(); setlocale(LC_ALL, ""); /* If the following parser is one created by lex, the application must be careful to ensure that LC_CTYPE and LC_COLLATE are set to the POSIX locale. */ (void) yyparse(); return(0); } #include <stdio.h> int yyerror(const char *msg) { (void) fprintf(stderr, "%s ", msg); return(0); } ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of yacc: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. yacc can handle characters from EUC primary and supplementary codesets as one-token symbols. EUC codes can only be single character quoted terminal symbols. yacc expects yylex() to return a wide character (wchar_t) value for these one-token symbols. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. FILES
y.output state transitions of the generated parser y.tab.c source code of the generated parser y.tab.h header file for the generated parser yacc.acts temporary file yacc.debug temporary file yacc.tmp temporary file yaccpar parser prototype for C programs ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWbtool | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
cc(1B), lex(1), attributes(5), environ(5), standards(5) DIAGNOSTICS
The number of reduce-reduce and shift-reduce conflicts is reported on the standard error output. A more detailed report is found in the y.output file. Similarly, if some rules are not reachable from the start symbol, this instance is also reported. NOTES
Because file names are fixed, at most one yacc process can be active in a given directory at a given time. Users are encouraged to avoid using '$' as part of any identifier name. SunOS 5.11 28 Jun 2007 yacc(1)