SlideShare a Scribd company logo
1 of 113
Compiler Design and Construction COSC 5353
Project Instructions - LOLCODE
In this project, you will develop a minimalistic compiler for a
procedural programming language. You will build on the work
you did in Assignment 1 and will create compiler that accepts a
nontrivial subset of LOLCODE programming language:
http://www.lolcode.org/
This assignment is worth 200 points, and covers two areas:
syntax-directed translation, and code generation. There are 2
stages of the project, each worth 100 points:
1) Grammar and intermediate representation. Language
specification is described here:
https://github.com/justinmeza/lolcode-
spec/blob/master/v1.2/lolcode-spec-v1.2.md
a. Using your LOLCALC Bison grammar specification as a
starting point, extend the grammar to properly recognize valid
LOLCODE programs. Minor deviations are OK (eg., I would not
deduct points if you do not handle comments). The grammar
should be complete enough that your language subset is (1)
proper LOLCODE and (2) sufficient to write nontrivial
programs
b. Create a data structure for a rudimentary Abstract Syntax
Tree (AST), or possibly another intermediate representation,
and add code to your program to construct it. At this point, do
not worry too much about having all the attributes for
subsequent code generation.
c. Submit your project to Blackboard. Due date is November 8,
2021
2. Extend your project to generate working low-level code for
programs. Code should be capable of execution directly or in a
simulator. Due date: November 30, 2021
For syntax-directed translation, pick an intermediate
representation that you see fit (such as an Abstract Syntax
Tree). For code generation, output should be into a real low -
level language: MIPS assembly code that run on the SPIM
simulator; JVM code, LLVM assembly, or Knuth’s MIX code
using appropriate emulator. Translations to another high-level
language (C, JavaScript, etc.) won’t be accepted.
Submissions will be graded on how complete your
implementation is. Approximate points allocation is (for info
purposes only):
Accept relevant syntax and construct valid AST or another IR –
40 %.
Construct and output a valid Symbol Table – 30 %.
Generate code for variable declarations (NUMBER type) – 20 %
Generate code for expressions – 20 %
Generate code for Conditional statements – 20 %
Generate code for loops – 20 %.
Generate code for input/output (VISIBLE/GIMMEH) and string
constants – 20 %.
Generate code for procedures – 20 %
Generate code for additional language features (YARN type,
TROOF type, type casting, local variable scope etc.) – 10 %.
each.
Optimizations – 10-50 %.
Clear report accompanying submission – 20 %.
Features above the minimum workable language subset can earn
points above 100%; these points are extra credit.
Note: you should work on assignment on your own. Sharing
code with other students is not allowed. Using code from the
Internet is allowed and encouraged; however, you must show
your significant efforts to build upon the code you downloaded,
respect copyright (if code is not in public domain), and give
proper referencing.
Resources:
1. LOLCODE: http://www.lolcode.org/
2. Run LOLCODE online:
https://www.tutorialspoint.com/execute_lolcode_online.php
3. FLEX reference: ftp://ftp.gnu.org/old-gnu/Manuals/flex-
2.5.4/html_mono/flex.html
4. BISON reference:
https://www.gnu.org/software/bison/manual/
A book on BISON and FLEX is available at
http://web.iitd.ac.in/~sumeet/flex__bison.pdf
5. Using SPIM with Modern Compiler Implementation -
https://www.cs.princeton.edu/~appel/modern/spim/ .
6. Assemblers, Linkers, and the SPIM simulator – on
Blackboard
7. https://busy.org/@drifter1 (scroll down to see his “Writing a
simple Compiler on my own” tutorial series, which links to
GitHub with code samples).
/* A lexical scanner generated by flex */
/* Scanner skeleton version:
* $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91
96/09/10 16:58:48 vern Exp $
*/
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
#include <stdio.h>
/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
#ifdef c_plusplus
#ifndef __cplusplus
#define __cplusplus
#endif
#endif
#ifdef __cplusplus
#include <stdlib.h>
#include <unistd.h>
/* Use prototypes in function declarations. */
#define YY_USE_PROTOS
/* The "const" storage-class-modifier is valid. */
#define YY_USE_CONST
#else/* ! __cplusplus */
#if __STDC__
#define YY_USE_PROTOS
#define YY_USE_CONST
#endif /* __STDC__ */
#endif /* ! __cplusplus */
#ifdef __TURBOC__
#pragma warn -rch
#pragma warn -use
#include <io.h>
#include <stdlib.h>
#define YY_USE_CONST
#define YY_USE_PROTOS
#endif
#ifdef YY_USE_CONST
#define yyconst const
#else
#define yyconst
#endif
#ifdef YY_USE_PROTOS
#define YY_PROTO(proto) proto
#else
#define YY_PROTO(proto) ()
#endif
/* Returned upon end-of-file. */
#define YY_NULL 0
/* Promotes a possibly negative, possibly signed char to an
unsigned
* integer for use as an array index. If the signed char is
negative,
* we want to instead treat it as an 8-bit unsigned char, hence
the
* double cast.
*/
#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
/* Enter a start condition. This macro really ought to take a
parameter,
* but we do it the disgusting crufty way forced on us by the ()-
less
* definition of BEGIN.
*/
#define BEGIN yy_start = 1 + 2 *
/* Translate the current start state into a value that can be later
handed
* to BEGIN to return to the state. The YYSTATE alias is for
lex
* compatibility.
*/
#define YY_START ((yy_start - 1) / 2)
#define YYSTATE YY_START
/* Action number for EOF rule of a given start state. */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER +
state + 1)
/* Special action meaning "start processing a new file". */
#define YY_NEW_FILE yyrestart( yyin )
#define YY_END_OF_BUFFER_CHAR 0
/* Size of default input buffer. */
#define YY_BUF_SIZE 16384
typedef struct yy_buffer_state *YY_BUFFER_STATE;
extern int yyleng;
extern FILE *yyin, *yyout;
#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2
/* The funky do-while in the following #define is used to turn
the definition
* int a single C statement (which needs a semi-colon
terminator). This
* avoids problems with code like:
*
* if ( condition_holds )
* yyless( 5 );
* else
* do_something_else();
*
* Prior to using the do-while the compiler would get upset at
the
* "else" because it interpreted the "if" statement as being all
* done when it reached the ';' after the yyless() call.
*/
/* Return all but the first 'n' matched characters back to the
input stream. */
#define yyless(n) 
do 
{ 
/* Undo effects of setting up yytext. */
*yy_cp = yy_hold_char; 
YY_RESTORE_YY_MORE_OFFSET 
yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ;

YY_DO_BEFORE_ACTION; /* set up yytext again */

} 
while ( 0 )
#define unput(c) yyunput( c, yytext_ptr )
/* The following is because we cannot portably get our hands on
size_t
* (without autoconf's help, which isn't available because we
want
* flex-generated scanners to compile on their own).
*/
typedef unsigned int yy_size_t;
struct yy_buffer_state
{
FILE *yy_input_file;
char *yy_ch_buf; /* input buffer */
char *yy_buf_pos; /* current position in input
buffer */
/* Size of input buffer in bytes, not including room for
EOB
* characters.
*/
yy_size_t yy_buf_size;
/* Number of characters read into yy_ch_buf, not including
EOB
* characters.
*/
int yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created
it,
* and can realloc() it to grow it, and should free() it to
* delete it.
*/
int yy_is_our_buffer;
/* Whether this is an "interactive" input source; if so, and
* if we're using stdio for input, then we want to use getc()
* instead of fread(), to make sure we stop fetching input
after
* each newline.
*/
int yy_is_interactive;
/* Whether we're considered to be at the beginning of a
line.
* If so, '^' rules will be active on the next match,
otherwise
* not.
*/
int yy_at_bol;
/* Whether to try to fill the input buffer when we reach the
* end of it.
*/
int yy_fill_buffer;
int yy_buffer_status;
#define YY_BUFFER_NEW 0
#define YY_BUFFER_NORMAL 1
/* When an EOF's been seen but there's still some text to
process
* then we mark the buffer as YY_EOF_PENDING, to
indicate that we
* shouldn't try reading from the input source any more.
We might
* still have a bunch of tokens to match, though, because
of
* possible backing-up.
*
* When we actually see the EOF, we change the status to
"new"
* (via yyrestart()), so that the user can continue scanning
by
* just pointing yyin at a new input file.
*/
#define YY_BUFFER_EOF_PENDING 2
};
static YY_BUFFER_STATE yy_current_buffer = 0;
/* We provide macros for accessing buffer states in case in the
* future we want to put the buffer states in a more general
* "scanner state".
*/
#define YY_CURRENT_BUFFER yy_current_buffer
/* yy_hold_char holds the character lost when yytext is formed.
*/
static char yy_hold_char;
static int yy_n_chars; /* number of characters read into
yy_ch_buf */
int yyleng;
/* Points to current character in buffer. */
static char *yy_c_buf_p = (char *) 0;
static int yy_init = 1; /* whether we need to initialize
*/
static int yy_start = 0; /* start state number */
/* Flag which is used to allow yywrap()'s to do buffer switches
* instead of setting up a fresh yyin. A bit of a hack ...
*/
static int yy_did_buffer_switch_on_eof;
void yyrestart YY_PROTO(( FILE *input_file ));
void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE
new_buffer ));
void yy_load_buffer_state YY_PROTO(( void ));
YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE
*file, int size ));
void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b
));
void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b,
FILE *file ));
void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
#define YY_FLUSH_BUFFER yy_flush_buffer(
yy_current_buffer )
YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char
*base, yy_size_t size ));
YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst
char *yy_str ));
YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst
char *bytes, int len ));
static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
static void yy_flex_free YY_PROTO(( void * ));
#define yy_new_buffer yy_create_buffer
#define yy_set_interactive(is_interactive) 
{ 
if ( ! yy_current_buffer ) 
yy_current_buffer = yy_create_buffer( yyin,
YY_BUF_SIZE ); 
yy_current_buffer->yy_is_interactive = is_interactive; 
}
#define yy_set_bol(at_bol) 
{
if ( ! yy_current_buffer ) 
yy_current_buffer = yy_create_buffer( yyin,
YY_BUF_SIZE ); 
yy_current_buffer->yy_at_bol = at_bol; 
}
#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
typedef unsigned char YY_CHAR;
FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
typedef int yy_state_type;
extern char *yytext;
#define yytext_ptr yytext
static yy_state_type yy_get_previous_state YY_PROTO(( void
));
static yy_state_type yy_try_NUL_trans YY_PROTO((
yy_state_type current_state ));
static int yy_get_next_buffer YY_PROTO(( void ));
static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
/* Done after the current pattern has been matched and before
the
* corresponding action - sets up yytext.
*/
#define YY_DO_BEFORE_ACTION 
yytext_ptr = yy_bp; 
yyleng = (int) (yy_cp - yy_bp); 
yy_hold_char = *yy_cp; 
*yy_cp = '0'; 
yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 37
#define YY_END_OF_BUFFER 38
static yyconst short int yy_accept[204] =
{ 0,
0, 0, 38, 37, 1, 36, 35, 35, 35, 35,
35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
35, 35, 35, 35, 36, 35, 35, 35, 35, 35,
35, 35, 35, 35, 0, 35, 35, 35, 35, 35,
35, 0, 35, 35, 35, 35, 35, 35, 35, 35,
35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
35, 4, 0, 0, 9, 35, 35, 35, 0, 24,
0, 35, 33, 30, 35, 35, 35, 35, 35, 35,
35, 0, 35, 35, 35, 0, 2, 0, 35, 35,
35, 35, 32, 0, 0, 0, 35, 35, 0, 0,
0, 35, 35, 35, 35, 35, 0, 35, 0, 29,
0, 34, 35, 0, 0, 35, 35, 35, 0, 0,
0, 35, 28, 0, 0, 0, 0, 0, 35, 35,
35, 35, 35, 35, 0, 35, 0, 0, 0, 0,
0, 0, 35, 35, 7, 0, 0, 0, 35, 14,
27, 25, 0, 35, 31, 35, 35, 35, 10, 35,
23, 26, 0, 21, 0, 11, 18, 0, 8, 0,
0, 5, 0, 35, 35, 35, 0, 6, 15, 0,
0, 20, 0, 0, 35, 0, 35, 0, 17, 22,
0, 0, 3, 0, 0, 0, 16, 0, 12, 0,
19, 13, 0
} ;
static yyconst int yy_ec[256] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 5, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 1, 1, 1,
1, 1, 7, 1, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
1, 1, 1, 1, 1, 1, 17, 17, 17, 17,
34, 17, 17, 17, 35, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 36, 17, 17, 17, 37,
17, 17, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1
} ;
static yyconst int yy_meta[38] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2
} ;
static yyconst short int yy_base[209] =
{ 0,
0, 0, 267, 268, 268, 260, 0, 22, 249, 248,
23, 255, 35, 235, 29, 239, 37, 235, 231, 28,
242, 25, 249, 219, 249, 0, 240, 226, 222, 238,
223, 229, 235, 231, 231, 240, 211, 228, 233, 230,
38, 215, 212, 228, 223, 214, 213, 226, 213, 206,
210, 217, 224, 193, 213, 211, 65, 212, 209, 203,
200, 0, 213, 38, 0, 189, 210, 213, 187, 0,
197, 185, 0, 184, 202, 186, 192, 205, 193, 203,
200, 181, 169, 179, 198, 55, 268, 199, 72, 56,
189, 188, 0, 173, 177, 169, 187, 183, 172, 185,
160, 81, 164, 162, 174, 169, 165, 177, 163, 268,
165, 0, 178, 67, 160, 160, 155, 164, 173, 172,
149, 143, 0, 161, 157, 165, 76, 86, 113, 152,
157, 151, 140, 142, 153, 146, 151, 131, 140, 148,
152, 146, 131, 152, 0, 148, 123, 127, 141, 268,
268, 268, 102, 141, 0, 124, 129, 144, 268, 127,
268, 268, 125, 268, 125, 268, 0, 114, 268, 110,
126, 0, 96, 107, 126, 103, 105, 0, 268, 106,
99, 268, 106, 97, 60, 77, 93, 84, 268, 268,
64, 101, 98, 106, 82, 72, 268, 67, 268, 78,
268, 268, 268, 43, 140, 142, 144, 146
} ;
static yyconst short int yy_def[209] =
{ 0,
203, 1, 203, 203, 203, 203, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 203, 204, 204, 204, 204, 204,
204, 204, 204, 204, 203, 204, 204, 204, 204, 204,
204, 203, 204, 204, 204, 204, 204, 204, 204, 204,
204, 204, 204, 204, 204, 204, 205, 204, 204, 204,
204, 204, 203, 203, 204, 204, 204, 204, 203, 204,
203, 204, 204, 204, 204, 204, 204, 204, 204, 204,
204, 203, 204, 204, 204, 206, 203, 203, 205, 204,
204, 204, 204, 203, 203, 203, 204, 204, 203, 203,
203, 207, 204, 204, 204, 204, 203, 204, 203, 203,
203, 204, 204, 203, 203, 204, 204, 204, 203, 203,
203, 204, 204, 203, 203, 203, 208, 208, 207, 129,
204, 204, 204, 204, 203, 204, 203, 203, 203, 203,
203, 203, 204, 204, 204, 203, 203, 203, 204, 203,
203, 203, 208, 129, 204, 204, 204, 204, 203, 204,
203, 203, 203, 203, 203, 203, 204, 203, 203, 203,
203, 204, 208, 129, 204, 204, 203, 204, 203, 203,
203, 203, 203, 208, 129, 203, 204, 203, 203, 203,
203, 208, 208, 208, 203, 203, 203, 203, 203, 203,
203, 203, 0, 203, 203, 203, 203, 203
} ;
static yyconst short int yy_nxt[306] =
{ 0,
4, 5, 4, 4, 5, 6, 4, 7, 8, 7,
9, 10, 7, 11, 12, 13, 7, 14, 7, 15,
16, 17, 18, 19, 7, 20, 7, 7, 21, 22,
7, 23, 7, 24, 7, 7, 7, 27, 32, 35,
39, 42, 69, 28, 26, 43, 51, 48, 29, 33,
40, 52, 44, 95, 36, 49, 45, 87, 88, 96,
115, 37, 193, 194, 70, 86, 86, 87, 88, 86,
86, 86, 86, 86, 87, 88, 86, 86, 86, 128,
116, 127, 127, 127, 128, 127, 127, 127, 140, 128,
202, 201, 141, 200, 199, 198, 197, 196, 195, 128,
128, 128, 153, 193, 194, 128, 184, 130, 193, 128,
191, 190, 153, 127, 127, 127, 128, 127, 127, 127,
173, 192, 153, 153, 153, 189, 188, 153, 153, 187,
186, 185, 153, 183, 182, 181, 180, 179, 178, 130,
89, 89, 86, 86, 129, 129, 127, 127, 177, 176,
175, 174, 172, 171, 170, 169, 168, 167, 166, 165,
164, 163, 162, 161, 160, 159, 158, 157, 156, 155,
154, 152, 151, 150, 149, 148, 147, 146, 145, 144,
143, 142, 139, 138, 137, 136, 135, 134, 133, 132,
131, 126, 125, 124, 123, 122, 121, 120, 119, 118,
117, 87, 114, 113, 112, 111, 110, 109, 108, 107,
106, 105, 104, 103, 102, 101, 100, 99, 98, 97,
94, 93, 92, 91, 90, 85, 84, 83, 82, 81,
80, 79, 78, 77, 76, 75, 74, 73, 72, 71,
68, 67, 66, 65, 64, 63, 62, 61, 60, 59,
58, 57, 56, 55, 25, 54, 53, 50, 47, 46,
41, 38, 34, 31, 30, 25, 203, 3, 203, 203,
203, 203, 203, 203, 203, 203, 203, 203, 203, 203,
203, 203, 203, 203, 203, 203, 203, 203, 203, 203,
203, 203, 203, 203, 203, 203, 203, 203, 203, 203,
203, 203, 203, 203, 203
} ;
static yyconst short int yy_chk[306] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 8, 11, 13,
15, 17, 41, 8, 204, 17, 22, 20, 8, 11,
15, 22, 17, 64, 13, 20, 17, 86, 86, 64,
90, 13, 185, 185, 41, 57, 57, 57, 57, 57,
57, 57, 89, 89, 89, 89, 89, 89, 89, 127,
90, 102, 102, 102, 102, 102, 102, 102, 114, 128,
200, 198, 114, 196, 195, 191, 188, 187, 186, 173,
184, 193, 127, 192, 192, 153, 173, 102, 194, 194,
183, 181, 128, 129, 129, 129, 129, 129, 129, 129,
153, 184, 173, 184, 193, 180, 177, 192, 153, 176,
175, 174, 194, 171, 170, 168, 165, 163, 160, 129,
205, 205, 206, 206, 207, 207, 208, 208, 158, 157,
156, 154, 149, 148, 147, 146, 144, 143, 142, 141,
140, 139, 138, 137, 136, 135, 134, 133, 132, 131,
130, 126, 125, 124, 122, 121, 120, 119, 118, 117,
116, 115, 113, 111, 109, 108, 107, 106, 105, 104,
103, 101, 100, 99, 98, 97, 96, 95, 94, 92,
91, 88, 85, 84, 83, 82, 81, 80, 79, 78,
77, 76, 75, 74, 72, 71, 69, 68, 67, 66,
63, 61, 60, 59, 58, 56, 55, 54, 53, 52,
51, 50, 49, 48, 47, 46, 45, 44, 43, 42,
40, 39, 38, 37, 36, 35, 34, 33, 32, 31,
30, 29, 28, 27, 25, 24, 23, 21, 19, 18,
16, 14, 12, 10, 9, 6, 3, 203, 203, 203,
203, 203, 203, 203, 203, 203, 203, 203, 203, 203,
203, 203, 203, 203, 203, 203, 203, 203, 203, 203,
203, 203, 203, 203, 203, 203, 203, 203, 203, 203,
203, 203, 203, 203, 203
} ;
static yy_state_type yy_last_accepting_state;
static char *yy_last_accepting_cpos;
/* The intent behind this definition is that it'll catch
* any uses of REJECT which flex missed.
*/
#define REJECT reject_used_but_not_detected
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#line 1 "CDCFlex.l"
#define INITIAL 0
#line 2 "CDCFlex.l"
/*Definitions*/
/*Rules for the language*/
#line 501 "lex.yy.c"
/* Macros after this point can all be overridden by user
definitions in
* section 1.
*/
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
extern "C" int yywrap YY_PROTO(( void ));
#else
extern int yywrap YY_PROTO(( void ));
#endif
#endif
#ifndef YY_NO_UNPUT
static void yyunput YY_PROTO(( int c, char *buf_ptr ));
#endif
#ifndef yytext_ptr
static void yy_flex_strncpy YY_PROTO(( char *, yyconst char
*, int ));
#endif
#ifdef YY_NEED_STRLEN
static int yy_flex_strlen YY_PROTO(( yyconst char * ));
#endif
#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput YY_PROTO(( void ));
#else
static int input YY_PROTO(( void ));
#endif
#endif
#if YY_STACK_USED
static int yy_start_stack_ptr = 0;
static int yy_start_stack_depth = 0;
static int *yy_start_stack = 0;
#ifndef YY_NO_PUSH_STATE
static void yy_push_state YY_PROTO(( int new_state ));
#endif
#ifndef YY_NO_POP_STATE
static void yy_pop_state YY_PROTO(( void ));
#endif
#ifndef YY_NO_TOP_STATE
static int yy_top_state YY_PROTO(( void ));
#endif
#else
#define YY_NO_PUSH_STATE 1
#define YY_NO_POP_STATE 1
#define YY_NO_TOP_STATE 1
#endif
#ifdef YY_MALLOC_DECL
YY_MALLOC_DECL
#else
#if __STDC__
#ifndef __cplusplus
#include <stdlib.h>
#endif
#else
/* Just try to get by without declaring the routines. This will
fail
* miserably on non-ANSI systems for which sizeof(size_t) !=
sizeof(int)
* or sizeof(void*) != sizeof(int).
*/
#endif
#endif
/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#define YY_READ_BUF_SIZE 8192
#endif
/* Copy whatever the last rule matched to the standard output.
*/
#ifndef ECHO
/* This used to be an fputs(), but since the string might contain
NUL's,
* we now use fwrite().
*/
#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
#endif
/* Gets input and stuffs it into "buf". number of characters
read, or YY_NULL,
* is returned in "result".
*/
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) 
if ( yy_current_buffer->yy_is_interactive ) 
{ 
int c = '*', n; 
for ( n = 0; n < max_size && 
(c = getc( yyin )) != EOF && c != 'n'; ++n )
buf[n] = (char) c; 
if ( c == 'n' ) 
buf[n++] = (char) c; 
if ( c == EOF && ferror( yyin ) ) 
YY_FATAL_ERROR( "input in flex scanner
failed" ); 
result = n; 
} 
else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) 
&& ferror( yyin ) ) 
YY_FATAL_ERROR( "input in flex scanner failed" );
#endif
/* No semi-colon after return; correct usage is to write
"yyterminate();" -
* we don't want an extra ';' after the "return" because that will
cause
* some compilers to complain about unreachable statements.
*/
#ifndef yyterminate
#define yyterminate() return YY_NULL
#endif
/* Number of entries by which start-condition stack grows. */
#ifndef YY_START_STACK_INCR
#define YY_START_STACK_INCR 25
#endif
/* Report a fatal error. */
#ifndef YY_FATAL_ERROR
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
#endif
/* Default declaration of generated scanner - a define so the
user can
* easily add parameters.
*/
#ifndef YY_DECL
#define YY_DECL int yylex YY_PROTO(( void ))
#endif
/* Code executed at the beginning of each rule, after yytext and
yyleng
* have been set up.
*/
#ifndef YY_USER_ACTION
#define YY_USER_ACTION
#endif
/* Code executed at the end of each rule. */
#ifndef YY_BREAK
#define YY_BREAK break;
#endif
#define YY_RULE_SETUP 
YY_USER_ACTION
YY_DECL
{
register yy_state_type yy_current_state;
register char *yy_cp, *yy_bp;
register int yy_act;
#line 7 "CDCFlex.l"
#line 654 "lex.yy.c"
if ( yy_init )
{
yy_init = 0;
#ifdef YY_USER_INIT
YY_USER_INIT;
#endif
if ( ! yy_start )
yy_start = 1; /* first start state */
if ( ! yyin )
yyin = stdin;
if ( ! yyout )
yyout = stdout;
if ( ! yy_current_buffer )
yy_current_buffer =
yy_create_buffer( yyin, YY_BUF_SIZE );
yy_load_buffer_state();
}
while ( 1 ) /* loops until end-of-file is reached */
{
yy_cp = yy_c_buf_p;
/* Support of yytext. */
*yy_cp = yy_hold_char;
/* yy_bp points to the position in yy_ch_buf of the
start of
* the current run.
*/
yy_bp = yy_cp;
yy_current_state = yy_start;
yy_match:
do
{
register YY_CHAR yy_c =
yy_ec[YY_SC_TO_UI(*yy_cp)];
if ( yy_accept[yy_current_state] )
{
yy_last_accepting_state = yy_current_state;
yy_last_accepting_cpos = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] +
yy_c] != yy_current_state )
{
yy_current_state = (int)
yy_def[yy_current_state];
if ( yy_current_state >= 204 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state =
yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 268 );
yy_find_action:
yy_act = yy_accept[yy_current_sta te];
if ( yy_act == 0 )
{ /* have to back up */
yy_cp = yy_last_accepting_cpos;
yy_current_state = yy_last_accepting_state;
yy_act = yy_accept[yy_current_state];
}
YY_DO_BEFORE_ACTION;
do_action: /* This label is used only to access EOF actions.
*/
switch ( yy_act )
{ /* beginning of action switch */
case 0: /* must back up */
/* undo the effects of
YY_DO_BEFORE_ACTION */
*yy_cp = yy_hold_char;
yy_cp = yy_last_accepting_cpos;
yy_current_state = yy_last_accepting_state;
goto yy_find_action;
case 1:
YY_RULE_SETUP
#line 8 "CDCFlex.l"
; // ignore all whitespace
YY_BREAK
case 2:
YY_RULE_SETUP
#line 10 "CDCFlex.l"
{printf("Single line comments %s", yytext);}
YY_BREAK
case 3:
YY_RULE_SETUP
#line 11 "CDCFlex.l"
{printf("Multiple line comments %s", yytext);}
YY_BREAK
case 4:
YY_RULE_SETUP
#line 12 "CDCFlex.l"
{ printf("Program started"); }
YY_BREAK
case 5:
YY_RULE_SETUP
#line 13 "CDCFlex.l"
{ printf("program Ended"); }
YY_BREAK
case 6:
YY_RULE_SETUP
#line 14 "CDCFlex.l"
{ printf("Printing a variable to output"); }
YY_BREAK
case 7:
YY_RULE_SETUP
#line 15 "CDCFlex.l"
{ printf("Take an input from the user"); }
YY_BREAK
case 8:
YY_RULE_SETUP
#line 16 "CDCFlex.l"
{ printf("Declare a Variable"); }
YY_BREAK
case 9:
YY_RULE_SETUP
#line 17 "CDCFlex.l"
{ printf("Assign some value to the variable"); }
YY_BREAK
case 10:
YY_RULE_SETUP
#line 18 "CDCFlex.l"
{ printf("Sum of two Operations"); }
YY_BREAK
case 11:
YY_RULE_SETUP
#line 19 "CDCFlex.l"
{ printf("Difference of two Operations"); }
YY_BREAK
case 12:
YY_RULE_SETUP
#line 20 "CDCFlex.l"
{ printf("Product of two Operations"); }
YY_BREAK
case 13:
YY_RULE_SETUP
#line 21 "CDCFlex.l"
{ printf("Division of two Operations"); }
YY_BREAK
case 14:
YY_RULE_SETUP
#line 22 "CDCFlex.l"
{ printf("Modulo of two Operations"); }
YY_BREAK
case 15:
YY_RULE_SETUP
#line 23 "CDCFlex.l"
{ printf("Larger of two Operations"); }
YY_BREAK
case 16:
YY_RULE_SETUP
#line 24 "CDCFlex.l"
{ printf("Smaller of two Operations"); }
YY_BREAK
case 17:
YY_RULE_SETUP
#line 25 "CDCFlex.l"
{ printf("Both the operaters are same"); }
YY_BREAK
case 18:
YY_RULE_SETUP
#line 26 "CDCFlex.l"
{ printf("Both the operaters are not same"); }
YY_BREAK
case 19:
YY_RULE_SETUP
#line 27 "CDCFlex.l"
{ printf("Ending a Loop"); }
YY_BREAK
case 20:
YY_RULE_SETUP
#line 28 "CDCFlex.l"
{ printf("Starting a Loop"); }
YY_BREAK
case 21:
YY_RULE_SETUP
#line 29 "CDCFlex.l"
{ printf("AND operator"); }
YY_BREAK
case 22:
YY_RULE_SETUP
#line 30 "CDCFlex.l"
{ printf("OR operator"); }
YY_BREAK
case 23:
YY_RULE_SETUP
#line 31 "CDCFlex.l"
{ printf("XOR operator"); }
YY_BREAK
case 24:
YY_RULE_SETUP
#line 32 "CDCFlex.l"
{ printf("NOT operator"); }
YY_BREAK
case 25:
YY_RULE_SETUP
#line 33 "CDCFlex.l"
{ printf("Start IF condition"); }
YY_BREAK
case 26:
YY_RULE_SETUP
#line 34 "CDCFlex.l"
{ printf("Start IF yes"); }
YY_BREAK
case 27:
YY_RULE_SETUP
#line 35 "CDCFlex.l"
{ printf("Start IF not"); }
YY_BREAK
case 28:
YY_RULE_SETUP
#line 36 "CDCFlex.l"
{ printf("Start IF maybe"); }
YY_BREAK
case 29:
YY_RULE_SETUP
#line 37 "CDCFlex.l"
{ printf("Start SWITCH CASE"); }
YY_BREAK
case 30:
YY_RULE_SETUP
#line 38 "CDCFlex.l"
{ printf("CASE inside switch case"); }
YY_BREAK
case 31:
YY_RULE_SETUP
#line 39 "CDCFlex.l"
{ printf("DEFAULT case in switch case"); }
YY_BREAK
case 32:
YY_RULE_SETUP
#line 40 "CDCFlex.l"
{ printf("BREAK statement"); }
YY_BREAK
case 33:
YY_RULE_SETUP
#line 41 "CDCFlex.l"
{ printf("Condition Ending"); }
YY_BREAK
case 34:
YY_RULE_SETUP
#line 42 "CDCFlex.l"
{return 0;}
YY_BREAK
case 35:
YY_RULE_SETUP
#line 43 "CDCFlex.l"
{ printf("String Literals %s", yytext); }
YY_BREAK
case 36:
YY_RULE_SETUP
#line 44 "CDCFlex.l"
{ printf("Number Literals %s", yytext); }
YY_BREAK
case 37:
YY_RULE_SETUP
#line 45 "CDCFlex.l"
ECHO;
YY_BREAK
#line 922 "lex.yy.c"
case YY_STATE_EOF(INITIAL):
yyterminate();
case YY_END_OF_BUFFER:
{
/* Amount of text matched not including the EOB
char. */
int yy_amount_of_matched_text = (int) (yy_cp -
yytext_ptr) - 1;
/* Undo the effects of YY_DO_BEFORE_ACTION.
*/
*yy_cp = yy_hold_char;
YY_RESTORE_YY_MORE_OFFSET
if ( yy_current_buffer->yy_buffer_status ==
YY_BUFFER_NEW )
{
/* We're scanning a new file or input source.
It's
* possible that this happened because the user
* just pointed yyin at a new source and called
* yylex(). If so, then we have to assure
* consistency between yy_current_buffer and
our
* globals. Here is the right place to do so,
because
* this is the first action (other than possibly a
* back-up) that will match for the new input
source.
*/
yy_n_chars = yy_current_buffer->yy_n_chars;
yy_current_buffer->yy_input_file = yyin;
yy_current_buffer->yy_buffer_status =
YY_BUFFER_NORMAL;
}
/* Note that here we test for yy_c_buf_p "<=" to the
position
* of the first EOB in the buffer, since yy_c_buf_p
will
* already have been incremented past the NUL
character
* (since all states make transitions on EOB to the
* end-of-buffer state). Contrast this with the test
* in input().
*/
if ( yy_c_buf_p <= &yy_current_buffer-
>yy_ch_buf[yy_n_chars] )
{ /* This was really a NUL. */
yy_state_type yy_next_state;
yy_c_buf_p = yytext_ptr +
yy_amount_of_matched_text;
yy_current_state = yy_get_previous_state();
/* Okay, we're now positioned to make the NUL
* transition. We couldn't have
* yy_get_previous_state() go ahead and do it
* for us because it doesn't know how to deal
* with the possibility of jamming (and we don't
* want to build jamming into it because then it
* will run more slowly).
*/
yy_next_state = yy_try_NUL_trans(
yy_current_state );
yy_bp = yytext_ptr + YY_MORE_ADJ;
if ( yy_next_state )
{
/* Consume the NUL. */
yy_cp = ++yy_c_buf_p;
yy_current_state = yy_next_state;
goto yy_match;
}
else
{
yy_cp = yy_c_buf_p;
goto yy_find_action;
}
}
else switch ( yy_get_next_buffer() )
{
case EOB_ACT_END_OF_FILE:
{
yy_did_buffer_switch_on_eof = 0;
if ( yywrap() )
{
/* Note: because we've taken care in
* yy_get_next_buffer() to have set up
* yytext, we can now set up
* yy_c_buf_p so that if some total
* hoser (like flex itself) wants to
* call the scanner after we return the
* YY_NULL, it'll still work - another
* YY_NULL will get returned.
*/
yy_c_buf_p = yytext_ptr +
YY_MORE_ADJ;
yy_act =
YY_STATE_EOF(YY_START);
goto do_action;
}
else
{
if ( ! yy_did_buffer_switch_on_eof )
YY_NEW_FILE;
}
break;
}
case EOB_ACT_CONTINUE_SCAN:
yy_c_buf_p =
yytext_ptr +
yy_amount_of_matched_text;
yy_current_state =
yy_get_previous_state();
yy_cp = yy_c_buf_p;
yy_bp = yytext_ptr + YY_MORE_ADJ;
goto yy_match;
case EOB_ACT_LAST_MATCH:
yy_c_buf_p =
&yy_current_buffer-
>yy_ch_buf[yy_n_chars];
yy_current_state =
yy_get_previous_state();
yy_cp = yy_c_buf_p;
yy_bp = yytext_ptr + YY_MORE_ADJ;
goto yy_find_action;
}
break;
}
default:
YY_FATAL_ERROR(
"fatal flex scanner internal error--no action
found" );
} /* end of action switch */
} /* end of scanning one token */
} /* end of yylex */
/* yy_get_next_buffer - try to read in a new buffer
*
* Returns a code representing an action:
* EOB_ACT_LAST_MATCH -
* EOB_ACT_CONTINUE_SCAN - continue scanning from
current position
* EOB_ACT_END_OF_FILE - end of file
*/
static int yy_get_next_buffer()
{
register char *dest = yy_current_buffer->yy_ch_buf;
register char *source = yytext_ptr;
register int number_to_move, i;
int ret_val;
if ( yy_c_buf_p > &yy_current_buffer-
>yy_ch_buf[yy_n_chars + 1] )
YY_FATAL_ERROR(
"fatal flex scanner internal error--end of buffer
missed" );
if ( yy_current_buffer->yy_fill_buffer == 0 )
{ /* Don't try to fill the buffer, so this is an EOF. */
if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
{
/* We matched a single character, the EOB, so
* treat this as a final EOF.
*/
return EOB_ACT_END_OF_FILE;
}
else
{
/* We matched some text prior to the EOB, first
* process it.
*/
return EOB_ACT_LAST_MATCH;
}
}
/* Try to read more data. */
/* First move last chars to start of buffer. */
number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
if ( yy_current_buffer->yy_buffer_status ==
YY_BUFFER_EOF_PENDING )
/* don't do the read, it's not guaranteed to return an
EOF,
* just force an EOF
*/
yy_current_buffer->yy_n_chars = yy_n_chars = 0;
else
{
int num_to_read =
yy_current_buffer->yy_buf_size -
number_to_move - 1;
while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */
#ifdef YY_USES_REJECT
YY_FATAL_ERROR(
"input buffer overflow, can't enlarge buffer because scanner
uses REJECT" );
#else
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = yy_current_buffer;
int yy_c_buf_p_offset =
(int) (yy_c_buf_p - b->yy_ch_buf);
if ( b->yy_is_our_buffer )
{
int new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size /
8;
else
b->yy_buf_size *= 2;
b->yy_ch_buf = (char *)
/* Include room in for 2 EOB chars. */
yy_flex_realloc( (void *) b-
>yy_ch_buf,
b->yy_buf_size + 2 );
}
else
/* Can't grow it, we don't own it. */
b->yy_ch_buf = 0;
if ( ! b->yy_ch_buf )
YY_FATAL_ERROR(
"fatal error - scanner input buffer
overflow" );
yy_c_buf_p = &b-
>yy_ch_buf[yy_c_buf_p_offset];
num_to_read = yy_current_buffer->yy_buf_size
-
number_to_move - 1;
#endif
}
if ( num_to_read > YY_READ_BUF_SIZE )
num_to_read = YY_READ_BUF_SIZE;
/* Read in more data. */
YY_INPUT( (&yy_current_buffer-
>yy_ch_buf[number_to_move]),
yy_n_chars, num_to_read );
yy_current_buffer->yy_n_chars = yy_n_chars;
}
if ( yy_n_chars == 0 )
{
if ( number_to_move == YY_MORE_ADJ )
{
ret_val = EOB_ACT_END_OF_FILE;
yyrestart( yyin );
}
else
{
ret_val = EOB_ACT_LAST_MATCH;
yy_current_buffer->yy_buffer_status =
YY_BUFFER_EOF_PENDING;
}
}
else
ret_val = EOB_ACT_CONTINUE_SCAN;
yy_n_chars += number_to_move;
yy_current_buffer->yy_ch_buf[yy_n_chars] =
YY_END_OF_BUFFER_CHAR;
yy_current_buffer->yy_ch_buf[yy_n_chars + 1] =
YY_END_OF_BUFFER_CHAR;
yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
return ret_val;
}
/* yy_get_previous_state - get the state just before the EOB
char was reached */
static yy_state_type yy_get_previous_state()
{
register yy_state_type yy_current_state;
register char *yy_cp;
yy_current_state = yy_start;
for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp <
yy_c_buf_p; ++yy_cp )
{
register YY_CHAR yy_c = (*yy_cp ?
yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
if ( yy_accept[yy_current_state] )
{
yy_last_accepting_state = yy_current_state;
yy_last_accepting_cpos = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] !=
yy_current_state )
{
yy_current_state = (int)
yy_def[yy_current_state];
if ( yy_current_state >= 204 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state]
+ (unsigned int) yy_c];
}
return yy_current_state;
}
/* yy_try_NUL_trans - try to make a transition on the NUL
character
*
* synopsis
* next_state = yy_try_NUL_trans( current_state );
*/
#ifdef YY_USE_PROTOS
static yy_state_type yy_try_NUL_trans( yy_state_type
yy_current_state )
#else
static yy_state_type yy_try_NUL_trans( yy_current_state )
yy_state_type yy_current_state;
#endif
{
register int yy_is_jam;
register char *yy_cp = yy_c_buf_p;
register YY_CHAR yy_c = 1;
if ( yy_accept[yy_current_state] )
{
yy_last_accepting_state = yy_current_state;
yy_last_accepting_cpos = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] !=
yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 204 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] +
(unsigned int) yy_c];
yy_is_jam = (yy_current_state == 203);
return yy_is_jam ? 0 : yy_current_state;
}
#ifndef YY_NO_UNPUT
#ifdef YY_USE_PROTOS
static void yyunput( int c, register char *yy_bp )
#else
static void yyunput( c, yy_bp )
int c;
register char *yy_bp;
#endif
{
register char *yy_cp = yy_c_buf_p;
/* undo effects of setting up yytext */
*yy_cp = yy_hold_char;
if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
{ /* need to shift things up to make room */
/* +2 for EOB chars. */
register int number_to_move = yy_n_chars + 2;
register char *dest = &yy_current_buffer-
>yy_ch_buf[
yy_current_buffer->yy_buf_size + 2];
register char *source =
&yy_current_buffer-
>yy_ch_buf[number_to_move];
while ( source > yy_current_buffer->yy_ch_buf )
*--dest = *--source;
yy_cp += (int) (dest - source);
yy_bp += (int) (dest - source);
yy_current_buffer->yy_n_chars =
yy_n_chars = yy_current_buffer->yy_buf_size;
if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
YY_FATAL_ERROR( "flex scanner push-back
overflow" );
}
*--yy_cp = (char) c;
yytext_ptr = yy_bp;
yy_hold_char = *yy_cp;
yy_c_buf_p = yy_cp;
}
#endif /* ifndef YY_NO_UNPUT */
#ifdef __cplusplus
static int yyinput()
#else
static int input()
#endif
{
int c;
*yy_c_buf_p = yy_hold_char;
if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
{
/* yy_c_buf_p now points to the character we want to
return.
* If this occurs *before* the EOB characters, then
it's a
* valid NUL; if not, then we've hit the end of the
buffer.
*/
if ( yy_c_buf_p < &yy_current_buffer-
>yy_ch_buf[yy_n_chars] )
/* This was really a NUL. */
*yy_c_buf_p = '0';
else
{ /* need more input */
int offset = yy_c_buf_p - yytext_ptr;
++yy_c_buf_p;
switch ( yy_get_next_buffer() )
{
case EOB_ACT_LAST_MATCH:
/* This happens because yy_g_n_b()
* sees that we've accumulated a
* token and flags that we need to
* try matching the token before
* proceeding. But for input(),
* there's no matching to consider.
* So convert the
EOB_ACT_LAST_MATCH
* to EOB_ACT_END_OF_FILE.
*/
/* Reset buffer status. */
yyrestart( yyin );
/* fall through */
case EOB_ACT_END_OF_FILE:
{
if ( yywrap() )
return EOF;
if ( ! yy_did_buffer_switch_on_eof )
YY_NEW_FILE;
#ifdef __cplusplus
return yyinput();
#else
return input();
#endif
}
case EOB_ACT_CONTINUE_SCAN:
yy_c_buf_p = yytext_ptr + offset;
break;
}
}
}
c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's
*/
*yy_c_buf_p = '0'; /* preserve yytext */
yy_hold_char = *++yy_c_buf_p;
return c;
}
#ifdef YY_USE_PROTOS
void yyrestart( FILE *input_file )
#else
void yyrestart( input_file )
FILE *input_file;
#endif
{
if ( ! yy_current_buffer )
yy_current_buffer = yy_create_buffer( yyin,
YY_BUF_SIZE );
yy_init_buffer( yy_current_buffer, input_file );
yy_load_buffer_state();
}
#ifdef YY_USE_PROTOS
void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
#else
void yy_switch_to_buffer( new_buffer )
YY_BUFFER_STATE new_buffer;
#endif
{
if ( yy_current_buffer == new_buffer )
return;
if ( yy_current_buffer )
{
/* Flush out information for old buffer. */
*yy_c_buf_p = yy_hold_char;
yy_current_buffer->yy_buf_pos = yy_c_buf_p;
yy_current_buffer->yy_n_chars = yy_n_chars;
}
yy_current_buffer = new_buffer ;
yy_load_buffer_state();
/* We don't actually know whether we did this switch
during
* EOF (yywrap()) processing, but the only time this flag
* is looked at is after yywrap() is called, so it's safe
* to go ahead and always set it.
*/
yy_did_buffer_switch_on_eof = 1;
}
#ifdef YY_USE_PROTOS
void yy_load_buffer_state( void )
#else
void yy_load_buffer_state()
#endif
{
yy_n_chars = yy_current_buffer->yy_n_chars;
yytext_ptr = yy_c_buf_p = yy_current_buffer-
>yy_buf_pos;
yyin = yy_current_buffer->yy_input_file;
yy_hold_char = *yy_c_buf_p;
}
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
#else
YY_BUFFER_STATE yy_create_buffer( file, size )
FILE *file;
int size;
#endif
{
YY_BUFFER_STATE b;
b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct
yy_buffer_state ) );
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in
yy_create_buffer()" );
b->yy_buf_size = size;
/* yy_ch_buf has to be 2 characters longer than the size
given because
* we need to put in 2 end-of-buffer characters.
*/
b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size +
2 );
if ( ! b->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in
yy_create_buffer()" );
b->yy_is_our_buffer = 1;
yy_init_buffer( b, file );
return b;
}
#ifdef YY_USE_PROTOS
void yy_delete_buffer( YY_BUFFER_STATE b )
#else
void yy_delete_buffer( b )
YY_BUFFER_STATE b;
#endif
{
if ( ! b )
return;
if ( b == yy_current_buffer )
yy_current_buffer = (YY_BUFFER_STATE) 0;
if ( b->yy_is_our_buffer )
yy_flex_free( (void *) b->yy_ch_buf );
yy_flex_free( (void *) b );
}
#ifndef YY_ALWAYS_INTERACTIVE
#ifndef YY_NEVER_INTERACTIVE
extern int isatty YY_PROTO(( int ));
#endif
#endif
#ifdef YY_USE_PROTOS
void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
#else
void yy_init_buffer( b, file )
YY_BUFFER_STATE b;
FILE *file;
#endif
{
yy_flush_buffer( b );
b->yy_input_file = file;
b->yy_fill_buffer = 1;
#if YY_ALWAYS_INTERACTIVE
b->yy_is_interactive = 1;
#else
#if YY_NEVER_INTERACTIVE
b->yy_is_interactive = 0;
#else
b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
#endif
#endif
}
#ifdef YY_USE_PROTOS
void yy_flush_buffer( YY_BUFFER_STATE b )
#else
void yy_flush_buffer( b )
YY_BUFFER_STATE b;
#endif
{
if ( ! b )
return;
b->yy_n_chars = 0;
/* We always need two end-of-buffer characters. The first
causes
* a transition to the end-of-buffer state. The second
causes
* a jam in that state.
*/
b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
b->yy_buf_pos = &b->yy_ch_buf[0];
b->yy_at_bol = 1;
b->yy_buffer_status = YY_BUFFER_NEW;
if ( b == yy_current_buffer )
yy_load_buffer_state();
}
#ifndef YY_NO_SCAN_BUFFER
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t
size )
#else
YY_BUFFER_STATE yy_scan_buffer( base, size )
char *base;
yy_size_t size;
#endif
{
YY_BUFFER_STATE b;
if ( size < 2 ||
base[size-2] != YY_END_OF_BUFFER_CHAR ||
base[size-1] != YY_END_OF_BUFFER_CHAR )
/* They forgot to leave room for the EOB's. */
return 0;
b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct
yy_buffer_state ) );
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in
yy_scan_buffer()" );
b->yy_buf_size = size - 2; /* "- 2" to take care of
EOB's */
b->yy_buf_pos = b->yy_ch_buf = base;
b->yy_is_our_buffer = 0;
b->yy_input_file = 0;
b->yy_n_chars = b->yy_buf_size;
b->yy_is_interactive = 0;
b->yy_at_bol = 1;
b->yy_fill_buffer = 0;
b->yy_buffer_status = YY_BUFFER_NEW;
yy_switch_to_buffer( b );
return b;
}
#endif
#ifndef YY_NO_SCAN_STRING
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
#else
YY_BUFFER_STATE yy_scan_string( yy_str )
yyconst char *yy_str;
#endif
{
int len;
for ( len = 0; yy_str[len]; ++len )
;
return yy_scan_bytes( yy_str, len );
}
#endif
#ifndef YY_NO_SCAN_BYTES
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int
len )
#else
YY_BUFFER_STATE yy_scan_bytes( bytes, len )
yyconst char *bytes;
int len;
#endif
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
int i;
/* Get memory for full buffer, including space for trailing
EOB's. */
n = len + 2;
buf = (char *) yy_flex_alloc( n );
if ( ! buf )
YY_FATAL_ERROR( "out of dynamic memory in
yy_scan_bytes()" );
for ( i = 0; i < len; ++i )
buf[i] = bytes[i];
buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
b = yy_scan_buffer( buf, n );
if ( ! b )
YY_FATAL_ERROR( "bad buffer in
yy_scan_bytes()" );
/* It's okay to grow etc. this buffer, and we should throw it
* away when we're done.
*/
b->yy_is_our_buffer = 1;
return b;
}
#endif
#ifndef YY_NO_PUSH_STATE
#ifdef YY_USE_PROTOS
static void yy_push_state( int new_state )
#else
static void yy_push_state( new_state )
int new_state;
#endif
{
if ( yy_start_stack_ptr >= yy_start_stack_depth )
{
yy_size_t new_size;
yy_start_stack_depth += YY_START_STACK_INCR;
new_size = yy_start_stack_depth * sizeof( int );
if ( ! yy_start_stack )
yy_start_stack = (int *) yy_flex_alloc( new_size
);
else
yy_start_stack = (int *) yy_flex_realloc(
(void *) yy_start_stack, new_size );
if ( ! yy_start_stack )
YY_FATAL_ERROR(
"out of memory expanding start-condition stack"
);
}
yy_start_stack[yy_start_stack_ptr++] = YY_START;
BEGIN(new_state);
}
#endif
#ifndef YY_NO_POP_STATE
static void yy_pop_state()
{
if ( --yy_start_stack_ptr < 0 )
YY_FATAL_ERROR( "start-condition stack
underflow" );
BEGIN(yy_start_stack[yy_start_stack_ptr]);
}
#endif
#ifndef YY_NO_TOP_STATE
static int yy_top_state()
{
return yy_start_stack[yy_start_stack_ptr - 1];
}
#endif
#ifndef YY_EXIT_FAILURE
#define YY_EXIT_FAILURE 2
#endif
#ifdef YY_USE_PROTOS
static void yy_fatal_error( yyconst char msg[] )
#else
static void yy_fatal_error( msg )
char msg[];
#endif
{
(void) fprintf( stderr, "%sn", msg );
exit( YY_EXIT_FAILURE );
}
/* Redefine yyless() so it works in section 3 code. */
#undef yyless
#define yyless(n) 
do 
{ 
/* Undo effects of setting up yytext. */ 
yytext[yyleng] = yy_hold_char;
yy_c_buf_p = yytext + n; 
yy_hold_char = *yy_c_buf_p; 
*yy_c_buf_p = '0'; 
yyleng = n; 
} 
while ( 0 )
/* Internal utility routines. */
#ifndef yytext_ptr
#ifdef YY_USE_PROTOS
static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
#else
static void yy_flex_strncpy( s1, s2, n )
char *s1;
yyconst char *s2;
int n;
#endif
{
register int i;
for ( i = 0; i < n; ++i )
s1[i] = s2[i];
}
#endif
#ifdef YY_NEED_STRLEN
#ifdef YY_USE_PROTOS
static int yy_flex_strlen( yyconst char *s )
#else
static int yy_flex_strlen( s )
yyconst char *s;
#endif
{
register int n;
for ( n = 0; s[n]; ++n )
;
return n;
}
#endif
#ifdef YY_USE_PROTOS
static void *yy_flex_alloc( yy_size_t size )
#else
static void *yy_flex_alloc( size )
yy_size_t size;
#endif
{
return (void *) malloc( size );
}
#ifdef YY_USE_PROTOS
static void *yy_flex_realloc( void *ptr, yy_size_t size )
#else
static void *yy_flex_realloc( ptr, size )
void *ptr;
yy_size_t size;
#endif
{
/* The cast to (char *) in the following accommodates both
* implementations that use char* generic pointers, and
those
* that use void* generic pointers. It works with the latter
* because both ANSI C and C++ allow castless
assignment from
* any pointer type to void*, and deal with argument
conversions
* as though doing an assignment.
*/
return (void *) realloc( (char *) ptr, size );
}
#ifdef YY_USE_PROTOS
static void yy_flex_free( void *ptr )
#else
static void yy_flex_free( ptr )
void *ptr;
#endif
{
free( ptr );
}
#if YY_MAIN
int main()
{
yylex();
return 0;
}
#endif
#line 45 "CDCFlex.l"
yywrap() {}
int main() {
printf("Enter String: n");
yyin = fopen(argv[1], "r");
yylex();
fclose(yyin);
return 0;
}
This is the program to detect lex tokens using flex and C/C++.
CDCFlex.l is the flex program to detect tokens from LOLCODE.
It has all the tokens and keywords that are used in LOLCODE.
To execute this program there are three main commands.
1. "flex CDCFlex.l" is the command to convert flex program to
C creating lex.yy.c
2. "gcc lex.yy.c -o exe" is the command to compile lex.yy.c,
creating an executable exe
3. "exe < LOLCODE.txt" is the command to run the exe and
take input lolcode.txt file
The output of the program will be list of tokens printing in the
command prompt.
%{
/*Definitions*/
%}
/*Rules for the language*/
%%
[ t] ; // ignore all whitespace
BTW[^rn]*r?n {printf("Single line comments %sn",
yytext);}
OBTW(.|r|n)*TLDRr?n {printf("Multiple line comments
%sn", yytext);}
"HAI" { printf("Program startedn"); }
"KTHXBYE" { printf("program Endedn"); }
"VISIBLE" { printf("Printing a variable to outputn");
}
"GIMMEH" { printf("Take an input from the usern"); }
"I HAS A" { printf("Declare a Variablen"); }
"ITZ" { printf("Assign some value to the
variablen"); }
"SUM OF" { printf("Sum of two Operationsn"); }
"DIFF OF" { printf("Difference of two Operationsn");
}
"PRODUKT OF" { printf("Product of two Operationsn"); }
"QUOSHUNT OF" { printf("Division of two Operationsn"); }
"MOD OF" { printf("Modulo of two Operationsn"); }
"BIGGR OF" { printf("Larger of two Operationsn"); }
"SMALLR OF" { printf("Smaller of two Operationsn"); }
"BOTH SAEM" { printf("Both the operaters are samen"); }
"DIFFRNT" { printf("Both the operaters are not
samen"); }
"IM OUTTA YR" { printf("Ending a Loopn"); }
"IM IN YR" { printf("Starting a Loopn"); }
"BOTH OF" { printf("AND operatorn"); }
"EITHER OF" { printf("OR operatorn"); }
"WON OF" { printf("XOR operatorn"); }
"NOT" { printf("NOT operatorn"); }
"O RLY?" { printf("Start IF conditionn"); }
"YA RLY" { printf("Start IF yesn"); }
"NO WAI" { printf("Start IF notn"); }
"MEBBE" { printf("Start IF mayben"); }
"WTF?" { printf("Start SWITCH CASEn"); }
"OMG" { printf("CASE inside switch casen"); }
"OMGWTF" { printf("DEFAULT case in switch
casen"); }
"GTFO" { printf("BREAK statementn"); }
"OIC" { printf("Condition Endingn"); }
"exit" {return 0;}
[a-zA-Z]+ { printf("String Literals %sn", yytext); }
[0-9]+ { printf("Number Literals %sn", yytext); }
%%
yywrap() {}
int main() {
printf("Enter String: n");
yyin = fopen(argv[1], "r");
yylex();
fclose(yyin);
return 0;
}
HAI 1.2
CAN HAS STDIO?
VISIBLE "HAI WORLD!!!1!"
KTHXBYE

More Related Content

What's hot

Using the TOGAF® 9.1 Framework with the ArchiMate® 2.1 Modeling Language
Using the TOGAF® 9.1 Framework with the ArchiMate® 2.1 Modeling LanguageUsing the TOGAF® 9.1 Framework with the ArchiMate® 2.1 Modeling Language
Using the TOGAF® 9.1 Framework with the ArchiMate® 2.1 Modeling LanguageIver Band
 
Travaux dirigés 1: algorithme & structures de données
Travaux dirigés 1: algorithme & structures de donnéesTravaux dirigés 1: algorithme & structures de données
Travaux dirigés 1: algorithme & structures de donnéesInes Ouaz
 
A Study on the Relationship between Education and Income in the US
A Study on the Relationship between Education and Income in the USA Study on the Relationship between Education and Income in the US
A Study on the Relationship between Education and Income in the USEugene Yan Ziyou
 

What's hot (6)

Using the TOGAF® 9.1 Framework with the ArchiMate® 2.1 Modeling Language
Using the TOGAF® 9.1 Framework with the ArchiMate® 2.1 Modeling LanguageUsing the TOGAF® 9.1 Framework with the ArchiMate® 2.1 Modeling Language
Using the TOGAF® 9.1 Framework with the ArchiMate® 2.1 Modeling Language
 
cours algorithme
cours algorithmecours algorithme
cours algorithme
 
Exo algo
Exo algoExo algo
Exo algo
 
Travaux dirigés 1: algorithme & structures de données
Travaux dirigés 1: algorithme & structures de donnéesTravaux dirigés 1: algorithme & structures de données
Travaux dirigés 1: algorithme & structures de données
 
A Study on the Relationship between Education and Income in the US
A Study on the Relationship between Education and Income in the USA Study on the Relationship between Education and Income in the US
A Study on the Relationship between Education and Income in the US
 
Le Langage CSS
Le Langage CSSLe Langage CSS
Le Langage CSS
 

Similar to Compiler Design and Construction COSC 5353Project Instructions -

C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212Mahmoud Samir Fayed
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentationnadim akber
 
Flex lexer.h -c++-- flexlexer.h -- define interfaces f
Flex lexer.h  -c++-- flexlexer.h -- define interfaces fFlex lexer.h  -c++-- flexlexer.h -- define interfaces f
Flex lexer.h -c++-- flexlexer.h -- define interfaces faman39650
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance levelsajjad ali khan
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)aeden_brines
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variablesSaurav Kumar
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docxeugeniadean34240
 

Similar to Compiler Design and Construction COSC 5353Project Instructions - (20)

C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentation
 
Flex lexer.h -c++-- flexlexer.h -- define interfaces f
Flex lexer.h  -c++-- flexlexer.h -- define interfaces fFlex lexer.h  -c++-- flexlexer.h -- define interfaces f
Flex lexer.h -c++-- flexlexer.h -- define interfaces f
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
C++InputOutput.PPT
C++InputOutput.PPTC++InputOutput.PPT
C++InputOutput.PPT
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
C++InputOutput.pptx
C++InputOutput.pptxC++InputOutput.pptx
C++InputOutput.pptx
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
HPC_MPI_CICID_OA.pptx
HPC_MPI_CICID_OA.pptxHPC_MPI_CICID_OA.pptx
HPC_MPI_CICID_OA.pptx
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 

More from LynellBull52

· · · Must be a foreign film with subtitles· Provide you wit.docx
· · · Must be a foreign film with subtitles· Provide you wit.docx· · · Must be a foreign film with subtitles· Provide you wit.docx
· · · Must be a foreign film with subtitles· Provide you wit.docxLynellBull52
 
·  Identify the stakeholders and how they were affected by Heene.docx
·  Identify the stakeholders and how they were affected by Heene.docx·  Identify the stakeholders and how they were affected by Heene.docx
·  Identify the stakeholders and how they were affected by Heene.docxLynellBull52
 
· · Re WEEK ONE - DISCUSSION QUESTION # 2posted by DONALD DEN.docx
· · Re WEEK ONE - DISCUSSION QUESTION # 2posted by DONALD DEN.docx· · Re WEEK ONE - DISCUSSION QUESTION # 2posted by DONALD DEN.docx
· · Re WEEK ONE - DISCUSSION QUESTION # 2posted by DONALD DEN.docxLynellBull52
 
· Week 3 AssignmentGovernment and Not-For-Profit AccountingVal.docx
· Week 3 AssignmentGovernment and Not-For-Profit AccountingVal.docx· Week 3 AssignmentGovernment and Not-For-Profit AccountingVal.docx
· Week 3 AssignmentGovernment and Not-For-Profit AccountingVal.docxLynellBull52
 
· Week 10 Assignment 2 SubmissionStudents, please view the.docx
· Week 10 Assignment 2 SubmissionStudents, please view the.docx· Week 10 Assignment 2 SubmissionStudents, please view the.docx
· Week 10 Assignment 2 SubmissionStudents, please view the.docxLynellBull52
 
· Write in paragraph format (no lists, bullets, or numbers).· .docx
· Write in paragraph format (no lists, bullets, or numbers).· .docx· Write in paragraph format (no lists, bullets, or numbers).· .docx
· Write in paragraph format (no lists, bullets, or numbers).· .docxLynellBull52
 
· WEEK 1 Databases and SecurityLesson· Databases and Security.docx
· WEEK 1 Databases and SecurityLesson· Databases and Security.docx· WEEK 1 Databases and SecurityLesson· Databases and Security.docx
· WEEK 1 Databases and SecurityLesson· Databases and Security.docxLynellBull52
 
· Unit 4 Citizen RightsINTRODUCTIONIn George Orwells Animal.docx
· Unit 4 Citizen RightsINTRODUCTIONIn George Orwells Animal.docx· Unit 4 Citizen RightsINTRODUCTIONIn George Orwells Animal.docx
· Unit 4 Citizen RightsINTRODUCTIONIn George Orwells Animal.docxLynellBull52
 
· Unit Interface-User Interaction· Assignment Objectives Em.docx
· Unit  Interface-User Interaction· Assignment Objectives Em.docx· Unit  Interface-User Interaction· Assignment Objectives Em.docx
· Unit Interface-User Interaction· Assignment Objectives Em.docxLynellBull52
 
· The Victims’ Rights MovementWrite a 2 page paper.  Address the.docx
· The Victims’ Rights MovementWrite a 2 page paper.  Address the.docx· The Victims’ Rights MovementWrite a 2 page paper.  Address the.docx
· The Victims’ Rights MovementWrite a 2 page paper.  Address the.docxLynellBull52
 
· Question 1· · How does internal environmental analy.docx
· Question 1· ·        How does internal environmental analy.docx· Question 1· ·        How does internal environmental analy.docx
· Question 1· · How does internal environmental analy.docxLynellBull52
 
· Question 1Question 192 out of 2 pointsWhat file in the.docx
· Question 1Question 192 out of 2 pointsWhat file in the.docx· Question 1Question 192 out of 2 pointsWhat file in the.docx
· Question 1Question 192 out of 2 pointsWhat file in the.docxLynellBull52
 
· Question 15 out of 5 pointsWhen psychologists discuss .docx
· Question 15 out of 5 pointsWhen psychologists discuss .docx· Question 15 out of 5 pointsWhen psychologists discuss .docx
· Question 15 out of 5 pointsWhen psychologists discuss .docxLynellBull52
 
· Question 1 2 out of 2 pointsWhich of the following i.docx
· Question 1 2 out of 2 pointsWhich of the following i.docx· Question 1 2 out of 2 pointsWhich of the following i.docx
· Question 1 2 out of 2 pointsWhich of the following i.docxLynellBull52
 
· Processed on 09-Dec-2014 901 PM CST · ID 488406360 · Word .docx
· Processed on 09-Dec-2014 901 PM CST · ID 488406360 · Word .docx· Processed on 09-Dec-2014 901 PM CST · ID 488406360 · Word .docx
· Processed on 09-Dec-2014 901 PM CST · ID 488406360 · Word .docxLynellBull52
 
· Strengths Public Recognition of OrganizationOverall Positive P.docx
· Strengths Public Recognition of OrganizationOverall Positive P.docx· Strengths Public Recognition of OrganizationOverall Positive P.docx
· Strengths Public Recognition of OrganizationOverall Positive P.docxLynellBull52
 
· Part I Key Case SummaryThis case discusses the Union Carbid.docx
· Part I Key Case SummaryThis case discusses the Union Carbid.docx· Part I Key Case SummaryThis case discusses the Union Carbid.docx
· Part I Key Case SummaryThis case discusses the Union Carbid.docxLynellBull52
 
· Perceptual process is a process through manager receive organize.docx
· Perceptual process is a process through manager receive organize.docx· Perceptual process is a process through manager receive organize.docx
· Perceptual process is a process through manager receive organize.docxLynellBull52
 
· Performance Critique Assignment· During the first month of.docx
· Performance Critique Assignment· During the first month of.docx· Performance Critique Assignment· During the first month of.docx
· Performance Critique Assignment· During the first month of.docxLynellBull52
 
· Please read the following article excerpt, and view the video cl.docx
· Please read the following article excerpt, and view the video cl.docx· Please read the following article excerpt, and view the video cl.docx
· Please read the following article excerpt, and view the video cl.docxLynellBull52
 

More from LynellBull52 (20)

· · · Must be a foreign film with subtitles· Provide you wit.docx
· · · Must be a foreign film with subtitles· Provide you wit.docx· · · Must be a foreign film with subtitles· Provide you wit.docx
· · · Must be a foreign film with subtitles· Provide you wit.docx
 
·  Identify the stakeholders and how they were affected by Heene.docx
·  Identify the stakeholders and how they were affected by Heene.docx·  Identify the stakeholders and how they were affected by Heene.docx
·  Identify the stakeholders and how they were affected by Heene.docx
 
· · Re WEEK ONE - DISCUSSION QUESTION # 2posted by DONALD DEN.docx
· · Re WEEK ONE - DISCUSSION QUESTION # 2posted by DONALD DEN.docx· · Re WEEK ONE - DISCUSSION QUESTION # 2posted by DONALD DEN.docx
· · Re WEEK ONE - DISCUSSION QUESTION # 2posted by DONALD DEN.docx
 
· Week 3 AssignmentGovernment and Not-For-Profit AccountingVal.docx
· Week 3 AssignmentGovernment and Not-For-Profit AccountingVal.docx· Week 3 AssignmentGovernment and Not-For-Profit AccountingVal.docx
· Week 3 AssignmentGovernment and Not-For-Profit AccountingVal.docx
 
· Week 10 Assignment 2 SubmissionStudents, please view the.docx
· Week 10 Assignment 2 SubmissionStudents, please view the.docx· Week 10 Assignment 2 SubmissionStudents, please view the.docx
· Week 10 Assignment 2 SubmissionStudents, please view the.docx
 
· Write in paragraph format (no lists, bullets, or numbers).· .docx
· Write in paragraph format (no lists, bullets, or numbers).· .docx· Write in paragraph format (no lists, bullets, or numbers).· .docx
· Write in paragraph format (no lists, bullets, or numbers).· .docx
 
· WEEK 1 Databases and SecurityLesson· Databases and Security.docx
· WEEK 1 Databases and SecurityLesson· Databases and Security.docx· WEEK 1 Databases and SecurityLesson· Databases and Security.docx
· WEEK 1 Databases and SecurityLesson· Databases and Security.docx
 
· Unit 4 Citizen RightsINTRODUCTIONIn George Orwells Animal.docx
· Unit 4 Citizen RightsINTRODUCTIONIn George Orwells Animal.docx· Unit 4 Citizen RightsINTRODUCTIONIn George Orwells Animal.docx
· Unit 4 Citizen RightsINTRODUCTIONIn George Orwells Animal.docx
 
· Unit Interface-User Interaction· Assignment Objectives Em.docx
· Unit  Interface-User Interaction· Assignment Objectives Em.docx· Unit  Interface-User Interaction· Assignment Objectives Em.docx
· Unit Interface-User Interaction· Assignment Objectives Em.docx
 
· The Victims’ Rights MovementWrite a 2 page paper.  Address the.docx
· The Victims’ Rights MovementWrite a 2 page paper.  Address the.docx· The Victims’ Rights MovementWrite a 2 page paper.  Address the.docx
· The Victims’ Rights MovementWrite a 2 page paper.  Address the.docx
 
· Question 1· · How does internal environmental analy.docx
· Question 1· ·        How does internal environmental analy.docx· Question 1· ·        How does internal environmental analy.docx
· Question 1· · How does internal environmental analy.docx
 
· Question 1Question 192 out of 2 pointsWhat file in the.docx
· Question 1Question 192 out of 2 pointsWhat file in the.docx· Question 1Question 192 out of 2 pointsWhat file in the.docx
· Question 1Question 192 out of 2 pointsWhat file in the.docx
 
· Question 15 out of 5 pointsWhen psychologists discuss .docx
· Question 15 out of 5 pointsWhen psychologists discuss .docx· Question 15 out of 5 pointsWhen psychologists discuss .docx
· Question 15 out of 5 pointsWhen psychologists discuss .docx
 
· Question 1 2 out of 2 pointsWhich of the following i.docx
· Question 1 2 out of 2 pointsWhich of the following i.docx· Question 1 2 out of 2 pointsWhich of the following i.docx
· Question 1 2 out of 2 pointsWhich of the following i.docx
 
· Processed on 09-Dec-2014 901 PM CST · ID 488406360 · Word .docx
· Processed on 09-Dec-2014 901 PM CST · ID 488406360 · Word .docx· Processed on 09-Dec-2014 901 PM CST · ID 488406360 · Word .docx
· Processed on 09-Dec-2014 901 PM CST · ID 488406360 · Word .docx
 
· Strengths Public Recognition of OrganizationOverall Positive P.docx
· Strengths Public Recognition of OrganizationOverall Positive P.docx· Strengths Public Recognition of OrganizationOverall Positive P.docx
· Strengths Public Recognition of OrganizationOverall Positive P.docx
 
· Part I Key Case SummaryThis case discusses the Union Carbid.docx
· Part I Key Case SummaryThis case discusses the Union Carbid.docx· Part I Key Case SummaryThis case discusses the Union Carbid.docx
· Part I Key Case SummaryThis case discusses the Union Carbid.docx
 
· Perceptual process is a process through manager receive organize.docx
· Perceptual process is a process through manager receive organize.docx· Perceptual process is a process through manager receive organize.docx
· Perceptual process is a process through manager receive organize.docx
 
· Performance Critique Assignment· During the first month of.docx
· Performance Critique Assignment· During the first month of.docx· Performance Critique Assignment· During the first month of.docx
· Performance Critique Assignment· During the first month of.docx
 
· Please read the following article excerpt, and view the video cl.docx
· Please read the following article excerpt, and view the video cl.docx· Please read the following article excerpt, and view the video cl.docx
· Please read the following article excerpt, and view the video cl.docx
 

Recently uploaded

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 

Recently uploaded (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 

Compiler Design and Construction COSC 5353Project Instructions -

  • 1. Compiler Design and Construction COSC 5353 Project Instructions - LOLCODE In this project, you will develop a minimalistic compiler for a procedural programming language. You will build on the work you did in Assignment 1 and will create compiler that accepts a nontrivial subset of LOLCODE programming language: http://www.lolcode.org/ This assignment is worth 200 points, and covers two areas: syntax-directed translation, and code generation. There are 2 stages of the project, each worth 100 points: 1) Grammar and intermediate representation. Language specification is described here: https://github.com/justinmeza/lolcode- spec/blob/master/v1.2/lolcode-spec-v1.2.md a. Using your LOLCALC Bison grammar specification as a starting point, extend the grammar to properly recognize valid LOLCODE programs. Minor deviations are OK (eg., I would not deduct points if you do not handle comments). The grammar should be complete enough that your language subset is (1) proper LOLCODE and (2) sufficient to write nontrivial programs b. Create a data structure for a rudimentary Abstract Syntax Tree (AST), or possibly another intermediate representation, and add code to your program to construct it. At this point, do not worry too much about having all the attributes for subsequent code generation. c. Submit your project to Blackboard. Due date is November 8, 2021 2. Extend your project to generate working low-level code for programs. Code should be capable of execution directly or in a simulator. Due date: November 30, 2021
  • 2. For syntax-directed translation, pick an intermediate representation that you see fit (such as an Abstract Syntax Tree). For code generation, output should be into a real low - level language: MIPS assembly code that run on the SPIM simulator; JVM code, LLVM assembly, or Knuth’s MIX code using appropriate emulator. Translations to another high-level language (C, JavaScript, etc.) won’t be accepted. Submissions will be graded on how complete your implementation is. Approximate points allocation is (for info purposes only): Accept relevant syntax and construct valid AST or another IR – 40 %. Construct and output a valid Symbol Table – 30 %. Generate code for variable declarations (NUMBER type) – 20 % Generate code for expressions – 20 % Generate code for Conditional statements – 20 % Generate code for loops – 20 %. Generate code for input/output (VISIBLE/GIMMEH) and string constants – 20 %. Generate code for procedures – 20 % Generate code for additional language features (YARN type, TROOF type, type casting, local variable scope etc.) – 10 %. each. Optimizations – 10-50 %. Clear report accompanying submission – 20 %. Features above the minimum workable language subset can earn points above 100%; these points are extra credit. Note: you should work on assignment on your own. Sharing code with other students is not allowed. Using code from the Internet is allowed and encouraged; however, you must show your significant efforts to build upon the code you downloaded,
  • 3. respect copyright (if code is not in public domain), and give proper referencing. Resources: 1. LOLCODE: http://www.lolcode.org/ 2. Run LOLCODE online: https://www.tutorialspoint.com/execute_lolcode_online.php 3. FLEX reference: ftp://ftp.gnu.org/old-gnu/Manuals/flex- 2.5.4/html_mono/flex.html 4. BISON reference: https://www.gnu.org/software/bison/manual/ A book on BISON and FLEX is available at http://web.iitd.ac.in/~sumeet/flex__bison.pdf 5. Using SPIM with Modern Compiler Implementation - https://www.cs.princeton.edu/~appel/modern/spim/ . 6. Assemblers, Linkers, and the SPIM simulator – on Blackboard 7. https://busy.org/@drifter1 (scroll down to see his “Writing a simple Compiler on my own” tutorial series, which links to GitHub with code samples). /* A lexical scanner generated by flex */ /* Scanner skeleton version: * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $ */ #define FLEX_SCANNER
  • 4. #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 #include <stdio.h> /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ #ifdef c_plusplus #ifndef __cplusplus #define __cplusplus #endif #endif #ifdef __cplusplus #include <stdlib.h> #include <unistd.h>
  • 5. /* Use prototypes in function declarations. */ #define YY_USE_PROTOS /* The "const" storage-class-modifier is valid. */ #define YY_USE_CONST #else/* ! __cplusplus */ #if __STDC__ #define YY_USE_PROTOS #define YY_USE_CONST #endif /* __STDC__ */ #endif /* ! __cplusplus */ #ifdef __TURBOC__
  • 6. #pragma warn -rch #pragma warn -use #include <io.h> #include <stdlib.h> #define YY_USE_CONST #define YY_USE_PROTOS #endif #ifdef YY_USE_CONST #define yyconst const #else #define yyconst #endif #ifdef YY_USE_PROTOS #define YY_PROTO(proto) proto #else
  • 7. #define YY_PROTO(proto) () #endif /* Returned upon end-of-file. */ #define YY_NULL 0 /* Promotes a possibly negative, possibly signed char to an unsigned * integer for use as an array index. If the signed char is negative, * we want to instead treat it as an 8-bit unsigned char, hence the * double cast. */ #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()- less
  • 8. * definition of BEGIN. */ #define BEGIN yy_start = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ #define YY_START ((yy_start - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ #define YY_NEW_FILE yyrestart( yyin )
  • 9. #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ #define YY_BUF_SIZE 16384 typedef struct yy_buffer_state *YY_BUFFER_STATE; extern int yyleng; extern FILE *yyin, *yyout; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 /* The funky do-while in the following #define is used to turn the definition * int a single C statement (which needs a semi-colon terminator). This * avoids problems with code like:
  • 10. * * if ( condition_holds ) * yyless( 5 ); * else * do_something_else(); * * Prior to using the do-while the compiler would get upset at the * "else" because it interpreted the "if" statement as being all * done when it reached the ';' after the yyless() call. */ /* Return all but the first 'n' matched characters back to the input stream. */ #define yyless(n) do { /* Undo effects of setting up yytext. */
  • 11. *yy_cp = yy_hold_char; YY_RESTORE_YY_MORE_OFFSET yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; YY_DO_BEFORE_ACTION; /* set up yytext again */ } while ( 0 ) #define unput(c) yyunput( c, yytext_ptr ) /* The following is because we cannot portably get our hands on size_t * (without autoconf's help, which isn't available because we want * flex-generated scanners to compile on their own). */ typedef unsigned int yy_size_t;
  • 12. struct yy_buffer_state { FILE *yy_input_file; char *yy_ch_buf; /* input buffer */ char *yy_buf_pos; /* current position in input buffer */ /* Size of input buffer in bytes, not including room for EOB * characters. */ yy_size_t yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. */ int yy_n_chars;
  • 13. /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to * delete it. */ int yy_is_our_buffer; /* Whether this is an "interactive" input source; if so, and * if we're using stdio for input, then we want to use getc() * instead of fread(), to make sure we stop fetching input after * each newline. */ int yy_is_interactive; /* Whether we're considered to be at the beginning of a line. * If so, '^' rules will be active on the next match, otherwise
  • 14. * not. */ int yy_at_bol; /* Whether to try to fill the input buffer when we reach the * end of it. */ int yy_fill_buffer; int yy_buffer_status; #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 /* When an EOF's been seen but there's still some text to process * then we mark the buffer as YY_EOF_PENDING, to indicate that we * shouldn't try reading from the input source any more. We might * still have a bunch of tokens to match, though, because of
  • 15. * possible backing-up. * * When we actually see the EOF, we change the status to "new" * (via yyrestart()), so that the user can continue scanning by * just pointing yyin at a new input file. */ #define YY_BUFFER_EOF_PENDING 2 }; static YY_BUFFER_STATE yy_current_buffer = 0; /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". */ #define YY_CURRENT_BUFFER yy_current_buffer
  • 16. /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; static int yy_n_chars; /* number of characters read into yy_ch_buf */ int yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; static int yy_init = 1; /* whether we need to initialize */ static int yy_start = 0; /* start state number */ /* Flag which is used to allow yywrap()'s to do buffer switches * instead of setting up a fresh yyin. A bit of a hack ... */
  • 17. static int yy_did_buffer_switch_on_eof; void yyrestart YY_PROTO(( FILE *input_file )); void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); void yy_load_buffer_state YY_PROTO(( void )); YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); #define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
  • 18. YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); static void *yy_flex_alloc YY_PROTO(( yy_size_t )); static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); static void yy_flex_free YY_PROTO(( void * )); #define yy_new_buffer yy_create_buffer #define yy_set_interactive(is_interactive) { if ( ! yy_current_buffer ) yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); yy_current_buffer->yy_is_interactive = is_interactive; } #define yy_set_bol(at_bol) {
  • 19. if ( ! yy_current_buffer ) yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); yy_current_buffer->yy_at_bol = at_bol; } #define YY_AT_BOL() (yy_current_buffer->yy_at_bol) typedef unsigned char YY_CHAR; FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; typedef int yy_state_type; extern char *yytext; #define yytext_ptr yytext static yy_state_type yy_get_previous_state YY_PROTO(( void )); static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); static int yy_get_next_buffer YY_PROTO(( void )); static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
  • 20. /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION yytext_ptr = yy_bp; yyleng = (int) (yy_cp - yy_bp); yy_hold_char = *yy_cp; *yy_cp = '0'; yy_c_buf_p = yy_cp; #define YY_NUM_RULES 37 #define YY_END_OF_BUFFER 38 static yyconst short int yy_accept[204] = { 0, 0, 0, 38, 37, 1, 36, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
  • 21. 35, 35, 35, 35, 36, 35, 35, 35, 35, 35, 35, 35, 35, 35, 0, 35, 35, 35, 35, 35, 35, 0, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 4, 0, 0, 9, 35, 35, 35, 0, 24, 0, 35, 33, 30, 35, 35, 35, 35, 35, 35, 35, 0, 35, 35, 35, 0, 2, 0, 35, 35, 35, 35, 32, 0, 0, 0, 35, 35, 0, 0, 0, 35, 35, 35, 35, 35, 0, 35, 0, 29, 0, 34, 35, 0, 0, 35, 35, 35, 0, 0, 0, 35, 28, 0, 0, 0, 0, 0, 35, 35, 35, 35, 35, 35, 0, 35, 0, 0, 0, 0, 0, 0, 35, 35, 7, 0, 0, 0, 35, 14, 27, 25, 0, 35, 31, 35, 35, 35, 10, 35, 23, 26, 0, 21, 0, 11, 18, 0, 8, 0, 0, 5, 0, 35, 35, 35, 0, 6, 15, 0, 0, 20, 0, 0, 35, 0, 35, 0, 17, 22,
  • 22. 0, 0, 3, 0, 0, 0, 16, 0, 12, 0, 19, 13, 0 } ; static yyconst int yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 1, 1, 1, 1, 1, 7, 1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 1, 1, 1, 1, 1, 1, 17, 17, 17, 17,
  • 23. 34, 17, 17, 17, 35, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 36, 17, 17, 17, 37, 17, 17, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } ;
  • 24. static yyconst int yy_meta[38] = { 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 } ; static yyconst short int yy_base[209] = { 0, 0, 0, 267, 268, 268, 260, 0, 22, 249, 248, 23, 255, 35, 235, 29, 239, 37, 235, 231, 28, 242, 25, 249, 219, 249, 0, 240, 226, 222, 238, 223, 229, 235, 231, 231, 240, 211, 228, 233, 230, 38, 215, 212, 228, 223, 214, 213, 226, 213, 206, 210, 217, 224, 193, 213, 211, 65, 212, 209, 203, 200, 0, 213, 38, 0, 189, 210, 213, 187, 0,
  • 25. 197, 185, 0, 184, 202, 186, 192, 205, 193, 203, 200, 181, 169, 179, 198, 55, 268, 199, 72, 56, 189, 188, 0, 173, 177, 169, 187, 183, 172, 185, 160, 81, 164, 162, 174, 169, 165, 177, 163, 268, 165, 0, 178, 67, 160, 160, 155, 164, 173, 172, 149, 143, 0, 161, 157, 165, 76, 86, 113, 152, 157, 151, 140, 142, 153, 146, 151, 131, 140, 148, 152, 146, 131, 152, 0, 148, 123, 127, 141, 268, 268, 268, 102, 141, 0, 124, 129, 144, 268, 127, 268, 268, 125, 268, 125, 268, 0, 114, 268, 110, 126, 0, 96, 107, 126, 103, 105, 0, 268, 106, 99, 268, 106, 97, 60, 77, 93, 84, 268, 268, 64, 101, 98, 106, 82, 72, 268, 67, 268, 78, 268, 268, 268, 43, 140, 142, 144, 146 } ;
  • 26. static yyconst short int yy_def[209] = { 0, 203, 1, 203, 203, 203, 203, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 203, 204, 204, 204, 204, 204, 204, 204, 204, 204, 203, 204, 204, 204, 204, 204, 204, 203, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 205, 204, 204, 204, 204, 204, 203, 203, 204, 204, 204, 204, 203, 204, 203, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 203, 204, 204, 204, 206, 203, 203, 205, 204, 204, 204, 204, 203, 203, 203, 204, 204, 203, 203, 203, 207, 204, 204, 204, 204, 203, 204, 203, 203, 203, 204, 204, 203, 203, 204, 204, 204, 203, 203, 203, 204, 204, 203, 203, 203, 208, 208, 207, 129, 204, 204, 204, 204, 203, 204, 203, 203, 203, 203, 203, 203, 204, 204, 204, 203, 203, 203, 204, 203,
  • 27. 203, 203, 208, 129, 204, 204, 204, 204, 203, 204, 203, 203, 203, 203, 203, 203, 204, 203, 203, 203, 203, 204, 208, 129, 204, 204, 203, 204, 203, 203, 203, 203, 203, 208, 129, 203, 204, 203, 203, 203, 203, 208, 208, 208, 203, 203, 203, 203, 203, 203, 203, 203, 0, 203, 203, 203, 203, 203 } ; static yyconst short int yy_nxt[306] = { 0, 4, 5, 4, 4, 5, 6, 4, 7, 8, 7, 9, 10, 7, 11, 12, 13, 7, 14, 7, 15, 16, 17, 18, 19, 7, 20, 7, 7, 21, 22, 7, 23, 7, 24, 7, 7, 7, 27, 32, 35, 39, 42, 69, 28, 26, 43, 51, 48, 29, 33, 40, 52, 44, 95, 36, 49, 45, 87, 88, 96, 115, 37, 193, 194, 70, 86, 86, 87, 88, 86,
  • 28. 86, 86, 86, 86, 87, 88, 86, 86, 86, 128, 116, 127, 127, 127, 128, 127, 127, 127, 140, 128, 202, 201, 141, 200, 199, 198, 197, 196, 195, 128, 128, 128, 153, 193, 194, 128, 184, 130, 193, 128, 191, 190, 153, 127, 127, 127, 128, 127, 127, 127, 173, 192, 153, 153, 153, 189, 188, 153, 153, 187, 186, 185, 153, 183, 182, 181, 180, 179, 178, 130, 89, 89, 86, 86, 129, 129, 127, 127, 177, 176, 175, 174, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 157, 156, 155, 154, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 139, 138, 137, 136, 135, 134, 133, 132, 131, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 87, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 94, 93, 92, 91, 90, 85, 84, 83, 82, 81,
  • 29. 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 25, 54, 53, 50, 47, 46, 41, 38, 34, 31, 30, 25, 203, 3, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203 } ; static yyconst short int yy_chk[306] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 11, 13, 15, 17, 41, 8, 204, 17, 22, 20, 8, 11,
  • 30. 15, 22, 17, 64, 13, 20, 17, 86, 86, 64, 90, 13, 185, 185, 41, 57, 57, 57, 57, 57, 57, 57, 89, 89, 89, 89, 89, 89, 89, 127, 90, 102, 102, 102, 102, 102, 102, 102, 114, 128, 200, 198, 114, 196, 195, 191, 188, 187, 186, 173, 184, 193, 127, 192, 192, 153, 173, 102, 194, 194, 183, 181, 128, 129, 129, 129, 129, 129, 129, 129, 153, 184, 173, 184, 193, 180, 177, 192, 153, 176, 175, 174, 194, 171, 170, 168, 165, 163, 160, 129, 205, 205, 206, 206, 207, 207, 208, 208, 158, 157, 156, 154, 149, 148, 147, 146, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 126, 125, 124, 122, 121, 120, 119, 118, 117, 116, 115, 113, 111, 109, 108, 107, 106, 105, 104, 103, 101, 100, 99, 98, 97, 96, 95, 94, 92, 91, 88, 85, 84, 83, 82, 81, 80, 79, 78,
  • 31. 77, 76, 75, 74, 72, 71, 69, 68, 67, 66, 63, 61, 60, 59, 58, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 25, 24, 23, 21, 19, 18, 16, 14, 12, 10, 9, 6, 3, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203 } ; static yy_state_type yy_last_accepting_state; static char *yy_last_accepting_cpos; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed.
  • 32. */ #define REJECT reject_used_but_not_detected #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *yytext; #line 1 "CDCFlex.l" #define INITIAL 0 #line 2 "CDCFlex.l" /*Definitions*/ /*Rules for the language*/ #line 501 "lex.yy.c" /* Macros after this point can all be overridden by user definitions in * section 1. */ #ifndef YY_SKIP_YYWRAP
  • 33. #ifdef __cplusplus extern "C" int yywrap YY_PROTO(( void )); #else extern int yywrap YY_PROTO(( void )); #endif #endif #ifndef YY_NO_UNPUT static void yyunput YY_PROTO(( int c, char *buf_ptr )); #endif #ifndef yytext_ptr static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); #endif #ifdef YY_NEED_STRLEN static int yy_flex_strlen YY_PROTO(( yyconst char * ));
  • 34. #endif #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput YY_PROTO(( void )); #else static int input YY_PROTO(( void )); #endif #endif #if YY_STACK_USED static int yy_start_stack_ptr = 0; static int yy_start_stack_depth = 0; static int *yy_start_stack = 0; #ifndef YY_NO_PUSH_STATE static void yy_push_state YY_PROTO(( int new_state )); #endif #ifndef YY_NO_POP_STATE
  • 35. static void yy_pop_state YY_PROTO(( void )); #endif #ifndef YY_NO_TOP_STATE static int yy_top_state YY_PROTO(( void )); #endif #else #define YY_NO_PUSH_STATE 1 #define YY_NO_POP_STATE 1 #define YY_NO_TOP_STATE 1 #endif #ifdef YY_MALLOC_DECL YY_MALLOC_DECL #else #if __STDC__ #ifndef __cplusplus #include <stdlib.h>
  • 36. #endif #else /* Just try to get by without declaring the routines. This will fail * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) * or sizeof(void*) != sizeof(int). */ #endif #endif /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE #define YY_READ_BUF_SIZE 8192 #endif /* Copy whatever the last rule matched to the standard output. */ #ifndef ECHO
  • 37. /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ #define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, * is returned in "result". */ #ifndef YY_INPUT #define YY_INPUT(buf,result,max_size) if ( yy_current_buffer->yy_is_interactive ) { int c = '*', n; for ( n = 0; n < max_size && (c = getc( yyin )) != EOF && c != 'n'; ++n )
  • 38. buf[n] = (char) c; if ( c == 'n' ) buf[n++] = (char) c; if ( c == EOF && ferror( yyin ) ) YY_FATAL_ERROR( "input in flex scanner failed" ); result = n; } else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) && ferror( yyin ) ) YY_FATAL_ERROR( "input in flex scanner failed" ); #endif /* No semi-colon after return; correct usage is to write "yyterminate();" - * we don't want an extra ';' after the "return" because that will cause * some compilers to complain about unreachable statements. */ #ifndef yyterminate
  • 39. #define yyterminate() return YY_NULL #endif /* Number of entries by which start-condition stack grows. */ #ifndef YY_START_STACK_INCR #define YY_START_STACK_INCR 25 #endif /* Report a fatal error. */ #ifndef YY_FATAL_ERROR #define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) #endif /* Default declaration of generated scanner - a define so the user can * easily add parameters. */ #ifndef YY_DECL
  • 40. #define YY_DECL int yylex YY_PROTO(( void )) #endif /* Code executed at the beginning of each rule, after yytext and yyleng * have been set up. */ #ifndef YY_USER_ACTION #define YY_USER_ACTION #endif /* Code executed at the end of each rule. */ #ifndef YY_BREAK #define YY_BREAK break; #endif #define YY_RULE_SETUP YY_USER_ACTION
  • 41. YY_DECL { register yy_state_type yy_current_state; register char *yy_cp, *yy_bp; register int yy_act; #line 7 "CDCFlex.l" #line 654 "lex.yy.c" if ( yy_init ) { yy_init = 0; #ifdef YY_USER_INIT YY_USER_INIT; #endif
  • 42. if ( ! yy_start ) yy_start = 1; /* first start state */ if ( ! yyin ) yyin = stdin; if ( ! yyout ) yyout = stdout; if ( ! yy_current_buffer ) yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); yy_load_buffer_state(); } while ( 1 ) /* loops until end-of-file is reached */ {
  • 43. yy_cp = yy_c_buf_p; /* Support of yytext. */ *yy_cp = yy_hold_char; /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; yy_current_state = yy_start; yy_match: do { register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; if ( yy_accept[yy_current_state] ) {
  • 44. yy_last_accepting_state = yy_current_state; yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 204 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } while ( yy_base[yy_current_state] != 268 ); yy_find_action: yy_act = yy_accept[yy_current_sta te];
  • 45. if ( yy_act == 0 ) { /* have to back up */ yy_cp = yy_last_accepting_cpos; yy_current_state = yy_last_accepting_state; yy_act = yy_accept[yy_current_state]; } YY_DO_BEFORE_ACTION; do_action: /* This label is used only to access EOF actions. */ switch ( yy_act ) { /* beginning of action switch */ case 0: /* must back up */ /* undo the effects of YY_DO_BEFORE_ACTION */
  • 46. *yy_cp = yy_hold_char; yy_cp = yy_last_accepting_cpos; yy_current_state = yy_last_accepting_state; goto yy_find_action; case 1: YY_RULE_SETUP #line 8 "CDCFlex.l" ; // ignore all whitespace YY_BREAK case 2: YY_RULE_SETUP #line 10 "CDCFlex.l" {printf("Single line comments %s", yytext);} YY_BREAK case 3: YY_RULE_SETUP #line 11 "CDCFlex.l"
  • 47. {printf("Multiple line comments %s", yytext);} YY_BREAK case 4: YY_RULE_SETUP #line 12 "CDCFlex.l" { printf("Program started"); } YY_BREAK case 5: YY_RULE_SETUP #line 13 "CDCFlex.l" { printf("program Ended"); } YY_BREAK case 6: YY_RULE_SETUP #line 14 "CDCFlex.l" { printf("Printing a variable to output"); } YY_BREAK case 7:
  • 48. YY_RULE_SETUP #line 15 "CDCFlex.l" { printf("Take an input from the user"); } YY_BREAK case 8: YY_RULE_SETUP #line 16 "CDCFlex.l" { printf("Declare a Variable"); } YY_BREAK case 9: YY_RULE_SETUP #line 17 "CDCFlex.l" { printf("Assign some value to the variable"); } YY_BREAK case 10: YY_RULE_SETUP #line 18 "CDCFlex.l" { printf("Sum of two Operations"); }
  • 49. YY_BREAK case 11: YY_RULE_SETUP #line 19 "CDCFlex.l" { printf("Difference of two Operations"); } YY_BREAK case 12: YY_RULE_SETUP #line 20 "CDCFlex.l" { printf("Product of two Operations"); } YY_BREAK case 13: YY_RULE_SETUP #line 21 "CDCFlex.l" { printf("Division of two Operations"); } YY_BREAK case 14: YY_RULE_SETUP
  • 50. #line 22 "CDCFlex.l" { printf("Modulo of two Operations"); } YY_BREAK case 15: YY_RULE_SETUP #line 23 "CDCFlex.l" { printf("Larger of two Operations"); } YY_BREAK case 16: YY_RULE_SETUP #line 24 "CDCFlex.l" { printf("Smaller of two Operations"); } YY_BREAK case 17: YY_RULE_SETUP #line 25 "CDCFlex.l" { printf("Both the operaters are same"); } YY_BREAK
  • 51. case 18: YY_RULE_SETUP #line 26 "CDCFlex.l" { printf("Both the operaters are not same"); } YY_BREAK case 19: YY_RULE_SETUP #line 27 "CDCFlex.l" { printf("Ending a Loop"); } YY_BREAK case 20: YY_RULE_SETUP #line 28 "CDCFlex.l" { printf("Starting a Loop"); } YY_BREAK case 21: YY_RULE_SETUP #line 29 "CDCFlex.l"
  • 52. { printf("AND operator"); } YY_BREAK case 22: YY_RULE_SETUP #line 30 "CDCFlex.l" { printf("OR operator"); } YY_BREAK case 23: YY_RULE_SETUP #line 31 "CDCFlex.l" { printf("XOR operator"); } YY_BREAK case 24: YY_RULE_SETUP #line 32 "CDCFlex.l" { printf("NOT operator"); } YY_BREAK case 25:
  • 53. YY_RULE_SETUP #line 33 "CDCFlex.l" { printf("Start IF condition"); } YY_BREAK case 26: YY_RULE_SETUP #line 34 "CDCFlex.l" { printf("Start IF yes"); } YY_BREAK case 27: YY_RULE_SETUP #line 35 "CDCFlex.l" { printf("Start IF not"); } YY_BREAK case 28: YY_RULE_SETUP #line 36 "CDCFlex.l" { printf("Start IF maybe"); }
  • 54. YY_BREAK case 29: YY_RULE_SETUP #line 37 "CDCFlex.l" { printf("Start SWITCH CASE"); } YY_BREAK case 30: YY_RULE_SETUP #line 38 "CDCFlex.l" { printf("CASE inside switch case"); } YY_BREAK case 31: YY_RULE_SETUP #line 39 "CDCFlex.l" { printf("DEFAULT case in switch case"); } YY_BREAK case 32: YY_RULE_SETUP
  • 55. #line 40 "CDCFlex.l" { printf("BREAK statement"); } YY_BREAK case 33: YY_RULE_SETUP #line 41 "CDCFlex.l" { printf("Condition Ending"); } YY_BREAK case 34: YY_RULE_SETUP #line 42 "CDCFlex.l" {return 0;} YY_BREAK case 35: YY_RULE_SETUP #line 43 "CDCFlex.l" { printf("String Literals %s", yytext); } YY_BREAK
  • 56. case 36: YY_RULE_SETUP #line 44 "CDCFlex.l" { printf("Number Literals %s", yytext); } YY_BREAK case 37: YY_RULE_SETUP #line 45 "CDCFlex.l" ECHO; YY_BREAK #line 922 "lex.yy.c" case YY_STATE_EOF(INITIAL): yyterminate(); case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ int yy_amount_of_matched_text = (int) (yy_cp -
  • 57. yytext_ptr) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ *yy_cp = yy_hold_char; YY_RESTORE_YY_MORE_OFFSET if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) { /* We're scanning a new file or input source. It's * possible that this happened because the user * just pointed yyin at a new source and called * yylex(). If so, then we have to assure * consistency between yy_current_buffer and our * globals. Here is the right place to do so, because * this is the first action (other than possibly a * back-up) that will match for the new input
  • 58. source. */ yy_n_chars = yy_current_buffer->yy_n_chars; yy_current_buffer->yy_input_file = yyin; yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; } /* Note that here we test for yy_c_buf_p "<=" to the position * of the first EOB in the buffer, since yy_c_buf_p will * already have been incremented past the NUL character * (since all states make transitions on EOB to the * end-of-buffer state). Contrast this with the test * in input(). */ if ( yy_c_buf_p <= &yy_current_buffer- >yy_ch_buf[yy_n_chars] ) { /* This was really a NUL. */
  • 59. yy_state_type yy_next_state; yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; yy_current_state = yy_get_previous_state(); /* Okay, we're now positioned to make the NUL * transition. We couldn't have * yy_get_previous_state() go ahead and do it * for us because it doesn't know how to deal * with the possibility of jamming (and we don't * want to build jamming into it because then it * will run more slowly). */ yy_next_state = yy_try_NUL_trans( yy_current_state );
  • 60. yy_bp = yytext_ptr + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ yy_cp = ++yy_c_buf_p; yy_current_state = yy_next_state; goto yy_match; } else { yy_cp = yy_c_buf_p; goto yy_find_action; } } else switch ( yy_get_next_buffer() )
  • 61. { case EOB_ACT_END_OF_FILE: { yy_did_buffer_switch_on_eof = 0; if ( yywrap() ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up * yytext, we can now set up * yy_c_buf_p so that if some total * hoser (like flex itself) wants to * call the scanner after we return the * YY_NULL, it'll still work - another * YY_NULL will get returned. */ yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
  • 62. yy_act = YY_STATE_EOF(YY_START); goto do_action; } else { if ( ! yy_did_buffer_switch_on_eof ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
  • 63. yy_current_state = yy_get_previous_state(); yy_cp = yy_c_buf_p; yy_bp = yytext_ptr + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: yy_c_buf_p = &yy_current_buffer- >yy_ch_buf[yy_n_chars]; yy_current_state = yy_get_previous_state(); yy_cp = yy_c_buf_p; yy_bp = yytext_ptr + YY_MORE_ADJ; goto yy_find_action; } break;
  • 64. } default: YY_FATAL_ERROR( "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ } /* end of yylex */ /* yy_get_next_buffer - try to read in a new buffer * * Returns a code representing an action: * EOB_ACT_LAST_MATCH - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */
  • 65. static int yy_get_next_buffer() { register char *dest = yy_current_buffer->yy_ch_buf; register char *source = yytext_ptr; register int number_to_move, i; int ret_val; if ( yy_c_buf_p > &yy_current_buffer- >yy_ch_buf[yy_n_chars + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); if ( yy_current_buffer->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so
  • 66. * treat this as a final EOF. */ return EOB_ACT_END_OF_FILE; } else { /* We matched some text prior to the EOB, first * process it. */ return EOB_ACT_LAST_MATCH; } } /* Try to read more data. */ /* First move last chars to start of buffer. */ number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
  • 67. for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ yy_current_buffer->yy_n_chars = yy_n_chars = 0; else { int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 )
  • 68. { /* Not enough room in the buffer - grow it. */ #ifdef YY_USES_REJECT YY_FATAL_ERROR( "input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); #else /* just a shorter name for the current buffer */ YY_BUFFER_STATE b = yy_current_buffer; int yy_c_buf_p_offset = (int) (yy_c_buf_p - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { int new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size /
  • 69. 8; else b->yy_buf_size *= 2; b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ yy_flex_realloc( (void *) b- >yy_ch_buf, b->yy_buf_size + 2 ); } else /* Can't grow it, we don't own it. */ b->yy_ch_buf = 0; if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
  • 70. yy_c_buf_p = &b- >yy_ch_buf[yy_c_buf_p_offset]; num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1; #endif } if ( num_to_read > YY_READ_BUF_SIZE ) num_to_read = YY_READ_BUF_SIZE; /* Read in more data. */ YY_INPUT( (&yy_current_buffer- >yy_ch_buf[number_to_move]), yy_n_chars, num_to_read ); yy_current_buffer->yy_n_chars = yy_n_chars; }
  • 71. if ( yy_n_chars == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; yyrestart( yyin ); } else { ret_val = EOB_ACT_LAST_MATCH; yy_current_buffer->yy_buffer_status = YY_BUFFER_EOF_PENDING; } } else ret_val = EOB_ACT_CONTINUE_SCAN;
  • 72. yy_n_chars += number_to_move; yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ static yy_state_type yy_get_previous_state() { register yy_state_type yy_current_state;
  • 73. register char *yy_cp; yy_current_state = yy_start; for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) { register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { yy_last_accepting_state = yy_current_state; yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 204 )
  • 74. yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; } return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character * * synopsis * next_state = yy_try_NUL_trans( current_state ); */ #ifdef YY_USE_PROTOS static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
  • 75. #else static yy_state_type yy_try_NUL_trans( yy_current_state ) yy_state_type yy_current_state; #endif { register int yy_is_jam; register char *yy_cp = yy_c_buf_p; register YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { yy_last_accepting_state = yy_current_state; yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state];
  • 76. if ( yy_current_state >= 204 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_is_jam = (yy_current_state == 203); return yy_is_jam ? 0 : yy_current_state; } #ifndef YY_NO_UNPUT #ifdef YY_USE_PROTOS static void yyunput( int c, register char *yy_bp ) #else static void yyunput( c, yy_bp ) int c; register char *yy_bp; #endif
  • 77. { register char *yy_cp = yy_c_buf_p; /* undo effects of setting up yytext */ *yy_cp = yy_hold_char; if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ register int number_to_move = yy_n_chars + 2; register char *dest = &yy_current_buffer- >yy_ch_buf[ yy_current_buffer->yy_buf_size + 2]; register char *source = &yy_current_buffer- >yy_ch_buf[number_to_move]; while ( source > yy_current_buffer->yy_ch_buf ) *--dest = *--source;
  • 78. yy_cp += (int) (dest - source); yy_bp += (int) (dest - source); yy_current_buffer->yy_n_chars = yy_n_chars = yy_current_buffer->yy_buf_size; if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) YY_FATAL_ERROR( "flex scanner push-back overflow" ); } *--yy_cp = (char) c; yytext_ptr = yy_bp; yy_hold_char = *yy_cp; yy_c_buf_p = yy_cp; }
  • 79. #endif /* ifndef YY_NO_UNPUT */ #ifdef __cplusplus static int yyinput() #else static int input() #endif { int c; *yy_c_buf_p = yy_hold_char; if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a
  • 80. * valid NUL; if not, then we've hit the end of the buffer. */ if ( yy_c_buf_p < &yy_current_buffer- >yy_ch_buf[yy_n_chars] ) /* This was really a NUL. */ *yy_c_buf_p = '0'; else { /* need more input */ int offset = yy_c_buf_p - yytext_ptr; ++yy_c_buf_p; switch ( yy_get_next_buffer() ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() * sees that we've accumulated a * token and flags that we need to
  • 81. * try matching the token before * proceeding. But for input(), * there's no matching to consider. * So convert the EOB_ACT_LAST_MATCH * to EOB_ACT_END_OF_FILE. */ /* Reset buffer status. */ yyrestart( yyin ); /* fall through */ case EOB_ACT_END_OF_FILE: { if ( yywrap() ) return EOF; if ( ! yy_did_buffer_switch_on_eof )
  • 82. YY_NEW_FILE; #ifdef __cplusplus return yyinput(); #else return input(); #endif } case EOB_ACT_CONTINUE_SCAN: yy_c_buf_p = yytext_ptr + offset; break; } } } c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ *yy_c_buf_p = '0'; /* preserve yytext */
  • 83. yy_hold_char = *++yy_c_buf_p; return c; } #ifdef YY_USE_PROTOS void yyrestart( FILE *input_file ) #else void yyrestart( input_file ) FILE *input_file; #endif { if ( ! yy_current_buffer ) yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); yy_init_buffer( yy_current_buffer, input_file );
  • 84. yy_load_buffer_state(); } #ifdef YY_USE_PROTOS void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) #else void yy_switch_to_buffer( new_buffer ) YY_BUFFER_STATE new_buffer; #endif { if ( yy_current_buffer == new_buffer ) return; if ( yy_current_buffer ) { /* Flush out information for old buffer. */ *yy_c_buf_p = yy_hold_char;
  • 85. yy_current_buffer->yy_buf_pos = yy_c_buf_p; yy_current_buffer->yy_n_chars = yy_n_chars; } yy_current_buffer = new_buffer ; yy_load_buffer_state(); /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag * is looked at is after yywrap() is called, so it's safe * to go ahead and always set it. */ yy_did_buffer_switch_on_eof = 1; } #ifdef YY_USE_PROTOS
  • 86. void yy_load_buffer_state( void ) #else void yy_load_buffer_state() #endif { yy_n_chars = yy_current_buffer->yy_n_chars; yytext_ptr = yy_c_buf_p = yy_current_buffer- >yy_buf_pos; yyin = yy_current_buffer->yy_input_file; yy_hold_char = *yy_c_buf_p; } #ifdef YY_USE_PROTOS YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) #else YY_BUFFER_STATE yy_create_buffer( file, size ) FILE *file; int size;
  • 87. #endif { YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_buf_size = size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in
  • 88. yy_create_buffer()" ); b->yy_is_our_buffer = 1; yy_init_buffer( b, file ); return b; } #ifdef YY_USE_PROTOS void yy_delete_buffer( YY_BUFFER_STATE b ) #else void yy_delete_buffer( b ) YY_BUFFER_STATE b; #endif { if ( ! b )
  • 89. return; if ( b == yy_current_buffer ) yy_current_buffer = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) yy_flex_free( (void *) b->yy_ch_buf ); yy_flex_free( (void *) b ); } #ifndef YY_ALWAYS_INTERACTIVE #ifndef YY_NEVER_INTERACTIVE extern int isatty YY_PROTO(( int )); #endif #endif
  • 90. #ifdef YY_USE_PROTOS void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) #else void yy_init_buffer( b, file ) YY_BUFFER_STATE b; FILE *file; #endif { yy_flush_buffer( b ); b->yy_input_file = file; b->yy_fill_buffer = 1; #if YY_ALWAYS_INTERACTIVE b->yy_is_interactive = 1; #else
  • 91. #if YY_NEVER_INTERACTIVE b->yy_is_interactive = 0; #else b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; #endif #endif } #ifdef YY_USE_PROTOS void yy_flush_buffer( YY_BUFFER_STATE b ) #else void yy_flush_buffer( b ) YY_BUFFER_STATE b; #endif { if ( ! b )
  • 92. return; b->yy_n_chars = 0; /* We always need two end-of-buffer characters. The first causes * a transition to the end-of-buffer state. The second causes * a jam in that state. */ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; b->yy_buf_pos = &b->yy_ch_buf[0]; b->yy_at_bol = 1; b->yy_buffer_status = YY_BUFFER_NEW; if ( b == yy_current_buffer )
  • 93. yy_load_buffer_state(); } #ifndef YY_NO_SCAN_BUFFER #ifdef YY_USE_PROTOS YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) #else YY_BUFFER_STATE yy_scan_buffer( base, size ) char *base; yy_size_t size; #endif { YY_BUFFER_STATE b; if ( size < 2 || base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR )
  • 94. /* They forgot to leave room for the EOB's. */ return 0; b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; b->yy_input_file = 0; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW;
  • 95. yy_switch_to_buffer( b ); return b; } #endif #ifndef YY_NO_SCAN_STRING #ifdef YY_USE_PROTOS YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) #else YY_BUFFER_STATE yy_scan_string( yy_str ) yyconst char *yy_str; #endif { int len; for ( len = 0; yy_str[len]; ++len )
  • 96. ; return yy_scan_bytes( yy_str, len ); } #endif #ifndef YY_NO_SCAN_BYTES #ifdef YY_USE_PROTOS YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) #else YY_BUFFER_STATE yy_scan_bytes( bytes, len ) yyconst char *bytes; int len; #endif { YY_BUFFER_STATE b; char *buf;
  • 97. yy_size_t n; int i; /* Get memory for full buffer, including space for trailing EOB's. */ n = len + 2; buf = (char *) yy_flex_alloc( n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); for ( i = 0; i < len; ++i ) buf[i] = bytes[i]; buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; b = yy_scan_buffer( buf, n ); if ( ! b ) YY_FATAL_ERROR( "bad buffer in
  • 98. yy_scan_bytes()" ); /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. */ b->yy_is_our_buffer = 1; return b; } #endif #ifndef YY_NO_PUSH_STATE #ifdef YY_USE_PROTOS static void yy_push_state( int new_state ) #else static void yy_push_state( new_state ) int new_state;
  • 99. #endif { if ( yy_start_stack_ptr >= yy_start_stack_depth ) { yy_size_t new_size; yy_start_stack_depth += YY_START_STACK_INCR; new_size = yy_start_stack_depth * sizeof( int ); if ( ! yy_start_stack ) yy_start_stack = (int *) yy_flex_alloc( new_size ); else yy_start_stack = (int *) yy_flex_realloc( (void *) yy_start_stack, new_size ); if ( ! yy_start_stack ) YY_FATAL_ERROR(
  • 100. "out of memory expanding start-condition stack" ); } yy_start_stack[yy_start_stack_ptr++] = YY_START; BEGIN(new_state); } #endif #ifndef YY_NO_POP_STATE static void yy_pop_state() { if ( --yy_start_stack_ptr < 0 ) YY_FATAL_ERROR( "start-condition stack underflow" ); BEGIN(yy_start_stack[yy_start_stack_ptr]);
  • 101. } #endif #ifndef YY_NO_TOP_STATE static int yy_top_state() { return yy_start_stack[yy_start_stack_ptr - 1]; } #endif #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif #ifdef YY_USE_PROTOS static void yy_fatal_error( yyconst char msg[] ) #else
  • 102. static void yy_fatal_error( msg ) char msg[]; #endif { (void) fprintf( stderr, "%sn", msg ); exit( YY_EXIT_FAILURE ); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless #define yyless(n) do { /* Undo effects of setting up yytext. */ yytext[yyleng] = yy_hold_char;
  • 103. yy_c_buf_p = yytext + n; yy_hold_char = *yy_c_buf_p; *yy_c_buf_p = '0'; yyleng = n; } while ( 0 ) /* Internal utility routines. */ #ifndef yytext_ptr #ifdef YY_USE_PROTOS static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) #else static void yy_flex_strncpy( s1, s2, n ) char *s1; yyconst char *s2; int n;
  • 104. #endif { register int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN #ifdef YY_USE_PROTOS static int yy_flex_strlen( yyconst char *s ) #else static int yy_flex_strlen( s ) yyconst char *s; #endif { register int n; for ( n = 0; s[n]; ++n )
  • 105. ; return n; } #endif #ifdef YY_USE_PROTOS static void *yy_flex_alloc( yy_size_t size ) #else static void *yy_flex_alloc( size ) yy_size_t size; #endif { return (void *) malloc( size ); } #ifdef YY_USE_PROTOS
  • 106. static void *yy_flex_realloc( void *ptr, yy_size_t size ) #else static void *yy_flex_realloc( ptr, size ) void *ptr; yy_size_t size; #endif { /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter * because both ANSI C and C++ allow castless assignment from * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ return (void *) realloc( (char *) ptr, size ); }
  • 107. #ifdef YY_USE_PROTOS static void yy_flex_free( void *ptr ) #else static void yy_flex_free( ptr ) void *ptr; #endif { free( ptr ); } #if YY_MAIN int main() { yylex(); return 0; } #endif
  • 108. #line 45 "CDCFlex.l" yywrap() {} int main() { printf("Enter String: n"); yyin = fopen(argv[1], "r"); yylex(); fclose(yyin); return 0; } This is the program to detect lex tokens using flex and C/C++. CDCFlex.l is the flex program to detect tokens from LOLCODE. It has all the tokens and keywords that are used in LOLCODE.
  • 109. To execute this program there are three main commands. 1. "flex CDCFlex.l" is the command to convert flex program to C creating lex.yy.c 2. "gcc lex.yy.c -o exe" is the command to compile lex.yy.c, creating an executable exe 3. "exe < LOLCODE.txt" is the command to run the exe and take input lolcode.txt file The output of the program will be list of tokens printing in the command prompt. %{ /*Definitions*/ %} /*Rules for the language*/ %% [ t] ; // ignore all whitespace
  • 110. BTW[^rn]*r?n {printf("Single line comments %sn", yytext);} OBTW(.|r|n)*TLDRr?n {printf("Multiple line comments %sn", yytext);} "HAI" { printf("Program startedn"); } "KTHXBYE" { printf("program Endedn"); } "VISIBLE" { printf("Printing a variable to outputn"); } "GIMMEH" { printf("Take an input from the usern"); } "I HAS A" { printf("Declare a Variablen"); } "ITZ" { printf("Assign some value to the variablen"); } "SUM OF" { printf("Sum of two Operationsn"); } "DIFF OF" { printf("Difference of two Operationsn"); } "PRODUKT OF" { printf("Product of two Operationsn"); } "QUOSHUNT OF" { printf("Division of two Operationsn"); } "MOD OF" { printf("Modulo of two Operationsn"); } "BIGGR OF" { printf("Larger of two Operationsn"); } "SMALLR OF" { printf("Smaller of two Operationsn"); }
  • 111. "BOTH SAEM" { printf("Both the operaters are samen"); } "DIFFRNT" { printf("Both the operaters are not samen"); } "IM OUTTA YR" { printf("Ending a Loopn"); } "IM IN YR" { printf("Starting a Loopn"); } "BOTH OF" { printf("AND operatorn"); } "EITHER OF" { printf("OR operatorn"); } "WON OF" { printf("XOR operatorn"); } "NOT" { printf("NOT operatorn"); } "O RLY?" { printf("Start IF conditionn"); } "YA RLY" { printf("Start IF yesn"); } "NO WAI" { printf("Start IF notn"); } "MEBBE" { printf("Start IF mayben"); } "WTF?" { printf("Start SWITCH CASEn"); } "OMG" { printf("CASE inside switch casen"); } "OMGWTF" { printf("DEFAULT case in switch casen"); } "GTFO" { printf("BREAK statementn"); } "OIC" { printf("Condition Endingn"); }
  • 112. "exit" {return 0;} [a-zA-Z]+ { printf("String Literals %sn", yytext); } [0-9]+ { printf("Number Literals %sn", yytext); } %% yywrap() {} int main() { printf("Enter String: n"); yyin = fopen(argv[1], "r"); yylex(); fclose(yyin); return 0; } HAI 1.2
  • 113. CAN HAS STDIO? VISIBLE "HAI WORLD!!!1!" KTHXBYE